stefanrmmr / streamlit-audio-recorder

Record Audio from the User's Microphone in Apps that are Deployed to the Web. (via Browser Media-API, REACT-based, Streamlit Custom Component)
MIT License
415 stars 75 forks source link

Downloading audio file to a server location #19

Open creme17 opened 7 months ago

creme17 commented 7 months ago

Hello!

I love this app, thank you so much for developing. It's very easy to use however I'm trying to save down the audio file to a server location once the stop button is pressed, which works, but takes an extremely long time to once the audio recording is longer than a couple of seconds (though downloading the file locally to my machine works well). Does anyone know of a potential workaround that would speed up the processing, ie leveraging or compressing the audio? Would appreciate any insights!

rushi-the-neural-arch commented 6 months ago

yes you can save it in this way once you stop the recording -

 import tempfile
 from st_audiorec import st_audiorec

wav_audio_data = st_audiorec()

if wav_audio_data is not None:
       st.audio(wav_audio_data, format='audio/wav')

with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
        temp_file.write(wav_audio_data)
        temp_file_path = temp_file.name
        st.success(f"Audio saved to {temp_file_path}")