Unable to load audio file using torchaudio.load()

So I downloaded the datasets and was trying to load the waveform using torchaudio.load(), I have given the arguments as below :

> filename = "./data/SpeechCommands/speech_commands_v0.02/yes/00f0204f_nohash_0.wav"
> waveform, sample_rate = torchaudio.load(filepath=filename, num_frames=3)
> print(f'waveform tensor with 3 frames:  {waveform} \n')
> waveform, sample_rate = torchaudio.load(filepath=filename, num_frames=3, frame_offset =2)
> print(f'waveform tensor with 2 frame_offsets: {waveform} \n')
> waveform, sample_rate = torchaudio.load(filepath=filename)
> print(f'waveform tensor:  {waveform}' )

Error message:

Traceback (most recent call last):

Cell In[6], line 2
waveform, sample_rate = torchaudio.load(filepath=filename, num_frames=3)

TypeError: get_load_func..load() got an unexpected keyword argument ‘filepath’

I am using jupyterlab notebook to execute the codes.

Is there anything missing over this?

The torchaudio.load documentation shows , I can give a path like object as first argument, so I was wondering, why it throws an error.

I am basically following this tutorial.

The docs show the first argument is called uri instead of filepath, so you might want to change the argument name or just pass the filename implicitly without specifying the argument name.

1 Like

Thank you, that was the issue and changing the argument name to uri solved the error.