Closed brainiakk closed 3 weeks ago
I am also interested in using piper directly from python.
From the main.py I came up with a basic example on how to use the python api directly. Here for french:
import piper
from pathlib import Path
import wave
cm_path = '/path/to/models/'
model = 'fr_FR-upmc-medium'
synthesize_args = {
"speaker_id": 0,
"length_scale": 1.0,
"noise_scale": 1.0,
"noise_w": 1.0,
"sentence_silence": 0.0,
}
output_file = Path(cm_path) / 'output.wav'
voice = piper.PiperVoice.load(
model_path=cm_path + model +".onnx",
config_path=cm_path + model + ".onnx.json",
use_cuda=False)
line = "Salut tout le monde"
with wave.open(str(output_file), "wb") as wav_file:
voice.synthesize(line, wav_file, **synthesize_args)
Thanks a million @robert-elles it worked perfectly. You can add the ".onnx" to the model variable value so the config_path can only have ".json" appendage, because I think that's how all the voice models are named.
I can't find documentation on implementing piper tts in a python function with using terminal or subprocess