Python調(diào)用pyttsx3實現(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)選項的朗讀功能的單行用法
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實現(xiàn)離線文字轉(zhuǎn)語音的文章就介紹到這了,更多相關(guān)Python離線文字轉(zhuǎn)語音內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python爬取門戶論壇評論淺談Python未來發(fā)展方向
這篇文章主要介紹了如何實現(xiàn)Python爬取門戶論壇評論,附含圖片示例代碼,講解了詳細(xì)的操作過程,有需要的的朋友可以借鑒參考下,希望可以有所幫助2021-09-09Python socket.error: [Errno 98] Address already in use的原因和解決
這篇文章主要介紹了Python socket.error: [Errno 98] Address already in use的原因和解決方法,在Python的socket編程中可能會經(jīng)常遇到這個問題,需要的朋友可以參考下2014-08-08解決Python找不到ssl模塊問題 No module named _ssl的方法
這篇文章主要介紹了解決Python找不到ssl模塊問題 No module named _ssl的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04Python 函數(shù)編編程的三大法寶map+filter+reduce分享
這篇文章主要介紹了Python 函數(shù)編編程的三大法寶map,filter,reduce的分享,python利用 map 在一個可迭代對象的各項上調(diào)用函數(shù)的工具;利用 filter 來過濾項;利用 reduce 把函數(shù)作用在成對的項上來運行結(jié)果的工具,下面我們就來對這三者進行詳細(xì)的介紹,需要的朋友可以參考下2022-03-03