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

See original GitHub issue

I am recording voice using javascript in .wav format:

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)
              }
            }
          }

sending the file to convert it to text using 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('/')

getting Error:

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

audio is saving and sound is clear

audio file:https://drive.google.com/open?id=17ucX9xRG0x5-JEtZDFaotSNLlcRs0jZc

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

2reactions
Paritoshyadavcommented, Jun 15, 2020

Try converting it using ffmpeg from the terminal (or use the os commands in python for doing it while the code is running)

can you expain detail??

@Asalle @cuongnguyengit u need to install FFmpeg like:= https://github.com/kkroening/ffmpeg-python or from any other repo or lib that use FFmpeg and use it to convert the current file format to PCM WAV, AIFF/AIFF-C, or Native FLAC format before processing it

0reactions
PRG14112000commented, Mar 23, 2022

Can you please tell how you record the audio using js from microphone and convert it to text

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Audio file could not be read as PCM WAV, AIFF ...
ValueError : Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another...
Read more >
Audio file could not be read as PCM WAV, AIFF/AIFF-C, or ...
above is my code,then the error is: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file...
Read more >
Python, speech_recognition tool does not recognize .wav file
ValueError : Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another...
Read more >
Audio file could not be read as PCM WAV, AIFF/AIFF-C, or ...
ValueError : Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another...
Read more >
ValueError: Audio file could not be read as PCM WAV, AIFF ...
ValueError : Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found