import subprocess import os piper_model_path = os.getenv("PIPER_MODEL_PATH") piper_model_json_path = os.getenv("PIPER_MODEL_JSON_PATH") def speak(text): # some text cleanup illegal_chars = ["\n", "\r", "\t", "", "*", "`", "[", "]", "{", "}", "\"", "\'"] for char in illegal_chars: text = text.replace(char, "") #remove emojis text = text.encode('ascii', 'ignore').decode('ascii') command = f"echo \"{text}. \" | piper -q -m {piper_model_path} -c {piper_model_json_path} --output-raw | aplay -q -r 22050 -f S16_LE -t raw -" process = subprocess.run(command, shell=True, check=True) if __name__ == "__main__": speak("Hello, world. This is a tts test.")