1

I am working on an app that uses a recording of the user, and am using requests to send a wav file to a flask backend

Here is the code in my html file, it logs the type of the audio which designates it as a wav file

       function sendAudioToServer(audioBlob) {
            console.log('MIME Type:', audioBlob.type);
            var formData = new FormData();
            formData.append('audioFile', audioBlob);
            var xhr = new XMLHttpRequest();
            xhr.open('POST', '/process_audio', true);
            xhr.onload = function () {
                if (xhr.status === 200) {
                    console.log('Audio processing successful');
                    console.log(xhr.responseText);
                } else {
                    console.error('Audio processing failed');
                }
            };
            xhr.send(formData);
        }

And here is the python code that processes it

`@app.route('/process_audio', methods=['POST'])
def process_audio():
> print('function')
    audio_file = request.files.get('audioFile')
    if audio_file:
        audio_file.save('audio.wav')
        return 'Audio file received and saved successfully'
    else:
        return 'No audio file received', 400`

Even though it says that it is a wav file in the front end, when it gets to the backend it gets corrupted

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.