dtmf-tone-pure
Zero-dependency DTMF tone generator — pure stdlib Python, RFC 4733-compliant WAV output.
Generate all 16 ITU Q.23/Q.24 DTMF tones as WAV bytes using only math and struct. No numpy, no C extensions, no dependencies. Designed for AWS Lambda, Cloudflare Workers, and embedded Python.
Quick Start
pip install dtmf-tone-pure
from dtmf_tone_pure import DTMFTone
tone = DTMFTone().tone('5') # Single tone, 44+ bytes of WAV
tones = DTMFTone().tones('911') # Multi-digit with 10ms inter-digit pause
coeff = DTMFTone().goertzel_coefficient(697, block_size=120) # Goertzel coefficient
Install from source:
pip install git+https://github.com/prasad-a-abhishek/dtmf-tone-pure.git
Run tests:
pip install -e .
pytest tests/ -v
Why dtmf-tone-pure?
Every existing DTMF library for Python depends on numpy or C extensions. In serverless environments (AWS Lambda cold start ~50ms for numpy import, ~50MB memory), that's prohibitive.
dtmf-tone-pure fills the gap: the only zero-dependency Python package on PyPI that generates DTMF tones as RFC 4733-compliant WAV bytes. (pydtmf on PyPI does detection only.)
| Package | PyPI | Generation | Dependencies |
|---|---|---|---|
dtmf-tone-pure |
Yes (this) | Yes | None |
pydtmf |
Yes | No (detection only) | None |
| numpy scripts | Various | Yes | numpy |
Key Features
- 16 DTMF tones: 0–9, A–D,
*,#per ITU Q.23/Q.24 - Zero dependencies: pure stdlib —
math,struct,typingonly - WAV output: 8 kHz, 16-bit mono PCM with correct RIFF header
- Goertzel coefficient:
goertzel_coefficient(freq, block_size)matching analytical values - ITU-spec durations: 60ms tone, 10ms inter-digit pause
- Subclassable: override
FREQ_TABLEfor custom frequency pairs
API Reference
from dtmf_tone_pure import DTMFTone
dtmf = DTMFTone()
# Class constants
dtmf.SAMPLE_RATE # 8000 Hz
dtmf.TONE_DURATION # 0.060 s (60 ms)
dtmf.PAUSE_DURATION # 0.010 s (10 ms)
dtmf.FREQ_TABLE # {'1': (697.0, 1209.0), ...} — 16 entries
# Methods
dtmf.tone(key: str) -> bytes
# Single DTMF tone as WAV bytes.
# key: '0'-'9', 'A'-'D', '*', '#'
# Returns: 44-byte RIFF WAV header + PCM samples
dtmf.tones(digits: str) -> bytes
# Concatenated tones with 10ms inter-digit silence.
# Returns: single valid WAV file
dtmf.goertzel_coefficient(freq: float, *, block_size: int = 120) -> float
# Goertzel coefficient = 2 * cos(2π * k / N)
# k = round(N * freq / sample_rate)
# Returns: float rounded to 6 decimal places
DTMF Frequency Table (ITU Q.23/Q.24):
| 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 |
Limitations
- Single sample rate (8000 Hz). Custom rates require subclassing and recomputing.
- Amplitude is fixed at 16383.5 scale factor (max sum-of-two-sines → max int16).
tones()returns a single concatenated WAV; no gapless-playback marker between segments.- Goertzel coefficient precision is rounded to 6 decimal places.
Non-Goals
- CLI interface (see
goertzel-tone-pureCLI wrapper if needed) - Tone detection (use
pydtmffor that) - numpy/scipy acceleration
- Multiple sample rates or bit depths beyond 8kHz/16-bit mono
License
MIT — see LICENSE.
Metadata
Release files for dtmf-tone-pure 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dtmf_tone_pure-0.1.0.tar.gz | 13.1 kB | Without provenance | Details for dtmf_tone_pure-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dtmf_tone_pure-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dtmf_tone_pure-0.1.0-py3-none-any.whl |
Total release size: 19.4 kB
Release files / dtmf_tone_pure-0.1.0.tar.gz
| Download URL | dtmf_tone_pure-0.1.0.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00d990385952eeb611d53456215d9bbcc3638ad4db835d5991db90020ee5f54c
|
|
BLAKE2b-256 checksum How to use checksums |
4e383453c6393cf1123fea3458f8f6b29794cb7d025c375764d79c5a8e4c5d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / dtmf_tone_pure-0.1.0-py3-none-any.whl
| Download URL | dtmf_tone_pure-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
879c041e21aa63b49646a1299a1fac43f3f73766cbdc13acd08a02e19e19c3a0
|
|
BLAKE2b-256 checksum How to use checksums |
486884f2bdf3b9f1fd5b8a08f3a48ec0d02684a034d10ef0cda715bd0648f270
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for dtmf-tone-pure 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.