简体   繁体   中英

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.

I will save text in txt file and how pyttsx can read that text from txt file and can speak?

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 ?

actually my real motto is using wit.ai with pyttsx how can I do it ?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM