簡體   English   中英

如何在python的pyttsx3 modlue中改變聲音

[英]How to change voices in pyttsx3 modlue of python

我在我的一個 python 項目中使用 pyttsx3 模塊進行文本到語音轉換,但我無法為聲音選擇男性/女性選項。 我閱讀了https://pypi.org/project/pyttsx3/上給出的文檔,其中說使用 voices[0].id/voices[1].id 分別用於男性和女性聲音。 但是,這似乎不起作用,因為兩種聲音之間沒有顯着差異。

我的代碼:

import pyttsx3
engine = pyttsx3.init()

voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

engine.say("Hello World!")
engine.runAndWait()

任何想法如何改變聲音,還有沒有辦法改變文本到語音的語言......類似於自動翻譯的東西?

要將聲音更改為女性或男性,請使用

import pyttsx3 as p
engine = p.init()
voice = engine.getProperty('voice')
#for female
engine.setProperty(voice, "!v/f1")
#for male
engine.setProperty(voice, "!v/m1")
engine.runAndWait()
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

這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM