Skip to content

Commit 7f18b89

Browse files
committed
Refactor Piper TTS WAV generation to use subprocess and improve error handling
1 parent 9d99526 commit 7f18b89

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

poor/voice.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,24 @@ class VoiceEnginePiper(VoiceEngine):
204204
def make_wav(self, text, fname):
205205
"""Generate voice output to WAV file `fname`."""
206206
text = self.transform_text(text)
207-
cmd = f"echo '{text}' | {self.command} --model /app/piper/voices/{self.voice_name} --output_file {fname}"
208-
return self.call([cmd]) == 0
207+
cmd = [
208+
self.command,
209+
"--model", f"/app/piper/voices/{self.voice_name}",
210+
"--output_file", fname
211+
]
212+
try:
213+
# Run Piper and pass text via stdin
214+
process = subprocess.Popen(
215+
cmd,
216+
stdin=subprocess.PIPE,
217+
stdout=subprocess.DEVNULL, # Suppress stdout
218+
stderr=subprocess.DEVNULL # Suppress stderr
219+
)
220+
process.communicate(input=text.encode("utf-8"))
221+
return process.returncode == 0
222+
except Exception as e:
223+
print(f"Error generating WAV: {e}")
224+
return False
209225

210226

211227

0 commit comments

Comments
 (0)