Audio display

audio_file = open(‘trans.mp3’, ‘rb’)
audio_bytes = audio_file.read()
st.audio(audio_bytes, format=‘audio/ogg’)

image

how can I autodisplay audio

Hi @lazeni,

What do you mean when you say you want to autodisplay the audio? can you attach a picture or gif of the functionality you’re looking for?

Thanks!
Marisa

Thank you Marisa,
I mean playing audio automaticaly without clicking play button

Hey @lazeni,

The audio doesn’t have any functionality to autoplay after an upload. The team wanted to make sure that the user had control over when audio is played on their device.

Why were you trying to get autoplay on the uploaded file? maybe there is another way I can help you to achieve your end goal?

Happy Streamlit-ing!
Marisa

Thank you again Marissa,
my goal is just to convert a text in to audio and just repeat directly in speech

this is my code:
text_en = “this article is non compliant”
ta_tts = gTTS(text_en)
ta_tts.save(‘trans.mp3’)
audio_file = open(‘trans.mp3’, ‘rb’)
audio_bytes = audio_file.read()
st.audio(audio_bytes, format=‘audio/ogg’,start_time=0)

Hey @lazeni,

Ah, I see now why you were hoping to have the audio file play automatically. Yes, I do believe that you have the best option there, for now the user who inputs the text will have to hit the play button to hear the generated audio.

But I think this is a cool application and I created a feature request (FR) on github for you, you can see it here: link to github FR

Happy Streamlit-ing!
Marisa

Thank you so much Marisa

1 Like