如何在pyttsx3中改变声音? [英] How to change the voice in pyttsx3?

查看:597
本文介绍了如何在pyttsx3中改变声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码有效,但我只能在 Microsoft Windows 中预装的声音之间切换.这些声音是Microsoft David Mobile"和Microsoft Zira Mobile".

This code is working but I'm only able to switch between the voices which came preInstalled in Microsoft Windows. These voices are "Microsoft David Mobile" and "Microsoft Zira Mobile".

后来我安装了Microsoft Kalpana Mobile"并将其设置为默认的 Windows 语音.但我仍然无法切换到Microsoft Kalpana Mobile".代码是-

Later I installed "Microsoft Kalpana Mobile" and set it as the default Windows voice. But still I'm not able to switch to "Microsoft Kalpana Mobile". The code is-

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) #changing index changes voices but ony 0 and 1 are working here
engine.say('Hello World')
engine.runAndWait()

只有 0 和 1 在 voices[] 中用作索引.

Only 0 and 1 are working as indices inside voices[].

我想让Microsoft Kalpana Mobile"发言.我在这个项目上工作了过去 2 个月.如果这不起作用,我所有的努力都会付诸东流.请帮助:(

I want the "Microsoft Kalpana Mobile" to speak. I'm working on this project for past 2 months. If this doesn't work, all my efforts will go in vein. Please Help:(

提前致谢.

推荐答案

你可以试试这个代码:

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print(voice, voice.id)
    engine.setProperty('voice', voice.id)
    engine.say("Hello World!")
    engine.runAndWait()
    engine.stop()

然后,而不是 for 循环,只需选择您喜欢的 voice.id

Then instead of the for loop, just pick up your preferred voice.id

这篇关于如何在pyttsx3中改变声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆