I am following a YT course to work on the urban 8k data set which uses torch audio. The author wrote the exact same code but was able to get an output while I get a error.
The following is the error I get:
RuntimeError: Couldn’t find appropriate backend to handle uri C:UsershbhavnagDocumentsHussainASUcollision detectionurban soundsUrbanSound8Kaudio5100263-2-0-121.wav and format None.
Following is my code
`from torch.utils.data import Dataset
import pandas as pd
import torchaudio
import os
class UrbanSoundDataset(Dataset):
def __init__(self,annotation_file,audio_dir):
self.annotations = pd.read_csv(annotation_file)
self.audio_dir = audio_dir
def __len__(self):
return len(self.annotations)
def __getitem__(self, index):
audio_sample_path = self._get_audio_sample_path(index)
label = self._get_audio_sample_label(index)
signal, sr = torchaudio.load(audio_sample_path)
return signal, label
def _get_audio_sample_path(self,index):
fold = f"fold{self.annotations.iloc[index,5]}"
path = os.path.join(self.audio_dir, fold, self.annotations.iloc[index,0])
return path
def _get_audio_sample_label(self, index):
return self.annotations.iloc[index,6]
if __name__ == "__main__":
annotations_file = r"C:UsershbhavnagDocumentsHussainASUcollision detectionurban soundsUrbanSound8KmetadataUrbanSound8K.csv"
audio_dir = r"C:UsershbhavnagDocumentsHussainASUcollision detectionurban soundsUrbanSound8Kaudio"
usd = UrbanSoundDataset(annotations_file, audio_dir)
print (f"There are {len(usd)} samples in the dataset")
signal, label = usd[2]`
I tried looking up the documentation for torch audio but was not sure if anything directly there was able to help me, I am assuming there are some version compatibility issues.
I am using windows