Marti Umbert
commited on
Commit
·
72d3f66
1
Parent(s):
936478d
whisperlivekit/audio_processor.py: bug fix to translate from transcribed text and show in log messages
Browse files
whisperlivekit/audio_processor.py
CHANGED
|
@@ -516,15 +516,20 @@ class AudioProcessor:
|
|
| 516 |
await self.restart_ffmpeg()
|
| 517 |
return
|
| 518 |
|
| 519 |
-
|
| 520 |
"""Translate recognized text to the target language."""
|
| 521 |
if not hasattr(self, "translation_tokenizer") or not hasattr(self, "translator"):
|
| 522 |
logger.warning("Translation model is not loaded. Skipping translation.")
|
| 523 |
return text
|
| 524 |
|
|
|
|
|
|
|
| 525 |
# Tokenize, translate, and detokenize
|
| 526 |
tokenized = self.translation_tokenizer.tokenize(text)
|
| 527 |
translated = self.translator.translate_batch([tokenized[0]])
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
|
|
|
|
| 516 |
await self.restart_ffmpeg()
|
| 517 |
return
|
| 518 |
|
| 519 |
+
def translate_text(self, text: str) -> str:
|
| 520 |
"""Translate recognized text to the target language."""
|
| 521 |
if not hasattr(self, "translation_tokenizer") or not hasattr(self, "translator"):
|
| 522 |
logger.warning("Translation model is not loaded. Skipping translation.")
|
| 523 |
return text
|
| 524 |
|
| 525 |
+
logger.info(f"Translating text: {text}")
|
| 526 |
+
|
| 527 |
# Tokenize, translate, and detokenize
|
| 528 |
tokenized = self.translation_tokenizer.tokenize(text)
|
| 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 |
|