pythonpython-3.xtext-to-speech

Text-to-speech (TTS) module that works under Python 3


I have tried PyTTS (deprecated) and PyTTSx (the most recommended) and two Google TTS solutions (gTTS and another one by some guy named Hung Truong) but none of them worked under Python 3.4. It seems they haven't been ported to 3.x.

I searched here on StackOverflow and Google, but all the proposed TTS solutions don't work under Python 3. I'm on Windows 7.


Solution

  • A user on Reddit found a solution.

    Turns out that gTTS works under Python 3.x, it was me that was importing the module wrong.

    I was using:

    import gtts
    blabla = ("Spoken text")
    tts = gTTS(text=blabla, lang='en')
    tts.save("C:/test.mp3")
    

    Resulting in the following error:

    NameError: name 'gTTS' is not defined
    

    When the correct way is:

    from gtts import gTTS
    blabla = ("Spoken text")
    tts = gTTS(text=blabla, lang='en')
    tts.save("C:/test.mp3")