python - Pyttsx3 Will only Speak Once
问题描述
When running the following program:
import multiprocessing
import pyttsx3
from multiprocessing import Process
class _TTS:
def __init__(self):
self.engine = pyttsx3.init('espeak')
self.engine.setProperty('rate', 175)
def start(self,text_):
self.engine.say(text_)
self.engine.runAndWait()
def Speakit(words):
print('running Speakit')
tts = _TTS()
tts.start(words)
del(tts)
def testing(n):
print(n)
if n == 0:
words = 'Argument is zero'
Speakit(words)
print(words)
else:
words = 'Argument is not zero'
Speakit(words)
print(words)
if __name__=="__main__":
words = 'start'
# Speakit(words)
p1=Process(target=testing,args=(0,))
p1.start()
p1.join()
p2=Process(target=testing,args=(5,))
p2.start()
p2.join()
print("We're done")
If I comment out the Speakit in the main, the script run correctly, speaking what prints out
Watson $ python3 mp2.py
0
running Speakit
Argument is zero
5
running Speakit
Argument is not zero
We're done
It I don't comment out the Speakit in the main, the script will just speak the "Start" word and then not speak again and just hangs
python3 mp2.py
running Speakit
0
running Speakit
Don't understand why
解决方案
我已经快速旋转了您的代码。起初,由于您的 pyttsx 引擎的初始化,解释器抛出了一些重大错误。我删除了这个'espeak'
论点,然后它确实起作用了,程序也确实说出了这两行。
也许用于try/except
排除故障。
推荐阅读
- asp.net-core - 电子邮件重置密码不起作用,但帐户确认有效.NetCore
- python - 如何向 Pandas 中的每一行广播统一的随机数?
- php - 得到“E:无法纠正问题,你拿着破损的包裹。” 使用 apt-get 在 Debian 9 上安装 php 7.4 时
- python - 如何通过从其他列中减去第一列来创建新的数据框?
- excel - 将数据透视表总计复制到下一个空单元格
- python - Python / Pyserial / Arduino 将串行数据写入 txt 文件问题
- python - 从硬件细节比较 python 性能
- python - ISO时间到python中的人类可读时间
- maven - 如何配置jooq-codegen-maven,所以我只能手动运行而不是每次编译
- c# - ASP net core multipart/forma-data,两个文件