Echore
Echore

Reputation: 11

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.sstatic.net/wZMVI.png

The solutions I tried:

  1. Updated Windows
  2. Uninstalled and Reinstalled gTTS

Upvotes: 1

Views: 2822

Answers (2)

Hassan Niaz
Hassan Niaz

Reputation: 11

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!

Upvotes: 1

Shibli Mueed
Shibli Mueed

Reputation: 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")

Upvotes: 0

Related Questions