Audio and speech task families
What is audio AI?
Audio AI analyzes or generates sound. A waveform stores amplitude over time; a sample is one measurement at a particular instant. Sample rate is measurements per second (Hz), not loudness or file size. A mono signal with four samples at 4 Hz represents a one-second recording window; sample times are 0, 0.25, 0.5 and 0.75 seconds. Stereo has two channels, so sample count per channel must be distinguished from total stored values. Quantization maps amplitude to finite levels; bit depth and sample rate are different properties.
Measure a synthetic waveform
The list [0, 1, 0, -1] is a tiny synthetic waveform. Root mean square (RMS) amplitude is the square root of the mean squared amplitude. It measures signal magnitude in the supplied units, not perceived loudness. Duration equals sample count per channel divided by sample rate. The function expects a nonempty mono list of small finite real amplitudes and a positive integer rate.
def audio_summary(samples, rate): if type(rate) is not int or rate <= 0: raise ValueError("positive integer sample rate required") if not samples: raise ValueError("empty signal") from math import sqrt return len(samples) / rate, sqrt(sum(x*x for x in samples) / len(samples))
print(audio_summary([0, 1, 0, -1], 4))print(audio_summary([0, 0], 8))The first result is (1.0, approximately 0.7071); the second is (0.25, 0.0). Silence has zero RMS. A spectrogram represents frequency content across short time windows, with frequency and time axes and intensity indicating magnitude or power according to the chosen transform. A mel spectrogram uses a perceptually motivated frequency scale. Changing sample rate requires appropriate resampling, including anti-alias filtering when reducing rate; simply relabeling the rate changes the interpreted timing. Frequencies above half the sample rate cannot be uniquely represented under the usual bandlimited sampling assumptions.
Choose the speech task
Automatic speech recognition (ASR) converts speech to text. Text-to-speech (TTS) generates speech audio from text. Audio classification predicts categories such as a synthetic alarm type, while event detection identifies when events occur. ASR can miss words in noise; TTS can mispronounce words or sound unnatural. Neither a plausible transcript nor natural speech guarantees factual accuracy. Streaming systems also need end-to-end latency, including buffering and processing, measured separately from offline accuracy. Use generated tones and invented transcripts, not private recordings or voice imitation.
Measure transcript errors
Word error rate (WER) is the minimum number of word substitutions, insertions and deletions divided by the reference word count. Match words under an explicit normalization policy; this example uses whitespace splitting and case-sensitive equality. The dynamic program stores distances between prefixes: inserting or deleting costs one, replacing a different word costs one, and matching costs zero. Each row uses the previous row and the current row’s left neighbor. Empty references return None for WER, but the edit count is still defined. WER may exceed 1 (100%) due to insertions.
def word_edits(reference, hypothesis): previous = list(range(len(hypothesis) + 1)) for i, ref in enumerate(reference, 1): current = [i] for j, hyp in enumerate(hypothesis, 1): current.append(min(previous[j] + 1, current[j-1] + 1, previous[j-1] + (ref != hyp))) previous = current return previous[-1]
def word_error_rate(reference, hypothesis): if not reference: return None return word_edits(reference, hypothesis) / len(reference)
print(word_edits("pack blue boxes".split(), "pack red boxes now".split()))print(round(word_error_rate("pack blue boxes".split(), "pack red boxes now".split()), 4))print(word_error_rate(["go"], ["go", "now", "please"]))print(word_error_rate([], ["hello"]))Changing blue to red and adding now costs two edits, so WER is 2/3, or about 66.67%. Adding two words to a one-word reference gives WER 2.0. For Persian evaluation, document normalization of letter variants, spacing and half-spaces, punctuation and digits before comparing systems; report performance by language variety and noise condition. Character error rate can complement WER, but neither measures meaning or accessibility by itself. For a corpus use total edits divided by total reference words, not an unweighted average of per-utterance WER. Evaluate empty-reference insertions separately or include their edit counts in corpus totals if that policy is declared.
Practice and recap
Compute the duration of 8000 mono samples at 16000 Hz, then compute the WER for reference “open blue box” and hypothesis “open box”. Answers: 0.5 seconds and 1/3. Explain why lowering WER does not prove TTS quality. Next, use temporal order to evaluate forecasts.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Audio and speech task families quiz
Apply the lesson to small synthetic inputs.
How long is a mono recording containing 8000 samples at 16000 Hz?
Which representation shows how frequency content changes over time?
Which task converts written instructions into spoken audio?
Using the lesson’s whitespace tokenization, what is WER for reference "pack blue boxes" and hypothesis "pack boxes"?
For a nonempty reference, why can WER exceed 100%?