whitphx / streamlit-webrtc-example

Real time video and audio processing examples with Streamlit and streamlit-webrtc
https://webrtc.streamlit.app/
MIT License
146 stars 119 forks source link

How do i export the recorded audio into a separate file ? #58

Open stonelazy opened 3 years ago

stonelazy commented 3 years ago

`
complete_audio_chunk = pydub.AudioSegment.empty() while True: if webrtc_ctx.audio_receiver: sound_chunk = pydub.AudioSegment.empty() try: audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=1) except queue.Empty: time.sleep(0.1) status_indicator.write("No frame arrived.") continue

        status_indicator.write("Running. Say something!")
        for idx, audio_frame in enumerate(audio_frames):
            sound = pydub.AudioSegment(
                data=audio_frame.to_ndarray().tobytes(),
                sample_width=audio_frame.format.bytes,
                frame_rate=audio_frame.sample_rate,
                channels=len(audio_frame.layout.channels),
            )
            op = str(idx) + "omg" + str(audio_frame.to_ndarray().shape)
            text_output.write(op)
            sound_chunk += sound
            complete_audio_chunk += sound
    else:
        status_indicator.write("Audio Receiver is not set. Abort.")
        break

    complete_audio_chunk.export("/home/kp/temp/audio_file.wav", format="wav")
    logger.info("ENEDNEND call")
    st.write("end call")

`

I tried the above code, (copied from https://github.com/whitphx/streamlit-webrtc-example/blob/main/app.py). Only audio frames are of interest for me. But, audio is not saved in audio_file.wav at all.

whitphx commented 3 years ago

https://github.com/whitphx/streamlit-webrtc/issues/357 might help.