Amitesh007's picture
Update app.py
da0fe8d
raw
history blame contribute delete
693 Bytes
import streamlit as st
import IPython.display as ipd
from gtts import gTTS
import io
from transformers import pipeline
def play_sound(text, lang):
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
translation = translator(text)
tts = gTTS(text=translation[0]['translation_text'], lang=lang)
fp = io.BytesIO()
tts.write_to_fp(fp)
fp.seek(0)
return ipd.Audio(fp.read(), autoplay=True)
st.title("English To French Translator")
text = st.text_input("Enter some text in English to translate.\nPlay the audio 2nd time to listen clearly")
if st.button("Translate and play sound"):
audio = play_sound(text, lang='fr')
st.write(audio)