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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -29,9 +29,14 @@ def translate_speech(audio):
29
 
30
  # Use the translation pipeline to translate the transcription
31
  translated_text = translator(transcription, return_tensors="pt")
 
32
 
33
- # Convert the tensor to a string
34
- translated_text_str = translated_text[0]['generated_text']
 
 
 
 
35
 
36
  # Use the text-to-speech pipeline to synthesize the translated text
37
  synthesised_speech = tts(translated_text_str)
 
29
 
30
  # Use the translation pipeline to translate the transcription
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
42
  synthesised_speech = tts(translated_text_str)