| from piper import PiperVoice | |
| import subprocess | |
| import wave | |
| import tempfile | |
| VOICE_PATH = "voices/fr/fr_FR/siwis/medium/fr_FR-siwis-medium.onnx" | |
| def generate(sentence): | |
| output_wav = tempfile.mktemp( | |
| suffix=".wav" | |
| ) | |
| process = subprocess.Popen( | |
| [ | |
| "piper", | |
| "--model", | |
| VOICE_PATH, | |
| "--output_file", | |
| output_wav | |
| ], | |
| stdin=subprocess.PIPE, | |
| text=True | |
| ) | |
| process.communicate(sentence) | |
| return output_wav |