import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")
# coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# __author__ = '郭 璞'
# __date__ = '2016/8/6'
# __Desc__ = 文字转语音输出
import pyttsx
engine = pyttsx.init()
engine.say('hello world')
engine.say('你好,郭璞')
engine.runAndWait()
# 朗读一次
engine.endLoop()
pyttsx.init([driverName : string, debug : bool]) → pyttsx.Engine
| 方法签名 | 参数列表 | 返回值 | 简单释义 |
| connect(topic : string, cb : callable) | topic:要描述的事件名称;cb:回调函数 | → dict | 在给定的topic上添加回调通知 |
| disconnect(token : dict) | token:回调失联的返回标记 | Void | 结束连接 |
| endLoop() | None | → None | 简单来说就是结束事件循环 |
| getProperty(name : string) | name有这些枚举值“rate, vioce,vioces,volumn | → object | 获取当前引擎实例的属性值 |
| setProperty(name : string) | name有这些枚举值“rate, vioce,vioces,volumn | → object | 设置当前引擎实例的属性值 |
| say(text : unicode, name : string) | text:要进行朗读的文本数据; name: 关联发音人,一般用不到 | → None | 预设要朗读的文本数据,这也是“万事俱备,只欠东风”中的“万事俱备” |
| runAndWait() | None | → None | 这个方法就是“东风”了。当事件队列中事件全部清空的时候返回 |
| startLoop([useDriverLoop : bool]) | useDriverLoop:是否启用驱动循环 | → None | 开启事件队列 |
import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
import pyttsx
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 = pyttsx.init()
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
import pyttsx
def onWord(name, location, length):
print 'word', name, location, length
if location > 10:
engine.stop()
engine = pyttsx.init()
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
engine = pyttsx.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 = pyttsx.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', rate+50)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
engine = pyttsx.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 = pyttsx.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 = pyttsx.init()
engine.say('The quick brown fox jumped over the lazy dog.', 'fox')
engine.startLoop()
engine = pyttsx.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()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有