Python GTTS / Failed to connect. Probable cause: Unknown - python

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:
Updated Windows
Uninstalled and Reinstalled gTTS

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!

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

Related

Python playsound() error when i change directory

I've a problem with Playsound and i don't know why... for me it's not understandable...
The code
from playsound import playsound
playsound(r"C:\\Users\\Toto\\Desktop\\songs\\dring.mp3")
It's work i'm happy, now i copy/paste the same directory (songs\dring.mp3) away from the desk for example my usb device (or other, no matter where i put it)
On my code i change the path
from playsound import playsound
playsound(r"D:\\songs\\ding.mp3)
i've always this error
Error 259 for command:
the driver cannot recognize the specified command parameter.
It's work only my desktop, elsewhere it does not work.. can you help me?
Thank
I found the solution...
you need to uninstall playsound 1.3.0 using :
pip uninstall playsound
(press y to proceed)
Then uninstall the old and pure version of playsound by this command :
pip install playsound==1.2.2
It worked perfectly for me

Unable to play sound even after installing playsound in python

Downloaded the sound from https://sounds-mp3.com/, and the syntax of the playsound was from the official site of it. Still there is no sound played and giving me the below mentioned output of execution.
from playsound import playsound
playsound('C:\\Users\\HP\\Downloads\\0003537.mp3')
output:
python -u "c:\Users\HP\Desktop\python files\hello.py"
I doubt it is a problem with the code, it looks fine.
It might be to do with your speakers or the audio file. Try out a wav and see if that works. Check your path too. I have had problems in the past with files downloaded from the web so maybe record something on Audacity and see if that plays. Try playing the audio file with the default software for your os, does it work?

Playsound module acting strange

I've been using the Python playsound module to play audio, and in VScode it works great, but when I play it outside of VScode in the console instead of the audio playing like usual, I get an error saying:
ModuleNotFoundError: No module named 'playsound'
I write in from playsound import playsound to import the module, and if I just try and write, import playsound, it doesn't even work in VScode, saying "'module' object is not callable".
I've uninstalled and reinstalled the new version, uninstalled and reinstalled version 1.2.2, and I'm beginning to lose hope with playsound. Has anyone out there experienced this?
At first, second part of your question:
You cannot just
import playsound
playsound(...)
because playsound is a module in this case, which is not callable (as the interpreter told you).
you need to import function playsound from the module, that is why
from playsound import playsound
playsound(...)
works.
First part of your question:
It might be possible vscode is using another version of python from one you're calling from the command line. Without more information about your environment setup I can only guess. Try to do this:
$ python -m pip install playsound
then
$ python -m playsound "path-to-your-mp3-file.mp3"
that should work without a problem.
I found out what was causing the problem. I had to edit the environment variables that point to pip and it started to work again.

Why is the playsound function not able to play my mp3 file in python

So basically I was trying to create a music playing program that would play music when you asked it to. I was just trying to get the song playing portion to actually work, so I wrote a super simple code to test it out:
import playsound
playsound('sample.mp3')
This was done in replit, and I added the mp3 file into the files section
when I hit run, it gives me TypeError: 'module' object is not callable. What can I do to fix this?
you need to install the PyObjC by writing below command.
if you are using python version 3
pip3 install PyObjC
if you are using python version 2
pip install PyObjC
After that you write below code in your terminal
from playsound import playsound
playsound("path of your audio file/testing_audio_file.mp3")
if you are facing any issue regarding path then use below pattern for (use two forward slash) Windows
playsound("D:\\path_of_your_audio_file\\testing_audio_file.mp3")
Replace
import playsound
with...
from playsound import playsound

Python is not playing sound but it finishes the program successfully without errors

I am trying to play sound in Python. When I run my code, it finishes successfully but the audio is not played by my computer.
I have tried with all the libraries like playsound, simpleaudio, pydub and kivy core audio.
Sample code I tried is:
from playsound import playsound
playsound('myfile.wav')
As i think it should work, check either your audio file (maybe it's empty) or check your audio drivers and audio output.
OR, You can try
pip install playsound
one more time
I've had this problem before, use the complete path:
from playsound import playsound
playsound(r"C:\some\path\sound.mp3") # the "r" is necessary, or else your code wont work!

Categories

Resources