DTMF¶
Dual-Tone Multi-Frequency (DTMF) tone generation and detection.
DTMF is the signalling system used by touch-tone telephones. Each keypad button is encoded as a pair of sinusoids — one from a low-frequency “row” group and one from a high-frequency “column” group:
1209 Hz |
1336 Hz |
1477 Hz |
1633 Hz |
|
|---|---|---|---|---|
697 Hz |
1 |
2 |
3 |
A |
770 Hz |
4 |
5 |
6 |
B |
852 Hz |
7 |
8 |
9 |
C |
941 Hz |
* |
0 |
# |
D |
The frequencies were chosen to avoid harmonic relationships, preventing false detections from speech or other complex signals.
Timing follows ITU-T Q.24: minimum 40 ms tone-on, minimum 40 ms inter-digit pause.
- pyminidsp.dtmf_signal_length(num_digits, sample_rate=8000.0, tone_ms=70, pause_ms=70)[source]¶
Calculate the number of samples needed for dtmf_generate().
Calculate the number of samples needed for
dtmf_generate():\[N = D \cdot \lfloor t_\text{tone} \cdot f_s / 1000 \rfloor + (D - 1) \cdot \lfloor t_\text{pause} \cdot f_s / 1000 \rfloor\]
- pyminidsp.dtmf_generate(digits, sample_rate=8000.0, tone_ms=70, pause_ms=70)[source]¶
Generate a DTMF tone sequence.
- Parameters:
digits – String of DTMF characters (‘0’-‘9’, ‘A’-‘D’, ‘*’, ‘#’).
sample_rate – Sampling rate in Hz.
tone_ms – Duration of each tone in ms (>= 40).
pause_ms – Duration of silence between tones in ms (>= 40).
- Returns:
numpy array of audio samples.
Generate a DTMF tone sequence. Each digit is rendered as the sum of its row and column sinusoids, each at amplitude 0.5 (peak sum = 1.0).
- Parameters:
digits – String of DTMF characters (
'0'–'9','A'–'D','*','#').sample_rate – Sampling rate in Hz.
tone_ms – Duration of each tone in ms (>= 40).
pause_ms – Duration of silence between tones in ms (>= 40).
- Returns:
Array of audio samples.
sig = md.dtmf_generate("5551234", sample_rate=8000.0)
- pyminidsp.dtmf_detect(signal, sample_rate=8000.0, max_tones=64)[source]¶
Detect DTMF tones in an audio signal.
- Parameters:
signal – Audio samples.
sample_rate – Sampling rate in Hz.
max_tones – Maximum number of tones to detect.
- Returns:
List of (digit, start_s, end_s) tuples.
Detect DTMF tones in an audio signal.
Uses a sliding Hanning-windowed FFT with a state machine that enforces ITU-T Q.24 minimum timing constraints (40 ms tone-on, 40 ms inter-digit pause).
- Parameters:
signal – Audio samples (mono).
sample_rate – Sampling rate in Hz (must be >= 4000).
max_tones – Maximum number of tones to detect.
- Returns:
List of
(digit, start_s, end_s)tuples.
digits = "5551234" sig = md.dtmf_generate(digits, sample_rate=8000.0) tones = md.dtmf_detect(sig, sample_rate=8000.0) detected = "".join(t[0] for t in tones) assert detected == digits