File size: 697 Bytes
dd421a7
 
8d593f1
7f855a0
c505931
7f855a0
 
8d593f1
 
 
 
 
 
c54218a
8d593f1
 
c54218a
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import streamlit as st
from transformers import pipeline
from gtts import gTTS  # Google Text-to-Speech library

# Create a translation pipeline
pipe = pipeline('translation', model='Helsinki-NLP/opus-mt-en-hi')

text = st.text_area("Enter some English text")
if text:
    out = pipe(text, src_lang='en', tgt_lang='hi')
    st.json(out)
    
    # Convert the translated text to speech
    translation_text = out[0]['translation_text']
    tts = gTTS(translation_text, lang='hi')  # You can specify the desired language ('hi' for Hindi)
    
    # Save the generated speech as an audio file
    tts.save("translated_audio.mp3")

    # Display the audio player
    st.audio("translated_audio.mp3")