gpt4 book ai didi

python - Pyttsx 语音性别

转载 作者:行者123 更新时间:2023-11-28 20:16:31 25 4
gpt4 key购买 nike

下午好,我正在学习和使用 pyttsx 进行语音,问题是我想将它用作“女性”声音,但我不能使用此代码:

import pyttsx as pt
from pyttsx import voice
engine = pt.init()
voices = engine.getProperty('voices')
#engine.setProperty('gender', 'female') # also does not work
engine.setProperty('female', voice.Voice.gender) #not even
engine.setProperty('female', voice.gender) #does not work
engine.setProperty('voice', voices[4].id)
engine.say("Hello World")
engine.runAndWait()


class Voice(object):
def __init__(self, id, name=None, languages=[], gender=None, age=None):
self.id = id
self.name = name
self.languages = languages
self.gender = gender
self.age = age

最佳答案

我使用以下代码遍历声音以找到女声

import pyttsx
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id)
print voice.id
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

在我的 Windows 10 机器上,女声是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0

所以我把代码改成了这样

import pyttsx
engine = pyttsx.init()
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

关于python - Pyttsx 语音性别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42845942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com