Is this intended behavior? #240
|
i have a pipeline that "chunks" text using 'nltk', and randomly a "." made it into the text to audio queue, to my surprise this raises an error: code: personally, i preferred if there is no audio being generated piper would still make a 0s audio file. |
Replies: 1 comment
|
This is an edge case in the current
If your desired contract is “always create a valid WAV, even when it has zero frames”, initialize the format yourself and tell Piper not to set it lazily: import wave
from piper import PiperVoice
voice = PiperVoice.load("pipermodels/en_GB-alan-medium.onnx")
with wave.open("test.wav", "wb") as wav_file:
wav_file.setframerate(voice.config.sample_rate)
wav_file.setsampwidth(2) # int16 PCM
wav_file.setnchannels(1) # Piper currently emits mono
voice.synthesize_wav(
". . . ",
wav_file,
set_wav_format=False,
)For normal text this writes the audio as usual. For input that yields no chunks, it closes as a valid mono/16-bit WAV with I would treat the exception as a small API edge-case/bug: the current |
This is an edge case in the current
synthesize_wavimplementation, rather than an intentional WAV representation.voice.synthesize()skips empty phoneme lists, so punctuation-only input can produce zeroAudioChunks (source).synthesize_wav()initializes the WAV format only when it receives the first chunk (source). With". . . "there is no first chunk, so Python'swavewriter reachesclose()withoutnchannelsever being set and raises the error you saw.If your desired contract is “always create a valid WAV, even when it has zero frames”, initialize the format yourself and tell Piper not to set it lazily: