AI Beyond Language Models ยท Everyday AI
A microphone measures air pressure many times a second. Sample a simple wave, and find its pitch by counting how often it rises through zero.
import math
# Speech AI starts with sound as numbers: air pressure, measured many times a second.
rate = 16 # samples per second (real audio uses 16,000 or more)
times = list(range(rate))
samples = [round(math.sin(2 * math.pi * 2 * t / rate), 2) for t in times] # a low 2 Hz hum
# How many times does the wave go up through zero? That is its pitch, in waves per second.
crossings = len([1 for a, b in zip(samples, samples[1:]) if a <= 0 < b])
print("pitch:", crossings, "waves per second")math module, for functions like math.exp and math.sqrt.