无法将音频文件读取为 PCM WAV、AIFF/AIFF-C 或 Native FLAC

Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC

我正在使用 javascript 以 .wav 格式录制语音:

        navigator.mediaDevices.getUserMedia({audio:true})
      .then(stream => {handlerFunction(stream)})

      function handlerFunction(stream) {
            rec = new MediaRecorder(stream);
            rec.ondataavailable = e => {
              audioChunks.push(e.data);
              if (rec.state == "inactive"){


                let blob = new Blob(audioChunks,{type:'audio/wav;codecs=0'});

                sendData(blob)
              }
            }
          }

正在发送文件以使用 speech_recognition:

将其转换为文本
    filename = "name.wav"
    print(filename)
    data = request.body
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    uploadedFile = open(filename, "wb")
    uploadedFile.write(request.body)
    uploadedFile.close()
    #os.path.join(BASE_DIR,filename)
    r = sr.Recognizer()
    file = sr.AudioFile(filename)
    with file as source:
        audio = r.record(source)
    msg = r.recognize_google(audio)
    print(msg)
    return redirect('/')


错误:-

ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format

P.S。正在保存音频文件,我可以清楚地听到 sound/voice

音频文件:https://drive.google.com/open?id=17ucX9xRG0x5-JEtZDFaotSNLlcRs0jZc

文件格式是 WebM,而不是 wav,尽管有 wav 扩展名。您可以使用文件命令检查文件类型:

$ file name.wav 
name.wav: WebM

您需要设置MediaRecorder的mimeType来录制wav:

rec = new MediaRecorder(stream);
rec.mimeType = 'audio/wav';

它可能不受任何浏览器支持。