Reading audio stream in python

Amazing in bash you can do

$ curl http://mp3.streampower.be/radio1-high.mp3 > test.mp3

with the audio stream and then ^ C out, and you will have a working mp3 file that will make me believe that I could automate it in python, but I can not find it.

If I just do

file('python.mp3', 'w').write(urllib2.urlopen("http://mp3.streampower.be/radio1-high.mp3").read())

he doesn't even read the stream.

Is there something like BufferedInputReader from java in python or can someone give me some guidance on how I will do this? Reading the audio stream and stopping reading after a while.

thank

+3
source share
1 answer

, - urllib2.urlopen(), read :

#!/usr/bin/python

import urllib2

f=file('python.mp3', 'w')

url=urllib2.urlopen("http://mp3.streampower.be/radio1-high.mp3")

while True:
    f.write(url.read(1024))

read - . , . - , write , .

mp3 . , 1024, , mp3, . ( 128 / 16 write(2), . 10 , read).

+7

Source: https://habr.com/ru/post/1754581/


All Articles