There is an audio stream

I learned to write it down:

import requests def save_stream(): stream_url = 'http://ic7.101.ru:8000/c15_3' r = requests.get(stream_url, stream=True) with open('./stream.mp3', 'wb') as f: try: for block in r.iter_content(1024): f.write(block) except KeyboardInterrupt: pass 

Now I want to learn how to play it?)

That's all, I figured it out) Here's the ready code , writes and immediately plays the audio stream.

  • The question is not clear: do you want (potentially infinite) audio stream to play or you have a question how to play mp3 in Python? (then it doesn't matter where the mp3 file came from). - jfs
  • Related question: Playing Flac music in python (you can try both webbrowser and Gstreamer to play the original link or play the saved file) - jfs

1 answer 1

You can use pyglet:

 def playFile(sound,reps=1): import pyglet from pyglet.media import Player player = Player() song = pyglet.media.load(sound,streaming=False) for i in range(reps): player.queue(song) player.play() def callback(dt): pyglet.app.exit() pyglet.clock.schedule_once(callback,song.duration*reps) pyglet.app.run() 

Not really elegant, cumbersome, but it works.

  • It works) but to reproduce .mp3 I had to connect avbin.dll pyglet.lib.load_library ('avbin') pyglet.have_avbin = True Thanks for the reply) - llpoqpeccop
  • As an option, you can throw in \ Windows \ System32 - Sergey