How to play radio stream with pgame? - python

In my audio player I want play music from a radio stream. Is this possible with the pgame.mixer.music?
Playing and controlling audio from file is no problem.

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.

How to sync audio and video using python

I am making a screen recorder which captures the screen and simultaneously also records the audio from microphone(input) with the help of a python script.
I am using Pillow and opencv library to record screen and using pyaudio library to record audio.
I have created a Gui using tkinter for this screen recorder(shown in image below).
So to start screen and audio recording i used buttons to start and stop different functions of scripts.
Now the problem is that duration of video file(screen recording) and the audio file(using pyaudio) is different.
ex. if user click on screen rec button and after 20-50 sec later click on voice rec button or vice-verse.
The time duration of both the file is different and can't be merge the audio and video file properly.
How can I overcome this situation?

LibVLC - Disabled popup video player

I'm trying to use libVLC in a Python program to play an online live stream.
The program passes .m3u8 link to libVLC, which works fine.
When the stream starts, it opens a window titled VLC (Direct3D11 output).
However, I only want the audio to play, not the video to show. This is the usual behaviour with a .mp3 file for example.
In short: how can I disable the video output of libVLC, to have it play just the audio of a live stream, with no window?
I don't know libVLC very well, but I had a similar problem with the python-vlc module.
In my case, I wanted to play the audio of a youtube video/stream.
I modified the code from here by adding the --no-video argument when instantiating the vlc object.
This is basically a general VLC command line argument to suppress video output.
Maybe there is a similar option to add this in libVLC?
Below the code, just for reference:
import pafy
import vlc
url = "YOURVIDEOURL"
video = pafy.new(url)
best = video.getbest()
playurl = best.url
Instance = vlc.Instance("--no-video") #This did the trick
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
player.play()
input()

How to record signal from soundcard in python

I want to process the audio data from sound card (i.e. USB external sound card). For example: I can record all sound while playing a Youtube clip along with PC game. However, I have tried Pyaudio which only allows me to record audio from microphone. Can someone suggest me any library to try? Thanks so much!

Playback of at least 3 music files at one in 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.

Categories