'Python GTTS / Failed to connect. Probable cause: Unknown

from playsound import playsound
from gtts import gTTS,gTTSError

 def playaudio(audio):
    playsound(audio)

def convert_to_audio(text):
    audio =gTTS(text)
    >- audio.save("textaud.mp3") -<
    playaudio("textaud.mp3")

convert_to_audio("my name is joe")

I'm using Anaconda Environments. I'm getting a error in highlighted line.

That error is:Failed to connect. Probable cause: Unknown https://i.stack.imgur.com/wZMVI.png

The solutions I tried:

  1. Updated Windows
  2. Uninstalled and Reinstalled gTTS


Solution 1:[1]

Try doing this.

from playsound
from gtts import gTTS

def playaudio(audio):
    playsound(audio)

def convert_to_audio(text):
    audio =gTTS(text=text, lang='en', tld='com')
    audio.save("textaud.mp3")
    playaudio("textaud.mp3")

convert_to_audio("my name is joe")

Solution 2:[2]

So I have used gtts in a recent project and one thing I noticed is that I get this error every time I run my code without an internet connection. As soon as my device is connected, it works fine for me. Even the code you provided worked as it should (after correcting the indentation and deleting ">-" from your save audio command), so be sure to be connected to the internet. Hope this'll help!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shibli Mueed
Solution 2