Pyttsx3 不读取其他语言的文本

问题描述

当我尝试使用 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()

现在它应该可以在印地语中运行,就像其他语言一样。

如果您的语言未出现在列表中,请重新启动系统,如果问题仍然存在,请执行以下操作:Pyttsx isn’t showing installed languages on windows 10