Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from gtts import gTTS | |
| import wavio | |
| from io import BytesIO | |
| import base64 | |
| # Function to play the original text as audio | |
| def text_to_speech(text_to_play): | |
| tts = gTTS(text_to_play, lang='hr') # Assuming the text is in English | |
| tts.save('original_audio.mp3') | |
| audio_bytes = BytesIO() | |
| tts.write_to_fp(audio_bytes) | |
| audio_bytes.seek(0) | |
| audio = base64.b64encode(audio_bytes.read()).decode("utf-8") | |
| audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>' | |
| return audio_player | |
| with gr.Blocks() as demo: | |
| html = gr.HTML() | |
| # html.visible = False | |
| text = gr.Text() | |
| btn = gr.Button("OK") | |
| btn.click(text_to_speech, inputs=[text], outputs=[html]) | |
| clear = gr.Button("Clear") | |
| clear.click(lambda x: gr.update(value=""), None, [text], queue=False) | |
| demo.launch() | |