← Voice AI curriculum

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

You do not need to write Python for V11 or V12. You will run a supplied program and read its report. If you already use a terminal, put audio_lab.py in a new practice folder, open a terminal there and run the command below. If this is new, open the first-time steps first. V02–V05 remain optional refreshers for learning to write and manage code.

First time running a Python file?
  1. Create a folder named voice-practice in Documents. Download the linked audio_lab.py into it. If the browser shows code, save that page as audio_lab.py. Check that the name ends in .py, not .py.txt or .html. The program needs no other downloaded input files.
  2. Open Terminal on macOS/Linux, or PowerShell on Windows. A terminal is an app where you type commands. A command runs when you press Enter. You do not type the command into the Python file or the browser address bar.
  3. Type python3 --version and press Enter. On Windows try py -3 --version. A working installation prints something beginning Python 3. If neither command is recognised, install Python 3 from Python's official downloads, then reopen the terminal and check again.
  4. Find voice-practice's full location in your file manager. Use cd, meaning change directory, followed by that location inside straight double quotes. For example, cd "/Users/your-name/Documents/voice-practice" on macOS, or cd "C:\Users\your-name\Documents\voice-practice" on Windows. Replace the example with your actual location. Quotes keep a path containing spaces together.
  5. Run ls on macOS/Linux or dir on Windows. These list the current folder's contents. Check that audio_lab.py appears. If it does not, check the download location and filename before running the next command.
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.

Success begins with “Created 8 WAV files”. In your file manager, open voice-practice, then voice-lab-output, then report.html. If you see “can't open file”, check that the terminal lists audio_lab.py in the current folder. Do not install extra packages to solve this error.

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 · reference for later lessons

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. You will meet these format and spectrum terms in V12 and V15; you do not need them to compare wave height and repetition in V11.

Return to this lab as you learn

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 from the report. “Signed 16-bit PCM” means two bytes per channel value here. Explain the difference between one audio frame and one individual channel value. Optional Python extension: open the metadata function in the source and find the calls that read the WAV header. Reading the source is not required for the V12 task.

V06 · Predict duration and size

When you reach V06 later in the path, predict tone-200's duration and audio-data bytes from 16,000 frames, one channel and two bytes per sample. Repeat for stereo. Compare the audio data with the total file size. Write the unit at every step.

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.

Next: build your portfolio alongside the lessons →