I want to stream the audio of my microphone (that is being recorded via pyaudio) via Flask to any client that connects.
This is where the audio comes from:
def getSound(self):# Current chunk of audio datadata = self.stream.read(self.CHUNK)self.frames.append(data)wave = self.save(list(self.frames))return data
Here's my flask-code:
@app.route('/audiofeed')
def audiofeed():def gen(microphone):while True:sound = microphone.getSound()#with open('tmp.wav', 'rb') as myfile:# yield myfile.read()yield soundreturn Response(stream_with_context(gen(Microphone())))
And this is the client:
<audio controls><source src="{{ url_for('audiofeed') }}" type="audio/x-wav;codec=pcm">Your browser does not support the audio element.</audio>
It does work sometimes, but most of the times I'm getting "[Errno 32] Broken pipe"
When uncommenting that with open("tmp.wav")-part (the self.save() optionally takes all previous frames and saves them in tmp.wav), I kind of get a stream, but all that comes out of the speakers is a "clicking"-noise.
I'm open for any suggestions. How do I get the input of my microphone live-streamed (no pre-recording!) to a webbrowser?
Thanks!