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

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

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

前言

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

一、pyttsx3是什么?

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

二、安裝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.引入庫

import pyttsx3

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

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

3.初始化pyttsx3引擎

engine = pyttsx3.init()

4.設(shè)置聲音

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

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

5.設(shè)置語速

engine.setProperty('rate', 150)

6.設(shè)置音量

engine.setProperty('volume', 0.8)

7.播放語音

engine.say(text)

8.保存語音

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

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

engine.runAndWait()

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

五、語音效果

由于博客中不能插入mp3文件,所以先將其轉(zhuǎn)為mp4,大家通過mp4的聲音來聽轉(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)于如何通過Python的pyttsx3庫將文字轉(zhuǎn)為音頻的文章就介紹到這了,更多相關(guān)Python 文字轉(zhuǎn)為音頻內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論