Linux: Piper TTS: Fix audio not playing on some Linux systems

Apparently setting a large buffer size causes some linux audio devices
to refuse to flush audio data. Sigh.
This commit is contained in:
Kovid Goyal 2024-10-20 14:04:15 +05:30
parent 1440a49cda
commit 4057ad3566
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -32,7 +32,7 @@ from qt.core import (
sip, sip,
) )
from calibre.constants import cache_dir, is_debugging, iswindows, piper_cmdline from calibre.constants import cache_dir, is_debugging, ismacos, iswindows, piper_cmdline
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.tts.types import TTS_EMBEDED_CONFIG, EngineSpecificSettings, Quality, TTSBackend, Voice, widget_parent from calibre.gui2.tts.types import TTS_EMBEDED_CONFIG, EngineSpecificSettings, Quality, TTSBackend, Voice, widget_parent
from calibre.spell.break_iterator import PARAGRAPH_SEPARATOR, split_into_sentences_for_tts from calibre.spell.break_iterator import PARAGRAPH_SEPARATOR, split_into_sentences_for_tts
@ -421,6 +421,9 @@ class Piper(TTSBackend):
self._audio_sink.setVolume(s.volume) self._audio_sink.setVolume(s.volume)
# On Windows, the buffer is zero causing data to be discarded. # On Windows, the buffer is zero causing data to be discarded.
# Ensure we have a nice large buffer on all platforms. # Ensure we have a nice large buffer on all platforms.
# However, on Linux changing the buffer size causes audio to not
# play on some systems. See https://www.mobileread.com/forums/showthread.php?t=363881
if not iswindows and not ismacos:
self._audio_sink.setBufferSize(2 * 1024 * 1024) 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()