Touch tones as a file, and digits out of a recording. DTMF encodes each key as two sine tones, one from a low group and one from a high group, which is how phone keypads have signalled since the 1960s and how IVR menus still listen.
Keys to tones
Type or tap the sequence. Each key plays for the tone length with the gap after it, edged with a short raised-cosine so the file has no clicks. Level is the pair’s share of full scale, each tone taking half. The WAV is mono at the chosen sample rate and bit depth; 8 kHz is enough for telephony, 48 kHz for anything that will be processed further.
Tones to keys
Open a recording, or listen through the microphone with a phone’s keypad held to it. The decoder runs eight Goertzel filters over 20 ms frames, picks the strongest row and column tone, and accepts the pair when both stand clear of their neighbours and carry most of the frame’s energy. A key is reported once it has held for two frames, and again only after a gap, so a held key is one digit. The time listed is where each key began.
The frequencies
Rows are 697, 770, 852 and 941 Hz; columns are 1209, 1336, 1477 and 1633 Hz. The fourth column, A to D, exists on radio and military keypads and is accepted by the decoder even though consumer phones do not have it.
Limits
A recording with a tone that is distorted or heavily compressed may read a wrong digit or none; the pair has to be clean enough for its two tones to dominate the frame. Decoding is reported once per key press, so a key held for a second is one digit, not several.