Sorry, I donβt have Python3 to test here, for mp3 stream using pyaudio you need to decode it in PCM data, I know that pymedia can do this, but it is too old and just supports python27 .
To do this correctly, you will need to find out some attributes of your sound, such as samplerate, number of channels, bit resolution, to set it to pyaudio.
I can show how I do it using python27 + pyaudio , first I will show how it is done for .wav stream
from urllib2 import urlopen
select a large buffer, python is slowly in the while loop, I did it using chunks of size 8192 , note that format , channels and rate are rigth attributes for this wav file, so for .wav we do not need to decode, this is PCM data, now for mp3 we need to decode and put in PCM format in the stream.
Let's try using pymedia
from urllib2 import urlopen import pyaudio import pymedia.audio.acodec as acodec import pymedia.muxer as muxer dm= muxer.Demuxer( 'mp3' ) pyaud = pyaudio.PyAudio() srate=44100 stream = pyaud.open(format = pyaud.get_format_from_width(2), channels = 1, rate = srate, output = True) url = "http://www.bensound.org/bensound-music/bensound-dubstep.mp3" u = urlopen(url) data = u.read(8192) while data:
This may be a secret because I have never seen anyone show how this can be done in python, for python3 I don't know anything that can decode .mp3 into pieces like pymedia do.
Here these two codes are erased and work for .wav and .mp3