Record voice with recorder.js and upload it to python-flask server, but WAV file is broken

后端 未结 2 1335
故里飘歌
故里飘歌 2021-01-14 02:17

I would like to realize this.

  1. A user speaks to a web browser.
  2. A web browser (Google Chrome) record user\'s voice as WAV file(Recorder.js) and send it
相关标签:
2条回答
  • 2021-01-14 02:48

    I have this problem and it takes me 2 days for finding the solution :)) . In flask server you can use request.files['audio_data'] to get wav audio file. You can pass and use it as an audio variable too. Hope this can help you

    0 讨论(0)
  • 2021-01-14 03:03

    For those who are still unable to figure it out after this. Just change the

    main.py

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    from flask import Flask
    from flask import request
    from flask import render_template
    import os
    
    app = Flask(__name__)
    
    
    @app.route("/", methods=['POST', 'GET'])
    def index():
        if request.method == "POST":
            f = request.files['audio_data']
            with open('audio.wav', 'wb') as audio:
                f.save(audio)
            print('file uploaded successfully')
    
            return render_template('index.html', request="POST")
        else:
            return render_template("index.html")
    
    
    if __name__ == "__main__":
        app.run(debug=True)
    

    Note:

    Using ":" in the filename confuses ffmpeg/ffprobe (and it does not matter whether you use "" or ' to surround the file name, and backslash escaping does not work for ":"). The only possible solution is to [temporarily] remove ":" from the filename.

    0 讨论(0)
提交回复
热议问题