[英]fetch data from text file in pyttsx python
Hello respected persons, 您好尊敬的人,
I am trying to fetch data from a external text file with pyttsx
package of python language. 我正在尝试使用python语言的
pyttsx
包从外部文本文件中获取数据。
I will save text in txt file and how pyttsx
can read that text from txt file and can speak? 我将文本保存在txt文件中,而
pyttsx
如何从txt文件读取该文本并能说出来?
I am trying to do like this, 我想这样做
import pyttsx
engine = pyttsx.init()
engine.say("open file and read data from /users/exe/voice.txt")
engine.runAndWait()
engine.runAndWait()
how pyttsx
can fetch and speak data of a text file ? pyttsx
如何获取和说出文本文件的数据?
actually my real motto is using wit.ai
with pyttsx
how can I do it ? 实际上,我真正的座右铭是将
wit.ai
与pyttsx
wit.ai
使用怎么办?
I found the answer myself: I had to add two lines of code to open the file and read its lines into an array: 我自己找到了答案:我必须添加两行代码来打开文件并将其行读入数组:
import pyttsx
engine = pyttsx.init()
with open('/Users/exepaul/Desktop/a.txt') as f:
lines = f.readlines()
engine.say(lines)
engine.runAndWait()
engine.runAndWait()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.