本文介绍了Pyttsx 语音性别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,我正在学习并使用 pyttsx 进行语音,问题是我想将其用作女性"语音,但我无法使用此代码来实现:

Good afternoon, I'm learning and using pyttsx for speech, the thing is that I want to use it as a "female" voice but I can not do it using this code:

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

推荐答案

如果你使用 linux/espeak...

if you use linux/espeak...

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

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

you can change the voice by adding f1 until f4

这篇关于Pyttsx 语音性别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:40