python-sounddevice
python-sounddevice copied to clipboard
Record and play at the same time
Mixed in reverb, and the sound suddenly big and small, sometimes there will be swallow word
import sounddevice as sd
import time
import numpy as np
import soundfile
Stream = sd.Stream(samplerate=16000, blocksize=256, channels=1)
Stream.start()
enhance_audio = np.zeros((0,))
print("开始")
for _ in range(2000):
start_time = time.time()
data, overflowed = Stream.read(frames=256, )
enhance_audio = np.append(enhance_audio, data)
Stream.write(data)
print(time.time() - start_time)
soundfile.write("no_alg.wav", data=enhance_audio, samplerate=16000)
You should check the overflowed
variable. I guess it is True
some of the times?
If that's the case, you could try to increase your block size.
Other than that, I can't really say anything about "blocking" mode, because I rarely use it and I don't know how to use it for recording and playback at the same time.
I would use the "callback" mode instead.
You should check the
overflowed
variable. I guess it isTrue
some of the times?If that's the case, you could try to increase your block size.
Other than that, I can't really say anything about "blocking" mode, because I rarely use it and I don't know how to use it for recording and playback at the same time.
I would use the "callback" mode instead.
When playback and recording are in progress at the same time, the signal recorded by the microphone will be processed by the window's mic (voice enhancement, spatial audio), we need to turn them off