Pyttsx 语音性别

Ald*_* OH 2 python voice python-2.7 pyttsx

下午好,我正在学习并使用 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
Run Code Online (Sandbox Code Playgroud)

小智 5

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

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()
Run Code Online (Sandbox Code Playgroud)

在我的 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() 
Run Code Online (Sandbox Code Playgroud)


小智 5

如果你使用 linux/espeak ...

在这里更改代码 engine.setProperty('voice', 'english+f1')

你可以通过添加 f1 到 f4 来改变声音