I use google-cloud text-to-speech API using python3 on linux.
The mp3 plays with os.startfile(), which opens a player.
Instead sending mp3 file & using mp3 player, I need to play audio through the browser.
I have tried:
“Python Media Player” —-defunct.
“20.1. webbrowser”— defunct.
“Rhythmbox” —simply another player.
“Pygame” — overkill.
"Pyglet" - overkill
SoX and pySoX, —Don’t appear to play the files they manipulate.
I read part of Schwoebel’s “An Introduction to Voice Computing in Python.”
"gl_talk" — Wasn't able to implement; very little documentation.
I need advice on how to mimic what google has done in the browser as in the link here:
https://cloud.google.com/text-to-speech
You can use the gTTS module to do text-to-speech in Python. And then you can use another module to play the sound using Python as well.
First install the following modules...
pip install gTTS
pip install playsound
Then you can do this...
from gtts import gTTS
import playsound
tts = gTTS('hello')
tts.save('hello.mp3')
playsound.playsound('hello.mp3')
This code should give you the same results as google in browser, because gtts uses the same API. If you have any problems you can comment and I will definitely reply :)
Related
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?
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
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!
For my PyQt5 project, I am using the QWebEngineView, but certain videos, such as .mp4 videos won't play. Can I install the codecs with pip, or pass a certain argument through QApplication() or something similar in order to fix this problem?
I installed PyQt5 through pip, so I don't have the C:\Qt\... files, only the PyQt5, pyqt5_tools folders in Appdata\Local\Programs\Python\Python37\Lib\site-packages.
I am using Python 3.7.2, and PyQt5.11
The pyqtwebengine provided by pypi does not enable the use_proprietary_codecs flag so you cannot play the .mp4.
If you want to get a pyqtwebengine that plays mp4 you must follow these steps:
You must compile Qt with the WEBENGINE_CONFIG += use_proprietary_codecs flag to enable the codecs needed to play mp4(Qt WebEngine Features: Audio and Video Codecs)
Then using that Qt you must compile pyqtwebengine.
I have been looking for ages on ways to find out how to make idle python play sound such as wav.
The solutions I have found are used by programs such as pygame. I can't download pygame or any other program.
Many thanks
To play a sound without downloading anything, you use the code:
import winsound
winsound.PlaySound('FILENAMEHERE.wav', winsound.SND_FILENAME)
keep everything the same apart from FILENAMEHERE
Why are you unable to download anything? https://pypi.python.org/pypi/playsound/1.2.1 - link for playsound module it is very easy to download. You can download it using pip by navigating with cmd to your python folder (usualy C:\Users\UserName\AppData\Local\Programs\Python\Python35-32) and writing: python -m pip install playsound (if you are using python 3). I think that is the easiest and the fastest way for you to play sound if you have any other questions about this let me know.
p.s
If you need to you can download pip here: https://pip.pypa.io/en/stable/installing/https://pip.pypa.io/en/stable/installing/
Hope I was helpful. :)