Python調(diào)用pyttsx3實(shí)現(xiàn)離線文字轉(zhuǎn)語(yǔ)音的方式
pyttsx3是 Python 中的文本到語(yǔ)音的離線轉(zhuǎn)換庫(kù)。
安裝依賴:
pip install pyttsx3
Linux 安裝要求:
apt update && apt install espeak ffmpeg libespeak1
使用方式:
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()帶默認(rèn)選項(xiàng)的朗讀功能的單行用法
import pyttsx3
pyttsx3.speak("I will speak this text")改變聲音、語(yǔ)速和音量:
import pyttsx3
engine = pyttsx3.init() # object creation
# 語(yǔ)速
rate = engine.getProperty('rate') # getting details of current speaking rate
print (rate) #printing current voice rate
engine.setProperty('rate', 125) # setting up new voice rate
# 音量
volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1)
print (volume) #printing current volume level
engine.setProperty('volume',1.0) # setting up volume level between 0 and 1
# 聲音
voices = engine.getProperty('voices') #getting details of current voice
#engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female
engine.say("Hello World!")
engine.say('My current speaking rate is ' + str(rate))
engine.runAndWait()
engine.stop()
# 保存到文件
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()到此這篇關(guān)于Python調(diào)用pyttsx3實(shí)現(xiàn)離線文字轉(zhuǎn)語(yǔ)音的文章就介紹到這了,更多相關(guān)Python離線文字轉(zhuǎn)語(yǔ)音內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python 利用pyttsx3文字轉(zhuǎn)語(yǔ)音過(guò)程詳解
- Python語(yǔ)音合成的項(xiàng)目實(shí)戰(zhàn)(PyQt5+pyttsx3)
- 如何通過(guò)Python的pyttsx3庫(kù)將文字轉(zhuǎn)為音頻
- Python語(yǔ)音合成之第三方庫(kù)gTTs/pyttsx3/speech橫評(píng)(內(nèi)附使用方法)
- python利用pyttsx3 API實(shí)現(xiàn)文本轉(zhuǎn)語(yǔ)音處理
- Python文本到語(yǔ)音轉(zhuǎn)換庫(kù)pyttsx3的安裝及使用全面指南
- Python pyttsx3庫(kù)實(shí)現(xiàn)文本轉(zhuǎn)語(yǔ)音功能的示例
相關(guān)文章
django框架基于模板 生成 excel(xls) 文件操作示例
這篇文章主要介紹了django框架基于模板 生成 excel(xls) 文件操作,結(jié)合具體實(shí)例形式分析了Django框架基于模板生成excel的實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2019-06-06
python密碼學(xué)文件解密實(shí)現(xiàn)教程
這篇文章主要為大家介紹了python密碼學(xué)文件解密實(shí)現(xiàn)教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
python 讀取文本文件的行數(shù)據(jù),文件.splitlines()的方法
今天小編就為大家分享一篇python 讀取文本文件的行數(shù)據(jù),文件.splitlines()的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
python通過(guò)opencv實(shí)現(xiàn)圖片裁剪原理解析
這篇文章主要介紹了python通過(guò)opencv實(shí)現(xiàn)圖片裁剪原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01
用tensorflow實(shí)現(xiàn)彈性網(wǎng)絡(luò)回歸算法
這篇文章主要介紹了用tensorflow實(shí)現(xiàn)彈性網(wǎng)絡(luò)回歸算法2018-01-01
在dataframe兩列日期相減并且得到具體的月數(shù)實(shí)例
今天小編就為大家分享一篇在dataframe兩列日期相減并且得到具體的月數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
Python學(xué)習(xí)筆記之Django創(chuàng)建第一個(gè)數(shù)據(jù)庫(kù)模型的方法
今天小編就為大家分享一篇Python學(xué)習(xí)筆記之Django創(chuàng)建第一個(gè)數(shù)據(jù)庫(kù)模型的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08

