SUSE_audio_assistant/test/pyttsx_test.py

20 lines
474 B
Python
Raw Normal View History

import pyttsx3
def text_to_speech(text):
# Initialize the TTS engine
engine = pyttsx3.init()
# Set properties (optional)
engine.setProperty('rate', 130) # Speed of speech
engine.setProperty('volume', 0.6) # Volume level (0.0 to 1.0)
# Convert text to speech
engine.say(text)
# Wait for the speech to finish
engine.runAndWait()
# Example usage
text = "Hello, this is a simple text-to-speech example in Python."
text_to_speech(text)