Challenge - 5 Problems
Audio File Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this code reading a WAV file?
Given the code below that reads an audio file and prints the sample rate and shape of the data array, what will be printed?
Signal Processing
import numpy as np from scipy.io import wavfile sample_rate, data = wavfile.read('test_audio.wav') print(sample_rate, data.shape)
Attempts:
2 left
💡 Hint
Check the sample rate and shape returned by wavfile.read for a stereo file sampled at 44100 Hz.
✗ Incorrect
The wavfile.read function returns the sample rate and a numpy array of audio data. For a stereo file, the shape has two columns (channels). The sample rate is 44100 Hz.
❓ data_output
intermediateWhat is the shape of the audio data array after reading a mono WAV file?
If you read a mono WAV file using scipy.io.wavfile.read, what will be the shape of the returned data array?
Signal Processing
from scipy.io import wavfile sample_rate, data = wavfile.read('mono_audio.wav') print(data.shape)
Attempts:
2 left
💡 Hint
Mono audio data is a single channel, so the array is one-dimensional.
✗ Incorrect
Mono audio data is returned as a one-dimensional numpy array with length equal to the number of samples.
🔧 Debug
advancedWhy does this code raise an error when writing audio?
This code tries to write a numpy array to a WAV file but raises a ValueError. What is the cause?
Signal Processing
from scipy.io import wavfile import numpy as np sample_rate = 44100 data = np.array([0.1, 0.2, 0.3, 0.4]) wavfile.write('output.wav', sample_rate, data)
Attempts:
2 left
💡 Hint
Check the data type required by wavfile.write for audio data.
✗ Incorrect
scipy.io.wavfile.write requires the data array to be an integer type like int16. Float arrays cause a ValueError.
🚀 Application
advancedHow to normalize audio data before writing to WAV?
You have a numpy array of audio samples with float values between -2 and 2. Which option correctly normalizes it to int16 range before saving?
Signal Processing
import numpy as np from scipy.io import wavfile float_data = np.array([-2.0, 0.0, 2.0, 1.0])
Attempts:
2 left
💡 Hint
Normalization scales the max absolute value to 1 before converting.
✗ Incorrect
Option A scales the data by dividing by the max absolute value, then multiplies by 32767 to fit int16 range.
🧠 Conceptual
expertWhat happens if you write stereo data as mono in WAV file?
If you have a stereo numpy array with shape (samples, 2) but write only one channel to a WAV file, what is the effect?
Attempts:
2 left
💡 Hint
Writing only one channel means only that channel's data is saved.
✗ Incorrect
Writing only one channel array results in a mono WAV file containing just that channel's audio.
