# Trackpad Voice: code

A Python port of the voice in [nospeaker](https://github.com/os6/nospeaker) by Cody Collier (MIT), and the test behind the note [Why a talking trackpad plays two notes, not three](/a-trackpad-that-talks/).

- `haptic_voice.py`: speech from espeak-ng, then the analysis from `nospeaker.swift` (LPC order 18 every 10 ms, formant picking, pitch, voicing, level), the motor drive (one set of sine tones per pitch period, strengths summing to 1, hiss as 4 ms bursts of three tones from 2.7 to 4.3 kHz), and a model of the glass from the loudness chart in nospeaker's README plus a quiet room's noise.
- `two_vs_three.py`: the test. 20 words (the ten digits and heed, hid, head, had, hod, hawed, hood, who'd, hud, heard), 8 espeak voices, 4 speaking rates: 640 recordings. Three playback rules, five rooms. Listener: MFCC features and dynamic time warping, nearest neighbour, trained on the other seven voices played the same way. Paired exact test between rules on the same recordings.
- `export_page_data.py`: the lines and figures the experiment page plays.
- `results.json`: every number in the note, and each recording's right or wrong per condition.

Run: `pip install numpy scipy soundfile librosa numba`, install `espeak-ng`, then `python3 two_vs_three.py` (about 10 minutes on four cores).

Noise and hiss seeds come from Python's `hash()`, which changes between runs unless `PYTHONHASHSEED` is set; the published run did not set it, so a rerun matches to within a point or so, not exactly.

The motor and glass are simulated from published measurements, not measured, and the listener is a machine, not people.
