Spaces:
Runtime error
Runtime error
File size: 693 Bytes
76288fe da0fe8d 76288fe b616780 76288fe b616780 76288fe 9c438e3 76288fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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) |