2

I am trying to figure out how to play radio from a stream, real time. I know the ip of the stream and I managed to write it to an mp3 file, for a pre-specified length:

import urllib2
import time

length = 60
f = open("test.mp3", "w+b")
stream = urllib2.urlopen("ip:port")
start_time = time.time()
finished = False
while not finished:
    f.write(stream.read(10420))
    if time.time() - start_time > length:
    start_time = time.time()
    f.close()

I also slightly know how to play audio files, however, I don't know how to play it real time. Is there a way pyaudio (or any module that's compatible with kivy) can help me achieve what I'm looking for, i.e. play radio in python via the stream from the ip?

Thanks in advance!

Jonas
  • 121,568
  • 97
  • 310
  • 388
J-Star
  • 96
  • 3
  • 8

0 Answers0