Stream audio from pyaudio with Flask to HTML5

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

    Try This its worked for me. shell cmd "cat" is working perfect see the code iam using FLASK

    import subprocess
    import os
    import inspect
    from flask import Flask
    from flask import Response
    
    @app.route('/playaudio')
        def playaudio():
            sendFileName=""
            def generate():
    
                #  get_list_all_files_name this function gives all internal files inside the folder
    
       filesAudios=get_list_all_files_name(currentDir+"/streamingAudios/1")
    
                # audioPath is audio file path in system 
                for audioPath in filesAudios:
                    data=subprocess.check_output(['cat',audioPath])
                    yield data
            return Response(generate(), mimetype='audio/mp3')
    

提交回复
热议问题