mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
write .wav in background
This commit is contained in:
parent
93eccd183f
commit
e7d9056acd
1 changed files with 18 additions and 13 deletions
|
@ -612,21 +612,26 @@ class QtAudioInputRecorder(Recorder):
|
||||||
showWarning(f"recording failed: {err}")
|
showWarning(f"recording failed: {err}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# swallow the first 300ms to allow audio device to quiesce
|
def write_file():
|
||||||
wait = int(44100 * self.STARTUP_DELAY)
|
# swallow the first 300ms to allow audio device to quiesce
|
||||||
if len(self._buffer) <= wait:
|
wait = int(44100 * self.STARTUP_DELAY)
|
||||||
return
|
if len(self._buffer) <= wait:
|
||||||
self._buffer = self._buffer[wait:]
|
return
|
||||||
|
self._buffer = self._buffer[wait:]
|
||||||
|
|
||||||
# write out the wave file
|
# write out the wave file
|
||||||
wf = wave.open(self.output_path, "wb")
|
wf = wave.open(self.output_path, "wb")
|
||||||
wf.setnchannels(self._format.channelCount())
|
wf.setnchannels(self._format.channelCount())
|
||||||
wf.setsampwidth(self._format.sampleSize() // 8)
|
wf.setsampwidth(self._format.sampleSize() // 8)
|
||||||
wf.setframerate(self._format.sampleRate())
|
wf.setframerate(self._format.sampleRate())
|
||||||
wf.writeframes(self._buffer)
|
wf.writeframes(self._buffer)
|
||||||
wf.close()
|
wf.close()
|
||||||
|
|
||||||
super().stop(on_done)
|
def and_then(fut):
|
||||||
|
fut.result()
|
||||||
|
Recorder.stop(self, on_done)
|
||||||
|
|
||||||
|
self.mw.taskman.run_in_background(write_file, and_then)
|
||||||
|
|
||||||
|
|
||||||
# PyAudio recording
|
# PyAudio recording
|
||||||
|
|
Loading…
Reference in a new issue