piper
piper copied to clipboard
Speech truncated when piping output
When I try to generate speech piped directly to aplay, the audio ends prematurely.
For example, when I generate a .wav file and then play it back, I hear the full input tongue twister:
$ echo "Fuzzy Wuzzy was a bear. Fuzzy Wuzzy had no hair. Fuzzy Wuzzy wasn’t fuzzy, was he?" \
| piper --model en_US-ryan-low.onnx > test.wav
WARNING:piper.voice:Missing phoneme from id map: ̩
$ aplay test.wav
Playing WAVE 'foo.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
But if I try to pipe directly to aplay without generating a .wav, The audio stops after "has no hair", and I get a traceback
$ echo "Fuzzy Wuzzy was a bear. Fuzzy Wuzzy had no hair. Fuzzy Wuzzy wasn’t fuzzy, was he?" \
| piper --model en_US-ryan-low.onnx \
| aplay -r 16000 -f S16_LE -t raw -
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
Traceback (most recent call last):
File "/home/steinbro/.local/share/uv/tools/piper-tts/lib/python3.11/site-packages/piper/__main__.py", line 151, in main
voice.synthesize(text, wav_file, **synthesize_args)
File "/home/steinbro/.local/share/uv/tools/piper-tts/lib/python3.11/site-packages/piper/voice.py", line 103, in synthesize
wav_file.writeframes(audio_bytes)
File "/home/steinbro/.local/share/uv/python/cpython-3.11.12-linux-aarch64-gnu/lib/python3.11/wave.py", line 560, in writeframes
self._patchheader()
File "/home/steinbro/.local/share/uv/python/cpython-3.11.12-linux-aarch64-gnu/lib/python3.11/wave.py", line 615, in _patchheader
curpos = self._file.tell()
^^^^^^^^^^^^^^^^^
OSError: [Errno 29] Illegal seek
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/steinbro/.local/bin/piper", line 10, in <module>
sys.exit(main())
^^^^^^
File "/home/steinbro/.local/share/uv/tools/piper-tts/lib/python3.11/site-packages/piper/__main__.py", line 150, in main
with wave.open(sys.stdout.buffer, "wb") as wav_file:
File "/home/steinbro/.local/share/uv/python/cpython-3.11.12-linux-aarch64-gnu/lib/python3.11/wave.py", line 453, in __exit__
self.close()
File "/home/steinbro/.local/share/uv/python/cpython-3.11.12-linux-aarch64-gnu/lib/python3.11/wave.py", line 567, in close
self._patchheader()
File "/home/steinbro/.local/share/uv/python/cpython-3.11.12-linux-aarch64-gnu/lib/python3.11/wave.py", line 615, in _patchheader
curpos = self._file.tell()
^^^^^^^^^^^^^^^^^
OSError: [Errno 29] Illegal seek