Stream audio from pyaudio with Flask to HTML5

后端 未结 4 1524
小鲜肉
小鲜肉 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:43

    After lots research and tinkering I finally found the solution.

    Basically it came down to serving pyaudio.paFloat32 audio data through WebSockets using Flask's SocketIO implementation and receiving/playing the data in JavaScript using HTML5's AudioContext.

    As this is requires quite some code, I think it would not be a good idea to post it all here. Instead, feel free to check out the project I'm using it in: simpleCam

    The relevant code is in: - noise_detector.py (recording) - server.py (WebSocket transfer) - static/js/player.js (receiving/playing)

    Thanks everyone for the support!

提交回复
热议问题