Spaces:
Running
Running
import subprocess | |
def speak_text_festival(text): | |
""" | |
Uses Festival to speak the given text. | |
""" | |
command = f'(SayText "{text}")' | |
try: | |
# Popen is used to run the Festival command. | |
# We pass the command to Festival's standard input. | |
process = subprocess.Popen(['festival', '--pipe'], | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
text=True) # text=True for string input/output | |
stdout, stderr = process.communicate(input=command) | |
if process.returncode != 0: | |
print(f"Error speaking text with Festival: {stderr}") | |
# else: | |
# print(f"Festival output: {stdout}") # Uncomment to see Festival's stdout | |
except FileNotFoundError: | |
print("Error: Festival executable not found. Make sure Festival is installed and in your PATH.") | |
except Exception as e: | |
print(f"An unexpected error occurred: {e}") | |
# Example usage: | |
speak_text_festival("Good morning, welcome to Festival.") | |
speak_text_festival("This is an example of Python interacting with Festival.") | |