使用Librosa提取音频文件特征时遭遇NoBackendError问题求助
Looking at your error logs and code, the core issue is crystal clear—your mylist contains a non-audio file (AudioRecorder.ipynb, a Jupyter Notebook file). When Librosa tries to load this file, it can't recognize the format, which cascades into the NoBackendError you're seeing. The critical clue from your error trace is this line:
RuntimeError: Error opening 'C:/Users/Admin/Desktop/pw-4/Speech-Emotion-Analyzer-master/Speech-Emotion-Analyzer-master/AudioRecorder.ipynb': File contains data in an unknown format.
Here's how to fix this step by step:
1. Filter Non-Audio Files From Your List
Modify your loop to skip any file that isn't a valid audio format (like .wav). Add a simple check before your existing filtering logic:
import pandas as pd import librosa import numpy as np df = pd.DataFrame(columns=['feature']) bookmark = 0 for index, y in enumerate(mylist): # Skip any file that isn't a .wav audio file if not y.endswith('.wav'): continue # Keep your original filtering conditions if (mylist[index][6:-16] not in ['01', '07', '08'] and mylist[index][:2] != 'su' and mylist[index][:1] not in ['n', 'd']): file_path = 'C:/Users/Admin/Desktop/pw-4/Speech-Emotion-Analyzer-master/Speech-Emotion-Analyzer-master/' + y X, sample_rate = librosa.load(file_path, res_type='kaiser_fast', duration=2.5, sr=22050*2, offset=0.5) sample_rate = np.array(sample_rate) mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=13), axis=0) df.loc[bookmark] = [mfccs] bookmark += 1
2. Fix How You Generate mylist
Chances are you used something like os.listdir() to pull all files from your audio directory, which includes non-audio files like notebooks. Generate your list with filtering from the start:
import os audio_directory = 'C:/Users/Admin/Desktop/pw-4/Speech-Emotion-Analyzer-master/Speech-Emotion-Analyzer-master/' # Only include .wav files in your list mylist = [file for file in os.listdir(audio_directory) if file.endswith('.wav')]
3. Verify Your Files and Setup
- Double-check that all
.wavfiles in your directory are valid (not corrupted or saved in an incompatible codec). - Print out
mylistto confirm no non-audio files slipped through:print(mylist) - If you still hit backend issues after fixing the file problem, ensure
ffmpegis properly installed and added to your system PATH (restart Jupyter after updating PATH), then upgrade your audio-related libraries:pip install --upgrade librosa audioread soundfile
内容的提问来源于stack exchange,提问作者Sohan R K

