Baghdad99 commited on
Commit
774e76f
1 Parent(s): 01153e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -31,11 +31,12 @@ def translate_speech(audio):
31
  translated_text = translator(transcription, return_tensors="pt")
32
  print(f"Translated text: {translated_text}") # Print the translated text to see what it contains
33
 
34
- # Check if the translated text contains 'generated_text'
35
- if 'generated_text' in translated_text[0]:
36
- translated_text_str = translated_text[0]['generated_text']
 
37
  else:
38
- print("The translated text does not contain 'generated_text'")
39
  return
40
 
41
  # Use the text-to-speech pipeline to synthesize the translated text
 
31
  translated_text = translator(transcription, return_tensors="pt")
32
  print(f"Translated text: {translated_text}") # Print the translated text to see what it contains
33
 
34
+ # Check if the translated text contains 'generated_token_ids'
35
+ if 'generated_token_ids' in translated_text[0]:
36
+ # Decode the tokens into text
37
+ translated_text_str = translator.tokenizer.decode(translated_text[0]['generated_token_ids'])
38
  else:
39
+ print("The translated text does not contain 'generated_token_ids'")
40
  return
41
 
42
  # Use the text-to-speech pipeline to synthesize the translated text