当前位置:网站首页>语音模块:pyttsx变声项目
语音模块:pyttsx变声项目
2022-06-23 11:53:00 【无水先生】
一、说明
程序员们好,我们将在本教程中看到如何使用 Python 中的 pyttsx3 将语音转换为文本。也可以将人的语音实现变音、变速等处理。
pyttsx3 库是 Python 中的文本到语音转换库。该库离线工作,使其优于其他库。该库适用于 Python 2 和 Python 3。
二、安装
在系统中使用命令提示符,使用以下命令安装 pyttsx3 库。
pip install pyttsx3
三、基本用法
下面给出了如何使用这个库的说明和解释。
import pyttsx3 #导入库
def textToVoice():
eng = pyttsx3.init() #初始化一个实例
eng.say("这是一个演示如何使用 python 中的 pyttsx3 库将文本转换为语音。")
# say 用于传递要说的文本的方法
eng.runAndWait() # 运行并处理语音命令if __name__ == "__main__":
textToVoice()解释
在运行 python 文件时,会触发 textToVoice() 函数。我们需要先导入 pyttsx3 库。在函数内部,一个实例在变量“eng”中初始化。然后,eng 将其从文本转换为语音,编译器在调用 runAndWait() 方法时告诉它。
了解 TTS 引擎
Pyttsx3 是 python 中一个非常易于使用的模块,可将文本转换为语音。该模块支持两种声音:女声和男声。
它包括三个 TTS(文本到语音)引擎:
sapi5 – 在 Windows 中提供男性和女性的声音
nsss – 在 MAC-OS 中提供男性和女性的声音
espeak – 在所有其他环境中提供男性和女性的声音
在 pyttsx3 中将声音从男性变为女性
说明如何将一种形式的语音转换为另一种形式的语音说明
import pyttsx3 #import the library
def voiceChange():
eng = pyttsx3.init() #initialize an instance
voice = eng.getProperty('voices') #get the available voices
# eng.setProperty('voice', voice[0].id) #set the voice to index 0 for male voice
eng.setProperty('voice', voice[1].id) #changing voice to index 1 for female voice
eng.say("This is a demonstration of how to convert index of voice using pyttsx3 library in python.") #say method for passing text to be spoken
eng.runAndWait() #run and process the voice command
if __name__ == "__main__":
voiceChange()解释
在运行 python 文件时,会调用 voiceChange() 函数。在函数内部,模块的一个实例被初始化。在语音库中,我们获取可用的语音,然后使用 setProperty() 方法,我们相应地更改语音 id 以带来男声或女声。 say 方法包含要说的文本。 runAndWait() 方法运行并处理语音命令。
四、结论
该模块还有许多其他功能。我们可以更改语音的速率和音量,甚至可以将语音保存到文件中。该库离线工作,在各种基于语音命令的项目中非常方便。
边栏推荐
- Proof and application of Chebyshev inequality
- Face the future calmly and strive to improve yourself
- Attack and defense drill collection | 3 stages, 4 key points, interpretation of the blue team defense whole process outline
- Redis 入门-第四篇-数据结构与对象-跳跃表
- How does easygbs solve the abnormal use of intercom function?
- Google Earth Engine(GEE)——GEDI L2A Vector Canopy Top Height (Ver
- navicat定时任务无效
- 【零基础微信小程序】基于百度大脑人像分割的证件照换底色小程序实战开发
- Leetcode 1209. 删除字符串中的所有相邻重复项 II(初版本没过)
- Monitor the cache update of Eureka client
猜你喜欢

PPT制作3D旋转动画从入门到进阶

4路电话+1路千兆以太网4路PCM电话光端机

【零基础微信小程序】基于百度大脑人像分割的证件照换底色小程序实战开发

Attack and defense drill collection | 3 stages, 4 key points, interpretation of the blue team defense whole process outline

64路PCM电话光端机64路电话+2路百兆以太网电话光端机64路电话PCM语音光端机

Leetcode 1209. 删除字符串中的所有相邻重复项 II(牛逼,终于过了)

From 0 to 1, how does the IDE improve the efficiency of end-to-end R & D| DX R & D mode

KDD 2022 | 基于分层图扩散学习的癫痫波预测

Blue Bridge Cup single chip microcomputer (I) -- turn off peripherals and turn off led

电脑坏了,换了台电脑,装node环境的时候出了问题,报错URL not defined
随机推荐
RF Analyzer Demo搭建
Surprise! Amd acquires Xilinx with USD 35billion!
Mysql, how to calculate the maximum value using stored procedures
4E1 PDH光端机19英寸机架式单纤传输20km E1接口光纤网络光端机
凭借32量子比特!Rigetti Computing打入英国量子计算市场
Leetcode 1209. 删除字符串中的所有相邻重复项 II(牛逼,终于过了)
EasyGBS如何解决对讲功能使用异常?
目前 在哪里开户是最安全正规的?
Vous comprenez vraiment la capacité de sortie de LDO!?
电感有极性吗?
4K-HDMI光端机1路[email protected] HDMI2.0光端机 HDMI高清视频光端机
Open classes are short videos! Tonight, I will teach you how to realize accurately!
Oversampling Series III: quantization error and oversampling rate
运行时应用自我保护(RASP):应用安全的自我修养
Daily question 7-1652 Defuse the bomb
Gary Marcus发文:AI研究者需要知道的三个来自语言学家的观点
Where is the safest and most formal way to open an account at present?
Necessary software for automation or electrical specialty
Use monotone stack to solve problems
视频数据标注工具与平台(数据标注公司)