A few touch ups to the Piper stuff.

This commit is contained in:
Storm Dragon
2026-01-09 18:00:07 -05:00
parent 862504b425
commit aa14e665a6
5 changed files with 23 additions and 9 deletions

View File

@@ -100,7 +100,7 @@ git status
- **Runtime**: python3, pygobject-3.0, pluggy, AT-SPI2 - **Runtime**: python3, pygobject-3.0, pluggy, AT-SPI2
- **Build**: meson, ninja, gettext - **Build**: meson, ninja, gettext
- **Optional**: dasbus (for D-Bus service), BrlTTY, speech-dispatcher - **Optional**: dasbus (for D-Bus service), BrlTTY, speech-dispatcher, piper-tts
Install build dependencies on Arch Linux: Install build dependencies on Arch Linux:
```bash ```bash

View File

@@ -64,6 +64,10 @@ toolkit, OpenOffice/LibreOffice, Gecko, WebKitGtk, and KDE Qt toolkit.
* **python-speechd** - Python bindings for Speech Dispatcher (recommended) * **python-speechd** - Python bindings for Speech Dispatcher (recommended)
* **gstreamer-1.0** - GStreamer streaming media framework (for sounds) * **gstreamer-1.0** - GStreamer streaming media framework (for sounds)
* **piper-tts** - Piper neural text-to-speech engine (optional)
Piper voice models are typically stored under `~/.local/share/piper/voices` or
`/usr/share/piper-voices`.
### Braille Support (Optional) ### Braille Support (Optional)

View File

@@ -13,6 +13,7 @@ dependencies = [
"pygobject>=3.18", "pygobject>=3.18",
"brlapi; extra == 'braille'", "brlapi; extra == 'braille'",
"python-speechd; extra == 'speech'", "python-speechd; extra == 'speech'",
"piper-tts; extra == 'piper'",
"louis; extra == 'braille'" "louis; extra == 'braille'"
] ]

View File

@@ -80,6 +80,8 @@ class PiperAudioPlayer:
if not _gstreamerAvailable: if not _gstreamerAvailable:
return False return False
self._resetPipeline()
try: try:
self._pipeline = Gst.Pipeline.new("piper-audio") self._pipeline = Gst.Pipeline.new("piper-audio")
@@ -148,6 +150,15 @@ class PiperAudioPlayer:
debug.printMessage(debug.LEVEL_WARNING, msg, True) debug.printMessage(debug.LEVEL_WARNING, msg, True)
return False return False
def _resetPipeline(self):
"""Reset the GStreamer pipeline and related elements."""
if self._pipeline is not None:
self._pipeline.set_state(Gst.State.NULL)
self._pipeline = None
self._appsrc = None
self._volume = None
self._initialized = False
def _onMessage(self, bus, message): def _onMessage(self, bus, message):
"""Handle GStreamer bus messages.""" """Handle GStreamer bus messages."""
if message.type == Gst.MessageType.EOS: if message.type == Gst.MessageType.EOS:
@@ -173,8 +184,8 @@ class PiperAudioPlayer:
""" """
if sampleRate != self._sampleRate: if sampleRate != self._sampleRate:
self._sampleRate = sampleRate self._sampleRate = sampleRate
self._initialized = False
self.stop() self.stop()
self._resetPipeline()
self._init() self._init()
def setVolume(self, volumeLevel): def setVolume(self, volumeLevel):
@@ -239,7 +250,6 @@ class PiperAudioPlayer:
with self._lock: with self._lock:
self._playing = True self._playing = True
stopRequested = False
self._completionCallback = completionCallback self._completionCallback = completionCallback
@@ -289,9 +299,4 @@ class PiperAudioPlayer:
def shutdown(self): def shutdown(self):
"""Shut down the audio player and release resources.""" """Shut down the audio player and release resources."""
self.stop() self.stop()
self._initialized = False self._resetPipeline()
if self._pipeline is not None:
self._pipeline.set_state(Gst.State.NULL)
self._pipeline = None
self._appsrc = None
self._volume = None

View File

@@ -79,15 +79,19 @@ class PiperVoiceManager:
VOICE_SEARCH_PATHS = [ VOICE_SEARCH_PATHS = [
"~/.local/share/piper/voices", "~/.local/share/piper/voices",
"~/.local/share/piper-voices",
"~/.local/share/piper-tts/voices", "~/.local/share/piper-tts/voices",
"~/.config/piper/voices", "~/.config/piper/voices",
"~/.config/piper-tts/voices",
"$XDG_DATA_HOME/piper/voices", "$XDG_DATA_HOME/piper/voices",
"$XDG_DATA_HOME/piper-voices",
"$XDG_DATA_HOME/piper-tts/voices", "$XDG_DATA_HOME/piper-tts/voices",
"$XDG_DATA_HOME/cthulhu/piper-voices", "$XDG_DATA_HOME/cthulhu/piper-voices",
"/usr/share/piper/voices", "/usr/share/piper/voices",
"/usr/share/piper-voices", "/usr/share/piper-voices",
"/usr/share/piper-tts/voices", "/usr/share/piper-tts/voices",
"/usr/local/share/piper/voices", "/usr/local/share/piper/voices",
"/usr/local/share/piper-voices",
"/usr/local/share/piper-tts/voices", "/usr/local/share/piper-tts/voices",
] ]