Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Pyttsx3语音性别(女性)_Python 3.x_Pyttsx - Fatal编程技术网

Python 3.x Pyttsx3语音性别(女性)

Python 3.x Pyttsx3语音性别(女性),python-3.x,pyttsx,Python 3.x,Pyttsx,我测试了文本到语音模块,即pyttsx3,它工作得很好,但是在打印文本时,我没有听到女性的声音。在将性别从男性改为女性方面有什么建议吗顺便说一句,我使用的是raspberry pi,使用的是Linux操作系统。 先谢谢你 tts.py engine = pyttsx.init() voices = engine.getProperty('voices') for voice in voices: engine.setProperty('voice', voice.id) engine

我测试了文本到语音模块,即pyttsx3,它工作得很好,但是在打印文本时,我没有听到女性的声音。在将性别从男性改为女性方面有什么建议吗顺便说一句,我使用的是raspberry pi,使用的是Linux操作系统。

先谢谢你

tts.py

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


如果你在下面的代码中运行,你会得到女性的声音。。倾听并享受

导入pyttsx3
engine=pyttsx3.init()#对象创建
voices=engine.getProperty(“voices”)#获取当前语音的详细信息
#engine.setProperty('voice',voices[0].id)#更改索引,更改语音。男性为0
engine.setProperty('voice',voices[1].id)#更改索引,更改语音。女性1人
引擎。说(“我将讲这篇课文”)
engine.runAndWait()

Opps等待在运行此代码之前,您需要安装其他软件包,只需在powershell或您的环境中复制并粘贴下面的文本即可

通常windows具有内置的语音功能

print(voices[0].id)#这家伙叫大卫
打印(声音[1].id)#美女名字ZIRA(哈哈哈)

Pyttsx为您提供了一个更改选项:

engine.setProperty('voice', voices[1].id)
我知道这不管用。然后我想在Python上运行以下命令:

for voice in voices:
  print("ID: %s" % voice.id)
  print("Name: %s" % voice.name)
  print("Age: %s" % voice.age)
  print("Gender: %s" % voice.gender)
  print("Languages Known: %s" % voice.languages)
当我看到输出时,没有女性的声音。我在Windows上尝试了相同的库,一切正常。因此,您可以通过更改ID来更改语音,但不能使用女性语音,不能使用Linux,也不能使用标准软件包。也许有一种方法可以实现语音包,但这可能很棘手

我试过GTT,但似乎不再有效。我猜谷歌正在改变翻译软件包中的一些东西,gTTS崩溃了(6个月前工作过,但现在不再工作了)。我找到了一个解决方案,但我不知道这是否能让您满意:

  • 编写一个bash脚本,该脚本使用SVOX pico2wave进行文本到语音转换(这是我发现的唯一一个女性语音库,我在Python中无法使用,但在bash中效果很好)
  • 使您的Python项目没有语音输入/输出部分,就像文本输入/输出一样
  • 为语音到文本制作另一个Bash脚本
  • 制作另一个Bash脚本,它使用3而不是2而不是1。这个想法是:
    • 通过Bash获取语音,输出应发送到Python代码
    • Python代码应该管理数据并给出输出
    • 输出应该触发文本到语音Bash脚本

  • 瞧,你的声音是女性的。这是一个变通办法,但总比没有好。

    事实是,核心pyttsx3软件包中没有女性声音。 但是,如果您使用linux/espeak,则有一个解决方案。你可以用其中一个来模拟女性的声音

    engine.setProperty('voice', 'english+f1')
    engine.setProperty('voice', 'english+f2')
    engine.setProperty('voice', 'english+f3')
    engine.setProperty('voice', 'english+f4')
    engine.setProperty('voice', 'english_rp+f3') #my preference
    engine.setProperty('voice', 'english_rp+f4')
    
    此外,您还可以通过将+f1添加到+f4与其他基本声音一起播放。
    有关更多信息,您可以在github中查看此问题:。

    我发现一些可以接受的女声(在我的例子中)使用pyttsx3。我正在使用MacOS High Sierra、Python 3.7.3和Pyttsx3 2.90。我已运行以下代码以使用此Samantha语音id:

    import pyttsx3
    engine = pyttsx3.init()
    engine.setProperty('voice', 'com.apple.speech.synthesis.voice.samantha')
    
    我发现很多女性声音都在寻找性别属性(“VoiceGenderFemale”)。然而,他们中的大多数人都很奇怪,上面这一个是最能接受的。我发现它运行以下代码:

    import pyttsx3
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    voiceFemales = filter(lambda v: v.gender == 'VoiceGenderFemale', voices)
    for v in voiceFemales:
        engine.setProperty('voice', v.id)
        engine.say('Hello world from ' + v.name)
        engine.runAndWait()
    

    你可以通过写下面的一行来获得女声:

    engine.setProperty('voice', voices[1].id)  # this is female voice
    
    您可以通过以下代码行打印所有语音:

    voices = engine.getProperty('voices')
    for v in voices:
        print(v)
    
    样本输出:

    <Voice id=com.apple.speech.synthesis.voice.Alex
              name=Alex
              languages=['en_US']
              gender=VoiceGenderMale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.alice
              name=Alice
              languages=['it_IT']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.alva
              name=Alva
              languages=['sv_SE']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.amelie
              name=Amelie
              languages=['fr_CA']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.anna
              name=Anna....
    
    
    
    不幸的是,我只有一个男声。当我试图打印出所有可用的声音时,令人惊讶的是,只有男性声音,但口音不同,如非洲、英国等。有没有办法安装一些模块并实现女性声音?这里也一样。只有一个男声在播放。我认为这是因为pyttsx3使用预先安装在系统上的TTS引擎,而Windows和Linux的TTS引擎是不同的<代码>打印('声音数',len(声音))
    显示有69种声音。当然需要一些更好的文档。在MacOS中也为我工作过
    voices = engine.getProperty('voices')
    for v in voices:
        print(v)
    
    <Voice id=com.apple.speech.synthesis.voice.Alex
              name=Alex
              languages=['en_US']
              gender=VoiceGenderMale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.alice
              name=Alice
              languages=['it_IT']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.alva
              name=Alva
              languages=['sv_SE']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.amelie
              name=Amelie
              languages=['fr_CA']
              gender=VoiceGenderFemale
              age=35>
    <Voice id=com.apple.speech.synthesis.voice.anna
              name=Anna....