Files
auracast-translator/text_to_speech/text_to_speech.py

20 lines
559 B
Python

import os
import subprocess
TTS_DIR = os.path.join(os.path.dirname(__file__))
def synthesize(text, model="en_US-lessac-medium", output_file="out.wav"):
pwd = os.getcwd()
os.chdir(TTS_DIR)
ret = subprocess.run(['piper', '--model', model, '--output_file', output_file], input=text.encode('utf-8'), check=True)
os.chdir(pwd)
return ret.returncode, ret.stdout, ret.stderr
if __name__ == "__main__":
r, stout, sterr = synthesize("Hello, how are you?", "en_US-lessac-medium", "hello.wav")
print(r)
print(stout)
print(sterr)