rhasspy / piper

A fast, local neural text to speech system
https://rhasspy.github.io/piper-samples/
MIT License
6.43k stars 473 forks source link

Looking for clarification on how to run/use this in Python. #143

Closed gavtography closed 1 year ago

gavtography commented 1 year ago

The documentation is a bit unclear. I want to simply have a python script where I input the speaker model, then the text I want it to say, then it spits the audio file on my desktop for testing purposes. This would be on Windows. Unfortunately I find the documentation to be a bit vague or lacking in detail. Any help would be appreciated, thanks!

synesthesiam commented 1 year ago

Please see the code example here: https://github.com/rhasspy/piper/blob/master/src/python_run/piper/__main__.py

Laope94 commented 1 year ago

This became easier with piper-tts package - https://pypi.org/project/piper-tts/ (python 3.9+ required). I've tried only on linux so I am not sure if it works on windows, but code is simple:

import piper
import wave

voice = piper.PiperVoice.load(model_path='/path/to/model.onnx', config_path='/path/to/config.json')

with open('/output/path/hello.wav' 'wb') as f:
    with wave.Wave_write(f) as wav:
        voice.synthesize('Your text here.', wav)