Work with actual audio files
You will create eight small WAV files, inspect their samples and compare what changes when you alter frequency, amplitude, channels and filtering. The sounds are known tones, not speech. No microphone, model, account or extra Python package is needed.
Set up once
If Python or terminal work is unfamiliar, review the optional V02–V05 refreshers first. Otherwise, start here. Create a practice folder, then download audio_lab.py into it. If your browser displays the code, use Save As and keep the .py extension. Open the terminal in that folder.
python3 audio_lab.py On Windows, use py -3 audio_lab.py if that is how your Python installation runs. The program creates a new voice-lab-output folder. Open its report.html in a browser. It includes audio controls, 20 ms waveform plots and file measurements. No server is needed.
If the output folder already exists, your work is preserved. Choose a new name:
python3 audio_lab.py --output voice-lab-second-attempt Start playback at a comfortable low volume. You can complete the comparisons using plots and measurements if you cannot or prefer not to listen.
What the program does
It calculates sine waves, quantises them to signed 16-bit PCM and writes WAV headers. The DFT inspects only the first 400 samples of the left channel. The program reads its own fixtures, creates no speech and makes no network requests.
Return to this lab as you learn
V06 · Predict duration and size
For tone-200, predict duration and PCM payload from 16,000 frames, one channel and two bytes per sample. Repeat for stereo. Compare the payload with the file size. Write the unit at every step.
V11 · Separate frequency and amplitude
Before inspecting the report, predict how tone-200, tone-400 and tone-200-quiet differ. Count the cycles in each 20 ms plot. Compare the quiet and original signals using the same vertical axis. Inspect cancelled: it adds each sample to its exact negative.
V12 · Inspect the format
Write down rate, frame count, channel count, sample width and duration for mono and stereo. Open the metadata function in the source. Find the calls that read the WAV header. Explain the difference between one audio frame and one scalar channel sample.
V15 · Connect a spectrum to a known signal
Predict bin spacing for 400 samples at 16 kHz. Which bins should contain 200 Hz and 400 Hz? Check the reported peak. Read dft and locate the real and imaginary sums. Change WINDOW from 400 to 800 in a copy of the script and generate a new folder. The report updates the analysis length and bin spacing. Predict the new bin numbers first. Our default report gives a spectrum summary, not a spectrogram; a full changing-speech spectrogram belongs in your later ASR notebook.
V16 · Trace a filter
Inspect moving_average. Calculate its first four outputs for [2,4,0,2] by hand. Compare with a call to the function. Explain the zero initial history and omitted tail. Compare filtered with tone-200; a mild low-frequency change does not mean the filter does nothing to other frequencies.
V27 · Identify distortion
Compare clipped with tone-200 using the fixed-scale plots. Explain why the clipped waveform flattens near the digital limits. Compare silence and cancelled: they sound alike here, but one was constructed directly and one by exact addition. Explain why this does not demonstrate real-room echo cancellation.
Check the reasoning
Open after predicting and inspecting
- One second of mono PCM uses 32,000 payload bytes; stereo uses 64,000. These fixtures add a 44-byte WAV header. Both last one second.
- At 200 Hz there are four cycles in 20 ms; at 400 Hz there are eight. The quiet tone has half the amplitude, the same frequency and the same duration.
- With N = 400, bin spacing is 40 Hz; the tone peaks are bins 5 and 10. With N = 800, spacing is 20 Hz and peaks are bins 10 and 20.
- The causal moving average gives [1,3,2,1] for [2,4,0,2]; full convolution would add a final 1.
- Clamping a 1.2-amplitude wave to the chosen full-scale range changes its shape. The cancelled file has zero samples because its inputs are constructed exact opposites. Real microphone echo is delayed, filtered and mixed with other sound.
Save evidence you can explain
Keep your predictions, measurements, one corrected mistake and your edited source file. In the studio notebook, save a short explanation rather than audio. These fixtures teach audio representation; they do not demonstrate recognition, synthesis or real-world audio quality.
API reference: Python's wave module. The lab uses long-established PCM methods and does not require the newest Python-only floating-point WAV features.