diff --git a/anki/sound.py b/anki/sound.py index 983a9bcd8..dc573b9af 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -288,8 +288,9 @@ class _Recorder: class PyAudioThreadedRecorder(threading.Thread): - def __init__(self): + def __init__(self, startupDelay): threading.Thread.__init__(self) + self.startupDelay = startupDelay self.finish = False def run(self): @@ -297,6 +298,7 @@ class PyAudioThreadedRecorder(threading.Thread): p = pyaudio.PyAudio() rate = int(p.get_default_input_device_info()['defaultSampleRate']) + wait = int(rate * self.startupDelay) stream = p.open(format=PYAU_FORMAT, channels=PYAU_CHANNELS, @@ -305,6 +307,8 @@ class PyAudioThreadedRecorder(threading.Thread): input_device_index=PYAU_INPUT_INDEX, frames_per_buffer=chunk) + stream.read(wait) + data = b"" while not self.finish: try: @@ -325,6 +329,9 @@ class PyAudioThreadedRecorder(threading.Thread): class PyAudioRecorder(_Recorder): + # discard first 250ms which may have pops/cracks + startupDelay = 0.25 + def __init__(self): for t in recFiles + [processingSrc, processingDst]: try: @@ -334,7 +341,7 @@ class PyAudioRecorder(_Recorder): self.encode = False def start(self): - self.thread = PyAudioThreadedRecorder() + self.thread = PyAudioThreadedRecorder(startupDelay=self.startupDelay) self.thread.start() def stop(self): diff --git a/aqt/sound.py b/aqt/sound.py index 2c8fb39b6..7b035da94 100644 --- a/aqt/sound.py +++ b/aqt/sound.py @@ -22,6 +22,7 @@ def getAudio(parent, encode=True): mb.setEscapeButton(but) t = time.time() r.start() + time.sleep(r.startupDelay) QApplication.instance().processEvents() while not mb.clickedButton(): txt =_("Recording...
Time: %0.1f")