0
0
SciPydata~20 mins

WAV audio file handling in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WAV Audio Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A44100
Bdata array
Cwavfile.read object
DError: file not found
Attempts:
2 left
💡 Hint
The first value returned by wavfile.read is the sample rate as an integer.
data_output
intermediate
2: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)
A(2, 1000)
B(1000, 2)
C(1000,)
D(2000,)
Attempts:
2 left
💡 Hint
Stereo audio has two channels, so the data array has two columns.
🔧 Debug
advanced
2: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)
ATypeError: data type not supported
BSyntaxError
CNo error, file written successfully
DValueError: data must be integer type
Attempts:
2 left
💡 Hint
scipy.io.wavfile.write expects integer data types for PCM WAV files.
🚀 Application
advanced
2: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
Anormalized = data / 65535.0
Bnormalized = data / 32768.0
Cnormalized = data.astype(float) / 32767.0
Dnormalized = data / 32767.0
Attempts:
2 left
💡 Hint
16-bit signed PCM ranges from -32768 to 32767; normalization uses max positive value.
🧠 Conceptual
expert
2: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?
AAudio plays at half speed and one octave lower
BAudio plays normally with no change
CAudio plays at double speed and one octave higher
DAudio file is corrupted and won't play
Attempts:
2 left
💡 Hint
Lowering sample rate without changing data affects playback speed and pitch.