shahpalash10 commited on
Commit
c54218a
1 Parent(s): 8d593f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
  from gtts import gTTS # Google Text-to-Speech library
4
- import IPython.display as ipd # For playing audio in the notebook
5
 
6
  # Create a translation pipeline
7
  pipe = pipeline('translation', model='Helsinki-NLP/opus-mt-en-hi')
@@ -11,15 +10,12 @@ if text:
11
  out = pipe(text, src_lang='en', tgt_lang='hi')
12
  st.json(out)
13
 
14
- # Extract the translated text from the JSON output
15
- translation_text = out[0]['translation_text']
16
-
17
  # Convert the translated text to speech
 
18
  tts = gTTS(translation_text, lang='hi') # You can specify the desired language ('hi' for Hindi)
19
 
20
- # Save the generated speech as an audio file (e.g., "translated_audio.mp3")
21
- audio_path = "translated_audio.mp3"
22
- tts.save(audio_path)
23
-
24
- # Display the audio player for listening to the speech
25
- st.audio(audio_path, format='audio/mp3')
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  from gtts import gTTS # Google Text-to-Speech library
 
4
 
5
  # Create a translation pipeline
6
  pipe = pipeline('translation', model='Helsinki-NLP/opus-mt-en-hi')
 
10
  out = pipe(text, src_lang='en', tgt_lang='hi')
11
  st.json(out)
12
 
 
 
 
13
  # Convert the translated text to speech
14
+ translation_text = out[0]['translation_text']
15
  tts = gTTS(translation_text, lang='hi') # You can specify the desired language ('hi' for Hindi)
16
 
17
+ # Save the generated speech as an audio file
18
+ tts.save("translated_audio.mp3")
19
+
20
+ # Display the audio player
21
+ st.audio("translated_audio.mp3")