Challenge - 5 Problems
WAV Audio Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of reading WAV file sample rate
What is the output of this code snippet that reads a WAV file's sample rate?
SciPy
from scipy.io import wavfile sample_rate, data = wavfile.read('example.wav') print(sample_rate)
Attempts:
2 left
💡 Hint
The first value returned by wavfile.read is the sample rate as an integer.
✗ Incorrect
The wavfile.read function returns a tuple: (sample_rate, data). The sample rate is an integer representing samples per second.
❓ data_output
intermediate2:00remaining
Shape of data array from stereo WAV file
If you read a stereo WAV file with 1000 samples using scipy.io.wavfile.read, what is the shape of the data array?
SciPy
from scipy.io import wavfile sample_rate, data = wavfile.read('stereo.wav') print(data.shape)
Attempts:
2 left
💡 Hint
Stereo audio has two channels, so the data array has two columns.
✗ Incorrect
For stereo WAV files, data is a 2D numpy array with shape (samples, channels). Here, 1000 samples and 2 channels means shape (1000, 2).
🔧 Debug
advanced2:00remaining
Error when writing WAV file with float data
What error will this code raise when trying to write a WAV file with float data using scipy.io.wavfile.write?
SciPy
from scipy.io import wavfile import numpy as np sample_rate = 44100 data = np.array([0.1, 0.2, 0.3], dtype=float) wavfile.write('output.wav', sample_rate, data)
Attempts:
2 left
💡 Hint
scipy.io.wavfile.write expects integer data types for PCM WAV files.
✗ Incorrect
The write function requires integer arrays for PCM WAV files. Passing float arrays causes a ValueError.
🚀 Application
advanced2:00remaining
Normalize WAV audio data to range -1 to 1
Which code snippet correctly normalizes 16-bit PCM WAV data to float values between -1 and 1?
SciPy
from scipy.io import wavfile sample_rate, data = wavfile.read('audio.wav') # Normalize data here
Attempts:
2 left
💡 Hint
16-bit signed PCM ranges from -32768 to 32767; normalization uses max positive value.
✗ Incorrect
To normalize 16-bit signed PCM data, convert to float and divide by 32767.0 to get range approximately -1 to 1.
🧠 Conceptual
expert2:00remaining
Effect of changing sample rate when writing WAV file
If you read a WAV file at 44100 Hz and write it back with a sample rate of 22050 Hz without changing data, what happens when playing the new file?
Attempts:
2 left
💡 Hint
Lowering sample rate without changing data affects playback speed and pitch.
✗ Incorrect
Writing the same data with half the sample rate causes playback at half speed and pitch drops one octave.