acumplid commited on
Commit
20e4167
·
1 Parent(s): 1db6194

connected translation with frontend

Browse files
whisperlivekit/audio_processor.py CHANGED
@@ -397,7 +397,8 @@ class AudioProcessor:
397
  "text": "",
398
  "beg": format_time(0),
399
  "end": format_time(tokens[-1].end if tokens else 0),
400
- "diff": 0
 
401
  }]
402
 
403
  response = {
@@ -529,7 +530,7 @@ class AudioProcessor:
529
  translated = self.translator.translate_batch([tokenized[0]])
530
 
531
  translated_text = self.translation_tokenizer.detokenize(translated[0].hypotheses[0])
532
- logger.info(f"Translated text: {translated_text}")
533
  return translated_text
534
 
535
 
 
397
  "text": "",
398
  "beg": format_time(0),
399
  "end": format_time(tokens[-1].end if tokens else 0),
400
+ "diff": 0,
401
+ "translation": ""
402
  }]
403
 
404
  response = {
 
530
  translated = self.translator.translate_batch([tokenized[0]])
531
 
532
  translated_text = self.translation_tokenizer.detokenize(translated[0].hypotheses[0])
533
+ logger.info(f"Translated text {translated_text}")
534
  return translated_text
535
 
536
 
whisperlivekit/web/live_transcription.html CHANGED
@@ -338,8 +338,8 @@
338
 
339
  const host = window.location.hostname || "localhost";
340
  const port = window.location.port || "8000";
341
- // const defaultWebSocketUrl = `ws://${host}:${port}/asr`;
342
- const defaultWebSocketUrl = `wss://${host}/asr`;
343
  websocketInput.value = defaultWebSocketUrl;
344
  websocketUrl = defaultWebSocketUrl;
345
 
@@ -426,6 +426,7 @@
426
  remaining_time_diarization = 0
427
  } = data;
428
 
 
429
  renderLinesWithBuffer(
430
  lines,
431
  buffer_diarization,
@@ -433,7 +434,7 @@
433
  remaining_time_diarization,
434
  remaining_time_transcription
435
  );
436
- renderLinesWithBufferUpper(
437
  lines,
438
  buffer_diarization,
439
  buffer_transcription,
@@ -484,7 +485,7 @@
484
  linesTranscriptDiv.innerHTML = linesHtml;
485
  }
486
 
487
- function renderLinesWithBufferUpper(lines, buffer_diarization, buffer_transcription, remaining_time_diarization, remaining_time_transcription) {
488
  const linesHtml = lines.map((item, idx) => {
489
  let timeInfo = "";
490
  if (item.beg !== undefined && item.end !== undefined) {
@@ -502,7 +503,7 @@
502
  speakerLabel = `<span id="speaker">Speaker ${item.speaker}<span id='timeInfo'>${timeInfo}</span></span>`;
503
  }
504
 
505
- let textContent = item.text.toUpperCase();
506
  if (idx === lines.length - 1) {
507
  speakerLabel += `<span class="label_transcription"><span class="spinner"></span>Transcription lag <span id='timeInfo'>${remaining_time_transcription}s</span></span>`
508
  }
 
338
 
339
  const host = window.location.hostname || "localhost";
340
  const port = window.location.port || "8000";
341
+ const defaultWebSocketUrl = `ws://${host}:${port}/asr`;
342
+ //const defaultWebSocketUrl = `wss://${host}/asr`;
343
  websocketInput.value = defaultWebSocketUrl;
344
  websocketUrl = defaultWebSocketUrl;
345
 
 
426
  remaining_time_diarization = 0
427
  } = data;
428
 
429
+
430
  renderLinesWithBuffer(
431
  lines,
432
  buffer_diarization,
 
434
  remaining_time_diarization,
435
  remaining_time_transcription
436
  );
437
+ renderLinesWithBufferTranslation(
438
  lines,
439
  buffer_diarization,
440
  buffer_transcription,
 
485
  linesTranscriptDiv.innerHTML = linesHtml;
486
  }
487
 
488
+ function renderLinesWithBufferTranslation(lines, buffer_diarization, buffer_transcription, remaining_time_diarization, remaining_time_transcription) {
489
  const linesHtml = lines.map((item, idx) => {
490
  let timeInfo = "";
491
  if (item.beg !== undefined && item.end !== undefined) {
 
503
  speakerLabel = `<span id="speaker">Speaker ${item.speaker}<span id='timeInfo'>${timeInfo}</span></span>`;
504
  }
505
 
506
+ let textContent = item.translation;
507
  if (idx === lines.length - 1) {
508
  speakerLabel += `<span class="label_transcription"><span class="spinner"></span>Transcription lag <span id='timeInfo'>${remaining_time_transcription}s</span></span>`
509
  }