pythonpyttsxpyttsx3

Pyttsx3 does not read text in other languages


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.


Solution

  • 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