spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
980 stars 145 forks source link

sounddevice rec stop playing when silence detected #483

Open Christhian16 opened 10 months ago

Christhian16 commented 10 months ago

Hello,

I'm currently using sounddevice to record audio from my speaker output using this code.

import sounddevice as REC
from scipy.io import wavfile
SAMPLE_RATE = 44100
SECONDS = 20
MONO    = 1
STEREO  = 2
REC.default.device = 12
REC.default.channels = 2,0
recording = REC.rec( int(SECONDS * SAMPLE_RATE), samplerate = SAMPLE_RATE, channels = 2)
REC.wait()
wavfile.write('recording.wav', SAMPLE_RATE, recording)

Normally, it should record for 20 seconds but instead if stop at silence before the 20 seconds had finished. So, for the recorded audio, the length is actually 20 seconds but I get 7 seconds of audio because after 7 seconds there was a silence.

Can you please help me with this issue?

Thank you in advance for your reply.

mgeier commented 5 months ago

for the recorded audio, the length is actually 20 seconds but I get 7 seconds of audio because after 7 seconds there was a silence.

I don't understand. Does this still happen? If yes, can you please provide more information, including the resulting WAV file?