Skip to content

Commit

Permalink
fix: streaming TTS in non pulseaudio systems
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jan 29, 2025
1 parent 087da0e commit 7ab2d59
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ovos_plugin_manager/templates/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,16 @@ class StreamingTTSCallbacks:
def __init__(self, bus, play_args=None, tts_config=None):
self.bus = bus
self.config = tts_config or {}
self.play_args = play_args or ["paplay"]
if not play_args:
# Check for the available player depending on the system's audio server.
player = shutil.which("pw-play") or shutil.which("paplay") or shutil.which("ffplay")
if not player:
raise RuntimeError("No audio player found (please install 'ffmpeg' or 'pulseaudio-utils').")
self.play_args = [player]
if player.endswith("ffplay"):
self.play_args += ["-autoexit", "-nodisp", "-"]
else:
self.play_args = play_args
self._process = None

def stream_start(self, message=None):
Expand All @@ -1129,9 +1138,7 @@ def stream_start(self, message=None):
- "recognizer_loop:audio_output_start"
"""
LOG.info(f"TTS stream start: {self.__class__.__name__}")
message = message or \
dig_for_message() or \
Message("speak")
message = message or dig_for_message() or Message("speak")

# we don't use the regular PlaybackThread here, we need to handle recognizer_loop:audio_output_start
if not self.config.get("pulse_duck", False):
Expand All @@ -1144,7 +1151,7 @@ def stream_start(self, message=None):
self._process = subprocess.Popen(self.play_args, stdin=subprocess.PIPE)

def stream_chunk(self, chunk):
"""play streamed chunk of audio"""
"""Play streamed chunk of audio"""
LOG.debug(f"TTS stream chunk: {self.__class__.__name__} - {len(chunk)} bytes")
if self._process:
self._process.stdin.write(chunk)
Expand All @@ -1158,9 +1165,7 @@ def stream_stop(self, listen=False, message=None):
- 'mycroft.mic.listen'
"""
LOG.info(f"TTS stream stop: {self.__class__.__name__}")
message = message or \
dig_for_message() or \
Message("speak")
message = message or dig_for_message() or Message("speak")

if self._process:
self._process.stdin.close()
Expand Down

0 comments on commit 7ab2d59

Please sign in to comment.