Reputation: 11
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:
Upvotes: 1
Views: 2822
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
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