Steve Yin
Steve Yin

Reputation: 1

Pyttsx3 runs but output no sound

import pyttsx3

# Initialize the engine
engine = pyttsx3.init()

# Adjust speaking rate
rate = engine.getProperty('rate')
print(f'Current speaking rate: {rate}')
engine.setProperty('rate', 125)

# Adjust volume
volume = engine.getProperty('volume')
print(f'Current volume level: {volume}')
engine.setProperty('volume', 1.0)

# Change voice
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)  # Selecting a female voice

# Make the engine speak
engine.say("Hello World!")
engine.say(f'My current speaking rate is {rate}')

print("test")
engine.runAndWait()

engine.stop()

I have tried everything. Python and pyttsx3 are in the newest version, the drivers are up-to-date. The code compiles perfectly without errors. But there was just no sound. Is there any configuration I should do before using pyttsx3?

Upvotes: 0

Views: 54

Answers (1)

Maybe it's worth adding a pause after engine.runAndWait()?

So, the final code will look like this:

import pyttsx3
import time
# Initialize the engine
engine = pyttsx3.init()

# Adjust speaking rate
rate = engine.getProperty('rate')
print(f'Current speaking rate: {rate}')
engine.setProperty('rate', 125)

# Adjust volume
volume = engine.getProperty('volume')
print(f'Current volume level: {volume}')
engine.setProperty('volume', 1.0)

# Change voice
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)  # Selecting a female voice

# Make the engine speak
engine.say("Hello World!")
engine.say(f'My current speaking rate is {rate}')

print("test")
engine.runAndWait()
time.sleep(3)
engine.stop()

Upvotes: 0

Related Questions