如何利用pyttsx3库搭建一个基础的语音合成TTS服务?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1144个文字,预计阅读时间需要5分钟。
操作系统:Windows 10_x64Python 版本:Python 3.9.2_x64pyttsx3 版本:2.90pyttsx3 是一个 TTS 引擎包装器,支持连接 SAPI5、NSSS(NSSpeechSynthesizer)、espeak 等引擎,实现统一的 TTS 接口。pyttsx3 地址:https://p
操作系统:Windows 10_x64 python版本:Python 3.9.2_x64 pyttsx3版本: 2.90 pyttsx3是一个tts引擎包装器,可对接SAPI5、NSSS(NSSpeechSynthesizer)、espeak等引擎,实现统一的tts接口。pyttsx3的地址:pypi.org/project/pyttsx3/
帮助文档地址:pyttsx3.readthedocs.org/
安装pyttsx3依赖包:
pip install pyttsx3 接口介绍
1、init接口
使用的具体引擎可以在init里面指定:
pyttsx3.init([driverName : string, debug : bool]) → pyttsx3.Engine 入参: driverName : 可选,用于指定tts引擎,若未指定,则使用系统默认引擎。- sapi5 - windows环境
- nsss - Mac OS X环境
- espeak - 非windows和Mac OS X 的其它系统
2、engine接口
使用init接口初始完毕,会返回engine对象。 engine对象的方法如下:- connect
- disconnect
- endLoop
- getProperty
- isBusy
- iterate
- runAndWait
- save_to_file
- say
- setProperty
- startLoop
- stop
#! /usr/bin/env python3 #-*- coding:utf-8 -*- # pip install pyttsx3 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.connect('started-utterance', onStart) engine.connect('started-word', onWord) engine.connect('finished-utterance', onEnd) # 语音转文本测试(直接播放) engine.say("I will speak this text") engine.say('I will speak this text!', 'speak') # 注册 speak 关键字,进行事件通知 engine.say("我可以说话了") # 语音转文本测试(文件存储到磁盘) engine.save_to_file('我可以说话了', 'test.mp3') # 运行并等待 engine.runAndWait() 运行效果如下:
2、使用pyttsx3搭建简单的tts服务
这里使用tornado搭建简单的pan.baidu.com/s/1Dc8zlL2fs8p4ebF916WyXQ可关注微信公众号(聊聊博文)后回复 2022040401 获得提取码。
微信公众号:本文共计1144个文字,预计阅读时间需要5分钟。
操作系统:Windows 10_x64Python 版本:Python 3.9.2_x64pyttsx3 版本:2.90pyttsx3 是一个 TTS 引擎包装器,支持连接 SAPI5、NSSS(NSSpeechSynthesizer)、espeak 等引擎,实现统一的 TTS 接口。pyttsx3 地址:https://p
操作系统:Windows 10_x64 python版本:Python 3.9.2_x64 pyttsx3版本: 2.90 pyttsx3是一个tts引擎包装器,可对接SAPI5、NSSS(NSSpeechSynthesizer)、espeak等引擎,实现统一的tts接口。pyttsx3的地址:pypi.org/project/pyttsx3/
帮助文档地址:pyttsx3.readthedocs.org/
安装pyttsx3依赖包:
pip install pyttsx3 接口介绍
1、init接口
使用的具体引擎可以在init里面指定:
pyttsx3.init([driverName : string, debug : bool]) → pyttsx3.Engine 入参: driverName : 可选,用于指定tts引擎,若未指定,则使用系统默认引擎。- sapi5 - windows环境
- nsss - Mac OS X环境
- espeak - 非windows和Mac OS X 的其它系统
2、engine接口
使用init接口初始完毕,会返回engine对象。 engine对象的方法如下:- connect
- disconnect
- endLoop
- getProperty
- isBusy
- iterate
- runAndWait
- save_to_file
- say
- setProperty
- startLoop
- stop
#! /usr/bin/env python3 #-*- coding:utf-8 -*- # pip install pyttsx3 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.connect('started-utterance', onStart) engine.connect('started-word', onWord) engine.connect('finished-utterance', onEnd) # 语音转文本测试(直接播放) engine.say("I will speak this text") engine.say('I will speak this text!', 'speak') # 注册 speak 关键字,进行事件通知 engine.say("我可以说话了") # 语音转文本测试(文件存储到磁盘) engine.save_to_file('我可以说话了', 'test.mp3') # 运行并等待 engine.runAndWait() 运行效果如下:
2、使用pyttsx3搭建简单的tts服务
这里使用tornado搭建简单的pan.baidu.com/s/1Dc8zlL2fs8p4ebF916WyXQ可关注微信公众号(聊聊博文)后回复 2022040401 获得提取码。
微信公众号:
