Pyttsx3 不读取其他语言的文本

Pyttsx3 does not read text in other languages

当我尝试使用 pyttsx3 阅读文本时,它只会阅读英文文本,不会阅读任何其他语言的文本。

这是我的代码:

import pyttsx3

engine = pyttsx3.init()

engine.say("'Hello world' in Chinese: 你好,世界")
engine.say("'Hello world' in Japanese: こんにちは世界")
engine.say("'Hello world' in Hindi: नमस्ते दुनिया")

engine.runAndWait()

这里pyttsx3只读英文文本,不读其他语言的文本

有什么办法可以解决这个问题吗?

如果有人能帮助我就太好了。

首先转到设置和语言设置并安装所需的语言包。请注意,这些语言包需要文本到语音功能才能工作。现在给它一些时间来注册数据并被 pyttsx3 识别。

在此之后找到所有可用的语言:

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print(f"Voice: {voice.name}")

对我来说,印地语在列表中排在第三位,所以我要添加(外循环):

engine.setProperty("voice", voices[2].id) # 2 is the 3rd item index
engine.say("'Hello world' in Hindi: नमस्ते दुनिया")

engine.runAndWait()

现在应该可以用印地语解决了,就像其他语言一样。

如果您的语言没有出现在列表中,请重新启动系统,如果问题仍然存在,请执行以下操作: