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

后端 未结 2 1334
故里飘歌
故里飘歌 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 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.

提交回复
热议问题