欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何通過(guò)Python的pyttsx3庫(kù)將文字轉(zhuǎn)為音頻

 更新時(shí)間:2023年04月15日 16:32:08   作者:空空star  
pyttsx3是一個(gè)開(kāi)源的Python文本轉(zhuǎn)語(yǔ)音庫(kù),可以將文本轉(zhuǎn)換為自然的人類(lèi)語(yǔ)音,這篇文章主要介紹了如何通過(guò)Python的pyttsx3庫(kù)將文字轉(zhuǎn)為音頻,需要的朋友可以參考下

前言

大家好,我是空空star,本篇給大家分享一下通過(guò)Python的pyttsx3庫(kù)將文字轉(zhuǎn)為音頻。

一、pyttsx3是什么?

pyttsx3是一個(gè)開(kāi)源的Python文本轉(zhuǎn)語(yǔ)音庫(kù),可以將文本轉(zhuǎn)換為自然的人類(lèi)語(yǔ)音。它提供了豐富靈活的配置選項(xiàng),可以自定義聲音,語(yǔ)速,語(yǔ)調(diào)等等,并且支持多語(yǔ)言轉(zhuǎn)換。此外,它還支持異步操作,可以在后臺(tái)自動(dòng)調(diào)用語(yǔ)音合成引擎,不會(huì)阻塞主程序。Pyttsx3可以廣泛應(yīng)用于各種領(lǐng)域,例如自動(dòng)化語(yǔ)音提示、智能語(yǔ)音助手、語(yǔ)音驗(yàn)證等等,是一個(gè)非常優(yōu)秀的Python語(yǔ)音處理庫(kù)。

二、安裝pyttsx3

pip install pyttsx3

三、查看pyttsx3版本

 pip show pyttsx3

Name: pyttsx3
Version: 2.90
Summary: Text to Speech (TTS) library for Python 2 and 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.
Home-page: https://github.com/nateshmbhat/pyttsx3

四、pyttsx3的使用

1.引入庫(kù)

import pyttsx3

2.定義需要轉(zhuǎn)換的文本

text = '大家好,我是空空star,本篇給大家分享一下文字轉(zhuǎn)音頻,這是通過(guò)pyttsx3轉(zhuǎn)換的音頻。'

3.初始化pyttsx3引擎

engine = pyttsx3.init()

4.設(shè)置聲音

# 獲取所有可用的聲音列表
voices = engine.getProperty('voices')
# 選擇一個(gè)指定語(yǔ)音(粵語(yǔ)語(yǔ)音sinji)
engine.setProperty('voice', voices[36].id)

這里我用的是mac系統(tǒng)下的粵語(yǔ)語(yǔ)音
com.apple.speech.synthesis.voice.sinji

5.設(shè)置語(yǔ)速

engine.setProperty('rate', 150)

6.設(shè)置音量

engine.setProperty('volume', 0.8)

7.播放語(yǔ)音

engine.say(text)

8.保存語(yǔ)音

local = '/Users/kkstar/Downloads/video/'
engine.save_to_file(text, local+"audio_pyttsx3.mp3")

9.等待完成語(yǔ)言轉(zhuǎn)換

engine.runAndWait()

engine.runAndWait() 用于在文本轉(zhuǎn)語(yǔ)音時(shí),等待文本轉(zhuǎn)換完成后再繼續(xù)程序的執(zhí)行。它的目的是在文本轉(zhuǎn)換為語(yǔ)音時(shí),避免出現(xiàn)程序過(guò)早結(jié)束,導(dǎo)致文本無(wú)法全部轉(zhuǎn)換的情況。

五、語(yǔ)音效果

由于博客中不能插入mp3文件,所以先將其轉(zhuǎn)為mp4,大家通過(guò)mp4的聲音來(lái)聽(tīng)轉(zhuǎn)換效果。

pyttsx3-文字轉(zhuǎn)音頻效果演示

總結(jié)

voices如下,可以選擇自己喜歡的聲音。
com.apple.speech.synthesis.voice.Alex
com.apple.speech.synthesis.voice.alice.premium
com.apple.speech.synthesis.voice.alva
com.apple.speech.synthesis.voice.amelie
com.apple.speech.synthesis.voice.anna
com.apple.speech.synthesis.voice.carmit
com.apple.speech.synthesis.voice.damayanti
com.apple.speech.synthesis.voice.daniel
com.apple.speech.synthesis.voice.diego
com.apple.speech.synthesis.voice.ellen
com.apple.speech.synthesis.voice.fiona
com.apple.speech.synthesis.voice.Fred
com.apple.speech.synthesis.voice.ioana
com.apple.speech.synthesis.voice.joana
com.apple.speech.synthesis.voice.jorge
com.apple.speech.synthesis.voice.juan
com.apple.speech.synthesis.voice.kanya
com.apple.speech.synthesis.voice.karen
com.apple.speech.synthesis.voice.kyoko
com.apple.speech.synthesis.voice.laura
com.apple.speech.synthesis.voice.lekha
com.apple.speech.synthesis.voice.luca
com.apple.speech.synthesis.voice.luciana
com.apple.speech.synthesis.voice.maged
com.apple.speech.synthesis.voice.mariska
com.apple.speech.synthesis.voice.meijia
com.apple.speech.synthesis.voice.melina
com.apple.speech.synthesis.voice.milena
com.apple.speech.synthesis.voice.moira
com.apple.speech.synthesis.voice.monica
com.apple.speech.synthesis.voice.nora
com.apple.speech.synthesis.voice.paulina
com.apple.speech.synthesis.voice.rishi
com.apple.speech.synthesis.voice.samantha
com.apple.speech.synthesis.voice.sara
com.apple.speech.synthesis.voice.satu
com.apple.speech.synthesis.voice.sinji
com.apple.speech.synthesis.voice.tessa
com.apple.speech.synthesis.voice.thomas
com.apple.speech.synthesis.voice.tingting.premium
com.apple.speech.synthesis.voice.veena
com.apple.speech.synthesis.voice.Victoria
com.apple.speech.synthesis.voice.xander
com.apple.speech.synthesis.voice.yelda
com.apple.speech.synthesis.voice.yuna
com.apple.speech.synthesis.voice.yuri
com.apple.speech.synthesis.voice.zosia
com.apple.speech.synthesis.voice.zuzana

到此這篇關(guān)于如何通過(guò)Python的pyttsx3庫(kù)將文字轉(zhuǎn)為音頻的文章就介紹到這了,更多相關(guān)Python 文字轉(zhuǎn)為音頻內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論