ComeçarComece de graça

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.

Este exercício faz parte do curso

Parallel Programming with Dask in Python

Ver curso

Instruções do exercício

  • Inside the load_wav() function, use wavfile.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 using numpy's abs() and mean() functions.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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 ____
Editar e executar o código