1

I am using speech_recognition to read a .wav file using the following code :

r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)

However, I get the following error: file does not start with RIFF id

I tried the following solutions and use the below code, but I end up with new errors:

Solution 1 Code:

import librosa
import soundfile as sf
x,_ = librosa.load('sample_wav.WAV', sr=16000)

Error : Error opening 'C:\\Users\\biswankar.das\\Downloads\\sample_wav.WAV': File contains data in an unknown format

Solution 2 Code:

from scipy.io import wavfile
samplerate, data = wavfile.read(file_path)

error : File format b'\xff\xe3\x18\xc4' not understood. Only 'RIFF' and 'RIFX' supported.

I tried analyzing this file online, the format is MPEG, following are the details: ANALYSIS DETAILS:

General
Format : MPEG Audio
File size : 246 KiB
Duration : 4 min 11 s
Overall bit rate mode : Constant
Overall bit rate : 8 000 b/s
FileExtension_Invalid : m1a mpa mpa1 mp1 m2a mpa2 mp2 mp3

Audio
Format : MPEG Audio
Format version : Version 2.5
Format profile : Layer 3
Duration : 4 min 11 s
Bit rate mode : Constant
Bit rate : 8 000 b/s
Channel(s) : 1 channel
Sampling rate : 8 000 Hz
Frame rate : 13.889 FPS (576 SPF)
Compression mode : Lossy
Stream size : 246 KiB (100%)

I tried using ffmpeg as well using the below code, but I get an error while trying the same :

import pydub as pydub
from pydub import AudioSegment
AudioSegment.ffmpeg = "\\ffmpeg.exe"
pydub.AudioSegment.converter = r"\\ffmpeg.exe"
data = AudioSegment.from_wav("sample_wav.wav")

Error: The system cannot find the file specified - Altho I can read the same file location

Biswankar Das
  • 303
  • 4
  • 12
  • Look at this post. It might help. https://stackoverflow.com/questions/25672289/failed-to-open-file-file-wav-as-a-wav-due-to-file-does-not-start-with-riff-id. – JoraSN Dec 31 '21 at 03:03
  • It looks like your file is misnamed. It appears to be an `.mp3` file and not a `.wav`. Have you tried renaming it (I'm not sure if librosa/libsoundfile/audioread pay attention to the file extension, but they might and could end up being confused). Note also that librosa support for MP3 depends on `audioread`. See [librosa docs](https://librosa.org/doc/main/ioformats.html). [This SO question](https://stackoverflow.com/q/9458480/758174) might help. – Pierre D Jan 02 '22 at 13:09

1 Answers1

0

The error file does not start with RIFF id means that your file is not supported by wave so you have to use a different file altogether. It might be because the file might not be a .wav file. Look at this post for more details- Failed to open file file.wav as a WAV due to: file does not start with RIFF id.

JoraSN
  • 332
  • 2
  • 14