find out which programs play sound python Python - python

I want to find out which programs are playing sound with a python code, I researched it a lot, even though I tried libraries like winsdk pycaw, I couldn't get any results

The simplest way is to use standard winsound module. Please, refer to documentation
If you are now under Windows, there are:
the bell character on the terminal
AppKit to play MacOS system sounds
pygame to play custom sound files
simpleaudio to play custom sound files
the beepy package

Related

Python audio playback library that supports cue sheets

I'm looking for a Python audio playback library that supports cue sheets. I found a good list of libraries here, but none of them seem to work with cue sheets (at least not from what I've seen in their documentations). Is there anywhere I can find something like this?
I would prefer if it's something that can work with PYQT5, but it's fine if there isn't anything like that!
I ended up deciding to use QMediaPlayer (part of PyQt5), along with this logic.
I had to install K-Lite codec on my computer, otherwise it would only play .wav files. Here is the download link for that.
Edit: QMediaPlayer ended up not supporting gapless playback, so I switched to pyglet which works for non-mp3 files. pyglet can also be used with PyQt5 because pyglet.app.run() without a pyglet window can play the audio in the background, which can be controlled from the GUI application running on PyQt5.
However as Denis pointed out in the comment to this, there are many other issues I hadn't considered.

Python audio without root privileges?

I working in python on computers in a lab where I do not have root privileges and can't get any libraries installed. Someone I am helping is writing a game and wants to add audio. We can play sounds with something like this
subprocess.call(["afplay","gun_battle_sound-ReamProductions-1158375208.wav"])
but everything stops until the sound is done playing. Is there a way to keep things moving while the audio is playing? Is there a library that we can just copy? We are using the graphics module from Zelle, so I am looking for something like that - simple to use and install.
Thank you!
Pyglet
is completely copyable and easy to download.
Otherwise you will probably need to create a thread from threading just for the sound to play on.

Playing sounds in Python without external module?

I've searched for this around, and every answer seems to include an external Python library, such as Pygame, Snack, etc, for playing sounds.
Is there not a simple pure pythonic way from the built in modules to play, say, a .wav file without the use for external modules? I know that Python doesn't natively support .mp3 files.
The most I've found in that regard is winsound. Nothing extra to install; just import it. However, as you might have guessed, it only works on Windows. I use Pygame's mixer when I want sound. Its support for mp3 files is limited, and it requires an installation (unless you package your application), but it's the most straightforward of the third-party audio modules I've looked into.

Playing sound files in python

What is a good package for playing MP3 files in python? It would need to be something that is maintained and is cross platform (Win, Mac, Linux) and something with a simple and repeatable call structure, rather than having to perform complex setup every time the same file is opened (I use the sounds in various loops and need to not have to constantly worry about if a channel is full or other factors). It also needs to be relatively small; I don't want to import an entire GUI toolkit just so I can play a small bell and alert sounds. Lastly, it needs to be non-blocking; I need it to play the file once and move on without locking up the entire program.
I had been using PyAudiere in order to play MP3 files from python, as it used to meet all these criteria. Unfortunately, the package has been abandoned, and so I need to find a replacement (PyAudiere was updated to python 2.6 and still works in 2.7 if you hack it by manually changing the version check, but this is not a long term solution, especially since finding a copy of the package is now difficult).
Hi Try the following libraries:
PyMedia
pygame
PyAudio
pyglet

Python Raspberry PI PyGame Audio error - just a click [duplicate]

I'm quite new with raspberry pi and am very new but I am trying to play an audio file through a python file on a pi B. I played the audio from the command line using omxplayer and it worked fine but when i run the following code it plays only static.
from pygame import mixer
mixer.init()
wow = mixer.Sound('Wow.mp3')
wow.play()
time.sleep(5)
I tried using mixer.load('Wow.mp3') and other variations but still only get static. I tried putting things in the init like mixer.init(4800, -16, 1, 1024) and using pre_init but to no avail. I also tried adding disable_audio_dither=1 to config.txt. Any and all help would be greatly appreciated thank you very much.
Sometimes if sound is supposed to be playing but isn't, and the speakers are turned all the way up, it will play static instead. This is probably a computer problem, not a pygame problem. Check whether audio plays in other locations. If it does not, it is definitely a computer problem.
If using Linux (you probably are, Raspbian is a variant of Debian which is Linux), and you have identified that it is a computer problem, try initializing ALSA by typing alsactl init as root in the Linux Terminal. If this does not work and the above is true, then you are having some audio problems that will take a bit of research to fix.
If audio does play in other locations, then it is probably a file format issue. It's possible that the bitrate is different, the format is wrong, etc. Also, here is a quote pulled directly from Pygame documentation:
Be aware that MP3 support is limited. On some systems an unsupported format can crash the program, e.g. Debian Linux. Consider using OGG instead.
https://www.pygame.org/docs/ref/music.html
Other than this, there isn't much we can do to help you. A problem like this that isn't fixed by the above is usually a problem specific to very few computer setups. You will probably have to do some personal research.
If you need any more help, please notify me in the comments.

Categories