Piper backend: Dont change audio sink buffer size on windows

Instead only emit readyRead() when new speech audio is available.
The docs of QIODevice say that readyRead() must be emitted only when
new data is available. With this change audio playback works on my
windows machine without needing to adjust the audio sink buffer size.
This commit is contained in:
Kovid Goyal 2024-11-05 07:03:04 +05:30
parent 278f774331
commit ebf8e8d72b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -234,8 +234,6 @@ class UtteranceAudioQueue(QIODevice):
else: else:
ans = self.current_audio_data.first(maxlen) ans = self.current_audio_data.first(maxlen)
self.current_audio_data = self.current_audio_data.last(len(self.current_audio_data) - maxlen) self.current_audio_data = self.current_audio_data.last(len(self.current_audio_data) - maxlen)
if len(self.current_audio_data):
self.readyRead.emit()
debug(f'Audio sent to output: {maxlen=} {len(ans)=}') debug(f'Audio sent to output: {maxlen=} {len(ans)=}')
return ans return ans
@ -420,14 +418,6 @@ class Piper(TTSBackend):
self._audio_sink = QAudioSink(fmt, self) self._audio_sink = QAudioSink(fmt, self)
if s.volume is not None: if s.volume is not None:
self._audio_sink.setVolume(s.volume) self._audio_sink.setVolume(s.volume)
# On Windows, the buffer is zero causing data to be discarded.
# Ensure we have a nice large buffer on all platforms.
# However, on Linux and macOS changing the buffer size causes audio to not
# play on some systems or play with a large delay.
# See https://www.mobileread.com/forums/showthread.php?t=363881
# and https://www.mobileread.com/forums/showthread.php?t=364225
if iswindows:
self._audio_sink.setBufferSize(2 * 1024 * 1024)
self._audio_sink.stateChanged.connect(self._utterances_being_spoken.audio_state_changed) self._audio_sink.stateChanged.connect(self._utterances_being_spoken.audio_state_changed)
self._process.start() self._process.start()
self._audio_sink.start(self._utterances_being_spoken) self._audio_sink.start(self._utterances_being_spoken)