Stream audio from pyaudio with Flask to HTML5

后端 未结 4 1485
小鲜肉
小鲜肉 2021-02-01 10:51

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:



        
4条回答
  •  孤城傲影
    2021-02-01 11:45

    This question was asked long time ago, but since I spent entire day to figure out how to implement the same, I want to give the answer. Maybe it will be helpful for somebody.

    "[Errno 32] Broken pipe" error comes from the fact that client can not play audio and closes this stream. Audio can not be played due to absence of the header in the data stream. You can easily create the header using genHeader(sampleRate, bitsPerSample, channels, samples) function from the code here . This header has to be attached at least to the first chunck of sent data ( chunck=header+data ). Pay attention, that audio can be played ONLY untill client reaches file size in download that you have to specify in the header. So, workaround would be to set in the header some big files size, e.g. 2Gb.

提交回复
热议问题