Python調(diào)用pyttsx3實(shí)現(xiàn)離線文字轉(zhuǎn)語音的方式
pyttsx3是 Python 中的文本到語音的離線轉(zhuǎn)換庫。
安裝依賴:
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")
改變聲音、語速和音量:
import pyttsx3 engine = pyttsx3.init() # object creation # 語速 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)語音的文章就介紹到這了,更多相關(guān)Python離線文字轉(zhuǎn)語音內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python3實(shí)現(xiàn)自定義比較排序/運(yùn)算符
這篇文章主要介紹了Python3實(shí)現(xiàn)自定義比較排序/運(yùn)算符,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02Python爬取門戶論壇評(píng)論淺談Python未來發(fā)展方向
這篇文章主要介紹了如何實(shí)現(xiàn)Python爬取門戶論壇評(píng)論,附含圖片示例代碼,講解了詳細(xì)的操作過程,有需要的的朋友可以借鑒參考下,希望可以有所幫助2021-09-09使用python將一個(gè)文件分配到指定的多個(gè)文件夾
這篇文章主要為大家詳細(xì)介紹了如何使用python將一個(gè)文件分配到指定的多個(gè)文件夾,也就說將一個(gè)文件分配到一個(gè)母文件夾下的所有的子文件夾,感興趣的可以了解下2025-01-01Python socket.error: [Errno 98] Address already in use的原因和解決
這篇文章主要介紹了Python socket.error: [Errno 98] Address already in use的原因和解決方法,在Python的socket編程中可能會(huì)經(jīng)常遇到這個(gè)問題,需要的朋友可以參考下2014-08-08解決Python找不到ssl模塊問題 No module named _ssl的方法
這篇文章主要介紹了解決Python找不到ssl模塊問題 No module named _ssl的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-04-04使用python代碼進(jìn)行身份證號(hào)校驗(yàn)的實(shí)現(xiàn)示例
這篇文章主要介紹了使用python代碼進(jìn)行身份證號(hào)校驗(yàn)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11Python 函數(shù)編編程的三大法寶map+filter+reduce分享
這篇文章主要介紹了Python 函數(shù)編編程的三大法寶map,filter,reduce的分享,python利用 map 在一個(gè)可迭代對(duì)象的各項(xiàng)上調(diào)用函數(shù)的工具;利用 filter 來過濾項(xiàng);利用 reduce 把函數(shù)作用在成對(duì)的項(xiàng)上來運(yùn)行結(jié)果的工具,下面我們就來對(duì)這三者進(jìn)行詳細(xì)的介紹,需要的朋友可以參考下2022-03-03