Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stonelazy opened this issue Aug 2, 2021 · 1 comment
Open

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

stonelazy opened this issue Aug 2, 2021 · 1 comment

Comments

@stonelazy
Copy link

stonelazy commented Aug 2, 2021

`
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
Copy link
Owner

whitphx commented Aug 2, 2021

whitphx/streamlit-webrtc#357 might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants