vladelesin commited on
Commit
bcc1813
1 Parent(s): ee10fc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -27,18 +27,18 @@ model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
27
  tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
28
 
29
 
30
- def translator(audio):
31
  en_text = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
32
  translated_text = translation_en_to_rus(en_text["text"])
33
  return translated_text[0]['translation_text']
34
 
35
  def synthesise(text):
36
- translated_text = translator(text)
37
  speech = model.generate(**tokenizer(translated_text, return_tensors="pt"))
38
  return speech.to("cpu")
39
 
40
  def speech_to_speech_translation(audio):
41
- translated_text = translator(audio)
42
  synthesised_speech = synthesise(translated_text)
43
  synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
44
  return 16000, synthesised_speech[0]
 
27
  tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
28
 
29
 
30
+ def translate(audio):
31
  en_text = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
32
  translated_text = translation_en_to_rus(en_text["text"])
33
  return translated_text[0]['translation_text']
34
 
35
  def synthesise(text):
36
+ translated_text = translate(text)
37
  speech = model.generate(**tokenizer(translated_text, return_tensors="pt"))
38
  return speech.to("cpu")
39
 
40
  def speech_to_speech_translation(audio):
41
+ translated_text = translate(audio)
42
  synthesised_speech = synthesise(translated_text)
43
  synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
44
  return 16000, synthesised_speech[0]