Playback of at least 3 music files at one in python - python

I am searching for a way/framework to play at least 3 music files at one in a python application. It should run at least under ubuntu and mac as well as on the raspberry pi.
I need per channel/music file/"deck" that is played:
Control of the Volume of the Playback
Control of the start position of the playback
Play and Pause/Resume functionality
Should support mp3 (Not a must but would be great!)
Great would be built in repeat functionality really great would be a fade to the next iteration when the song is over.
If I can also play at least two video files with audio over the same framework, this would be great, but is not a must.
Has anyone an Idea? I already tried pygame but their player can play just one music file at once or has no control over the playback position.
I need that for a theatre where a background sound should be played (and started simultaneosly with the light) and when it is over, a next file fades over. while that is happening there are some effects (e.g. a bell) at a third audio layer.

I finally got an answer/workaround.
I am using pythons multiprocessing class/functionality to run multiple pygame instances.
So i can play more than one music file at a time with fully control over playmode and playback position.

Related

playing sound in Python with the ability to cut it off mid-play

I am writing a bit of python code that plays a sound file (MP3 or the equivalent) and should cut that sound off if the user strikes a (hardware) button that is wired into the system. This will be on a Raspberry Pi running Raspbian. The libraries I’ve used historically for playing sound all play to completion. The closest approach I can think of would be using an external sound player (OMXplayer perhaps) and then searching for and killing its process if the button is pressed, but this feels inelegant. Can anybody suggest a better approach?
Using Pyaudio you could simply check a flag before writing each buffer to the stream, and if the audio should stop, fade out the current buffer and then either continue the stream with silence (write 0's) or stop the stream and exit the program. This could be easily be achieved with a latency of ~1/10s after button press.
You would also need to create a UI thread in the application to handle commands since the stopping flag is switched on user input.

Pyglet Event Audio

I would like to know how I can start an audio without having to enter the Pyglet loop. My question is based on the fact that I'm already using a loop, for Pygame. Unfortunately, with the latter, I found the fact that it has an inaccurate control with regard to the volume of the audio. So I wanted to use Pyglet to play it. The fact is that I can not allow myself to start a loop with Pyglet, because it blocks the script, so, returning to the question, how can I use the audio playback event independently?

How to stop sound in pygame?

Ok so basically I'm working on this pygame game and I'm using the mixer sub module for sounds. However, in pygame if you want to stop a sound, the sound must finish its cycle until it can be stopped. For all my sounds this is ok as they can be a looped 1 second sound. However, I use a falling sound which needs to constantly play in a cycle, but cycling a falling sound that is only 1 second long doesn't sound very effective. So, ultimately I want to know if there is a way to stop a 7 second sound loop instantly without it finishing a cycle.
According to the pygame documentation for pygame.mixer
pygame.mixer.pause()
will temporarily stop playback of all sound channels. You can start them all playing again with;
pygame.mixer.unpause()
For an individual sound, whilst it will stop after a full cycle, you can immediately affect it's volume with;
pygame.mixer.Sound.set_volume(0)
So what I'd try first is stopping the sound at the same time as setting it's volume to zero and seeing if that solves your problem. Alternatively, you can split your mixer into Channels for better controlling sound playback, which will give you the ability to use
pygame.mixer.Channel.pause()
pygame.mixer.Channel.unpause()
On specific groups of sounds rather than all sound. You create a mixer channel with;
pygame.mixer.Channel(id)
You can then play specific sounds on that channel with;
pygame.mixer.Channel.play(Sound, loops=0, maxtime=0, fade_ms=0)
This would also allow you to more dynamically adjust the levels of various types of sounds in your game - for example, environment, music, weather, voices and how they overlap each other, just keep in mind a channel can only play one sound at a time. Because of this, it may by prudent to use;
free_channel = pygame.mixer.find_channel()
free_channel.play(Sound)
or more simply;
pygame.mixer.find_channel().play(Sound)
For everything except your 'falling' channel.

Python Master Volume Control

I want to make a small program that changes the volume levels of programs based on what programs are open and possibly given audio detection, for example if im running a game window, and I have music in the background, I'd want it to lower the music volume if it detects audio being sent from the game window.
I usually play with game volumes turned off, but I usually watch cutscenes, so my goal is to have the music playing and mute if a cutscene comes up.
I dont know how doable it is with python, but I have the most knowledge of python thus Im asking for that if possible, I could do it in another language if anyone has suggestion.
So more or less, I just need some direction on what libraries of languages would be useful for making this program.
OS involved - Windows 10

Is it possible to detect when the system is recording a sound and then perform some action on Python?

I began learning Python a few days ago, and i was wondering about a practical use for a program.
Then i came up with the following: if my brother is in his room recording himself playing guitar, a led plugged to the usb and wired so it's outside his door lights up, and then i'll know he's recording and i'll take care not to make any noises.
The main questions are:
How Python can detect any recording going on in the system?
How would i interface with the usb so i can actually turn the led on?
to interact with USB, you can read this related question.
to detect recording, you will have to tell us on which operating system your program is intented to run (but i am not sure it is possible to detect that another application is recording)

Categories