2

我下载了 pyttsx,除了声音列表只有一个声音(Microsoft Anna)之外,它似乎工作正常。我希望能够将其更改为男性声音,但我没有尝试或研究过!这是我当前的测试代码:

import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 100)

voices = engine.getProperty('voices')
for voice in voices:
    print "Using voice:", repr(voice.name)
    engine.setProperty('voice', voice.id)
    engine.setProperty('gender', 'male') #this doesn't raise an error, but also won't do anything
    engine.say("Hi there, how's you ?")
    engine.say("A B C D E F G H I J K L M")
    engine.say("N O P Q R S T U V W X Y Z")
    engine.say("0 1 2 3 4 5 6 7 8 9")
    engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")
    engine.say("Violet Indigo Blue Green Yellow Orange Red")
    engine.say("Apple Banana Cherry Date Guava")
engine.runAndWait()

这只运行一个循环。如果我说 print(voices),它会打印一个列表,其中只有一个项目。有什么建议么?

4

3 回答 3

0

既然您说您使用的是 MS Anna,我假设您使用的是 Windows 7。MS Speech Platform是我所知道的唯一一个可以为您提供额外“声音”的平台。

那里有很多商业的,但当然,大多数都需要付费,有些是免费试用的。

PYTTSX 没有额外的声音,它只为您提供访问您所拥有的工具的工具。

于 2015-07-11T19:20:49.807 回答
0

尝试这个

import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 100)

voices = engine.getProperty('voices')
for voice in range(len(voices)):
    engine.setProperty('voice', voices[voices].id)

# engine.setProperty('gender', 'male') This function won't work if you don't have any female voices in your system
于 2021-08-14T08:42:34.770 回答
0

声音存储在您可以打印的列表中。打印声音以获取系统上的所有声音。

engine = pyttsx3.init()

voices = engine.getProperty("voices")

engine.setProperty("voice", voices[1].id)
于 2021-07-27T12:23:01.010 回答