1

When I try to read text with pyttsx3, it only reads the English text and it does not read any text which is in some other language.

Here's my code:

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()

Here, pyttsx3 only reads the English text and it does not the text in other languages.

Is there any way to fix this problem?

It would be great if anyone could help me out.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Lenovo 360
  • 569
  • 1
  • 7
  • 27
  • Is it supposed to read other languages? – Delrius Euphoria Feb 26 '21 at 07:53
  • @CoolCloud: I'm not really sure, but all I want is to read text in other languages. Being able to achieve this with any module is ok. – Lenovo 360 Feb 26 '21 at 08:25
  • Hoping you are on windows, head over to settings and language settings, there click on add a language and installed your desired language, though it is necessary that text-to-speech for that language should be available(can be seen there) and install both language pack and text to speech. I think this should solve it. – Delrius Euphoria Feb 26 '21 at 08:40
  • @CoolCloud: I tried downloading Japanese language. It says text-to-speech is supported in Japanese, but pyttsx3 still does not read the Japanese text when I run my code. – Lenovo 360 Feb 26 '21 at 08:50
  • Give it some time, I have noticed that despite downloading it, it takes some more time to install the text to speech feature – Delrius Euphoria Feb 26 '21 at 08:52
  • @CoolCloud: I tried running my code only after ensuring that the language is installed. – Lenovo 360 Feb 26 '21 at 08:53
  • I checked the status, and it says everything (Including the text-to-speech feature) has been installed. – Lenovo 360 Feb 26 '21 at 08:54
  • Now follow [this](https://stackoverflow.com/questions/56730889/pyttsx-isn-t-showing-installed-languages-on-windows-10) question. – Delrius Euphoria Feb 26 '21 at 08:59

1 Answers1

3

Start off by going to settings and language settings and installing the required language packs. Though note that, these language packs require text-to-speech feature to be able to work. Now give it sometime to register the data and to be recognized by pyttsx3.

After this find all languages available with:

import pyttsx3

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

For me Hindi appears third in the list, so I would add(outside loop):

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

engine.runAndWait()

Now it should work out in Hindi, just like this follow through for other languages too.

If your language does not appear in the list, then restart your system and if the issue still persists, follow: Pyttsx isn’t showing installed languages on windows 10

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
  • Hi, thanks for your answer, but is there any easier way to get this done? I am asking this because reading in other languages only work when I install that language, change the settings with regedit, and restart my computer; so the user using my app wont be able to do these. – Lenovo 360 Feb 26 '21 at 09:45
  • Nope, I don't think so, I have searched the internet and found nothing. – Delrius Euphoria Feb 26 '21 at 09:57