2019-09-25 14:59:08 5866瀏覽
今天千鋒扣丁學(xué)堂Python培訓(xùn)老師給大家分享一篇關(guān)于利用pyttsx3文字轉(zhuǎn)語音過程詳解,文中通過示例代碼介紹的非常詳細(xì),下面我們一起來看一下吧。
# -*- coding: utf-8 -*- import pyttsx3 engine = pyttsx3.init() with open("all.txt",'r',encoding='utf-8') as f: while 1: line = f.readline() print(line, end = '') engine.say(line) engine.runAndWait() import pyttsx3 with open('all.txt','r',encoding='utf-8') as f: line = f.read()#文件不大,一次性讀取 engine = pyttsx3.init() #調(diào)整頻率 rate = engine.getProperty('rate') engine.setProperty('rate', rate-50) # 調(diào)整音量 volume = engine.getProperty('volume') engine.setProperty('volume', volume+0.25) engine.say(line) engine.runAndWait()
pip install pyttsx3
pyttsx.init([driverName : string, debug : bool]) → pyttsx.Engine
import pyttsx3 engine = pyttsx3.init() engine.say('Sally sells seashells by the seashore.') engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
import pyttsx3 def onStart(name): print 'starting', name def onWord(name, location, length): print 'word', name, location, length def onEnd(name, completed): print 'finishing', name, completed engine = pyttsx3.init() engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
import pyttsx3 def onWord(name, location, length): print('word', name, location, length) if location > 10: engine.stop() engine = pyttsx3.init() engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
engine = pyttsx3.init() voices = engine.getProperty('voices') for voice in voices: engine.setProperty('voice', voice.id) engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
engine = pyttsx3.init() rate = engine.getProperty('rate') engine.setProperty('rate', rate+50) engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
engine = pyttsx3.init() volume = engine.getProperty('volume') engine.setProperty('volume', volume-0.25) engine.say('The quick brown fox jumped over the lazy dog.') engine.runAndWait()
engine = pyttsx3.init() def onStart(name): print('starting', name) def onWord(name, location, length): print('word', name, location, length) def onEnd(name, completed): print('finishing', name, completed) if name == 'fox': engine.say('What a lazy dog!', 'dog') elif name == 'dog': engine.endLoop() engine = pyttsx3.init() engine.say('The quick brown fox jumped over the lazy dog.', 'fox') engine.startLoop()
engine = pyttsx3.init() engine.say('The quick brown fox jumped over the lazy dog.', 'fox') engine.startLoop(False) # engine.iterate() must be called inside externalLoop() externalLoop() engine.endLoop()
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進(jìn)入Python全棧開發(fā)免費公開課】
查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>