Я записываю голос, используя 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
PS аудиофайл сохраняется, и я хорошо слышу звук / голос
аудиофайл: https://drive.google.com/open?id=17ucX9xRG0x5-JEtZDFaotSNLlcRs0jZc