mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
add a small delay before terminating recording
https://forums.ankiweb.net/t/anki-crashes-periodically-after-clicking-record-audio-button/5824/12
This commit is contained in:
parent
729293f5e3
commit
7d1c8c29f9
1 changed files with 32 additions and 23 deletions
|
@ -530,6 +530,7 @@ class QtAudioInputRecorder(Recorder):
|
||||||
super().__init__(output_path)
|
super().__init__(output_path)
|
||||||
|
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
from PyQt5.QtMultimedia import (
|
from PyQt5.QtMultimedia import (
|
||||||
QAudio,
|
QAudio,
|
||||||
|
@ -567,6 +568,7 @@ class QtAudioInputRecorder(Recorder):
|
||||||
self._buffer += self._iodevice.readAll()
|
self._buffer += self._iodevice.readAll()
|
||||||
|
|
||||||
def stop(self, on_done: Callable[[str], None]):
|
def stop(self, on_done: Callable[[str], None]):
|
||||||
|
def on_stop_timer():
|
||||||
# read anything remaining in buffer & stop
|
# read anything remaining in buffer & stop
|
||||||
self._on_read_ready()
|
self._on_read_ready()
|
||||||
self._audio_input.stop()
|
self._audio_input.stop()
|
||||||
|
@ -596,6 +598,13 @@ class QtAudioInputRecorder(Recorder):
|
||||||
|
|
||||||
self.mw.taskman.run_in_background(write_file, and_then)
|
self.mw.taskman.run_in_background(write_file, and_then)
|
||||||
|
|
||||||
|
# schedule the stop for half a second in the future,
|
||||||
|
# to avoid truncating the end of the recording
|
||||||
|
self._stop_timer = t = QTimer(self._parent)
|
||||||
|
t.timeout.connect(on_stop_timer) # type: ignore
|
||||||
|
t.setSingleShot(True)
|
||||||
|
t.start(500)
|
||||||
|
|
||||||
|
|
||||||
# PyAudio recording
|
# PyAudio recording
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue