Loading wav data
To work with any non-standard data using Dask bags, you will need to write a lot of functions yourself. For this task, you are analyzing audio data, and so you need a custom function to load it.
Some of the audio recordings failed, and the audio is silent in these. Regular audio data looks like a wave, where the amplitude goes to large positive and negative values. Therefore, to check if a recording is silent, you can check whether the audio clip has very small amplitudes overall.
The scipy.io.wavfile
module has been imported into your environment as wavfile
, and numpy
has been imported as np
.
This exercise is part of the course
Parallel Programming with Dask in Python
Exercise instructions
- Inside the
load_wav()
function, usewavfile.read()
to load the audio data and sampling frequency. - Inside
load_wav()
, construct the returned dictionary. - Inside the
not_silent()
function, return a boolean of whether the'audio'
array inside the input dictionary has a mean absolute value of greater than 100, by usingnumpy
'sabs()
andmean()
functions.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def load_wav(filename):
# Load in the audio data
sampling_freq, audio = ____
# Add the filename, audio data, and sampling frequency to the dictionary
data_dict = {
'filename': ____,
'audio': ____,
'sample_frequency': ____,
}
return data_dict
def not_silent(data_dict):
# Check if the audio data is silent
return ____