Pyttsx3 运行但没有输出声音

问题描述 投票:0回答:1
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()

我已经尝试了一切。 Python 和

pyttsx3
是最新版本,驱动程序是最新的。代码完美编译,没有错误。但就是没有声音。使用前需要做什么配置吗
pyttsx3

python pyttsx3 pyttsx
1个回答
0
投票

也许值得在

engine.runAndWait()
之后添加一个暂停?

所以,最终的代码将如下所示:

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()
© www.soinside.com 2019 - 2024. All rights reserved.