Skip to content

Latest commit

 

History

History
53 lines (46 loc) · 3.38 KB

note2.md

File metadata and controls

53 lines (46 loc) · 3.38 KB

Playing live audio with python [7-5-2022]

live_audio_player.py | An (semi\kind-of working) attempt of streaming audio in a pythonic(?) way and without the use of vlc module [...]

import requests, pyaudio, io
from pydub import AudioSegment

stream_url = "http://realfm.live24.gr:80/realfm"
r = requests.get(stream_url, stream=True)
p = pyaudio.PyAudio()

stream = p.open(format=pyaudio.paInt16,
                channels=2,
                rate=44100,
                output=True)

for block in r.iter_content(1024 * 150):
    stream.write(AudioSegment.from_file(io.BytesIO(block), format="mp3")._data, exception_on_underflow=False) # m4a for YT?

stream.stop_stream()
stream.close()

Resources

References\Releated Topics\Searches across the internet about the subject of Audio and Streaming.