Skip to main content

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, typing only
  • 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_TABLE for 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-pure CLI wrapper if needed)
  • Tone detection (use pydtmf for that)
  • numpy/scipy acceleration
  • Multiple sample rates or bit depths beyond 8kHz/16-bit mono

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dtmf_tone_pure-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dtmf_tone_pure-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file dtmf_tone_pure-0.1.0.tar.gz.

File metadata

  • Download URL: dtmf_tone_pure-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for dtmf_tone_pure-0.1.0.tar.gz
Algorithm Hash digest
SHA256 00d990385952eeb611d53456215d9bbcc3638ad4db835d5991db90020ee5f54c
MD5 f47a16bba2b03918ad599778b46f6345
BLAKE2b-256 4e383453c6393cf1123fea3458f8f6b29794cb7d025c375764d79c5a8e4c5d67

See more details on using hashes here.

File details

Details for the file dtmf_tone_pure-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dtmf_tone_pure-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for dtmf_tone_pure-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 879c041e21aa63b49646a1299a1fac43f3f73766cbdc13acd08a02e19e19c3a0
MD5 ed5806def6fb1e1554a48343e5219a93
BLAKE2b-256 486884f2bdf3b9f1fd5b8a08f3a48ec0d02684a034d10ef0cda715bd0648f270

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page