dtmf
Package for working with DTMF - a system for signaling over the voice band of a telephony system using multi-frequency tones.
Features
- Parses dial strings (digits, symbols, etc.) into an object representation
- Constructs dial strings from element objects
- Detects the presence and position of DTMF tones in an audio buffer
- Generates DTMF audio from dial strings
Installation
pip install dtmf
What is DTMF?
Dual-tone multi-frequency signaling (DTMF) is a telecommunication signaling system used between telephone equipment and other communications devices. DTMF became known in the United States as 'Touch-Tone' for use in push-button telephones supplied to telephone customers.
DTMF tones use a mixture of two sine waves at different frequencies. Eight different audio frequencies are combined in pairs to make 16 unique tones. A tone is assigned to each of the digits from 0 to 9, the letters A to D, and the symbols # and *. The combination used for each tone are as follows:
| 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 |
Dial string syntax
A dial string is a textual representation of a sequence of DTMF digits and/or symbols. This format is commonly used as input to a telephone modem or another telephony device with automatic dialing as instructions for dialing the recipient of an outgoing call.
Dial strings use the following DTMF symbols:
0-9A-D*orE#orF
In addition to the 16 DTMF symbols, dial strings support the following additional symbols:
Por,for a momentary pause (usually 2 seconds)
Usage
Parsing a dial string
from dtmf import parse
dial_str = "5551234,500#"
obj = parse(dial_str)
print(repr(obj))
Output:
String([
Tone("5"),
Tone("5"),
Tone("5"),
Tone("1"),
Tone("2"),
Tone("3"),
Tone("4"),
Pause(),
Tone("5"),
Tone("0"),
Tone("0"),
Tone("#")
])
Constructing a dial string
import dtmf.model as model
obj = model.String([
model.Tone("5"),
model.Tone("5"),
model.Tone("5"),
model.Tone("1"),
model.Tone("2"),
model.Tone("3"),
model.Tone("4"),
model.Pause(),
model.Tone("5"),
model.Tone("0"),
model.Tone("0"),
model.Tone("#")
])
print(str(obj))
Output:
5551234,500#
Detecting DTMF tones in an audio buffer
from dtmf import detect
# list of audio samples as floats
data = [...]
sample_rate = 8000
results = detect(data, sample_rate)
for result in results:
print(f"{result.start:<3d} - {result.end:>5d} : {result.tone!s}")
Output:
0 - 105 : 5
105 - 210 : 5
210 - 315 : 5
315 - 420 : 5
420 - 525 : None
...
Generating DTMF audio from a dial string
from dtmf import generate
import dtmf.model as model
obj = model.String([
model.Tone("5"),
model.Tone("5"),
model.Tone("5"),
model.Tone("1"),
model.Tone("2"),
model.Tone("3"),
model.Tone("4"),
model.Pause(),
model.Tone("5"),
model.Tone("0"),
model.Tone("0"),
model.Tone("#")
])
audio = generate(obj)
Support
Please use the project's Issues page to report any issues.
Contributing
Installing for development
poetry install
Linting source files
poetry run pylint --rcfile .pylintrc src/dtmf
Running tests
poetry run pytest
License
This library is licensed under the terms of the MIT license.
Metadata
Release files for dtmf 1.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-1.1.0.tar.gz | 6.6 kB | Without provenance | Details for dtmf-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dtmf-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for dtmf-1.1.0-py3-none-any.whl |
Total release size: 15.2 kB
Release files / dtmf-1.1.0.tar.gz
| Download URL | dtmf-1.1.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0155cb3b5a84042a8698e8ccef23f68a590a0e11d04cb7309c0f6eb1acb7ea9d
|
|
BLAKE2b-256 checksum How to use checksums |
067eda1eec0de16f335c18c5000cb96b29e5414f1109d00e739b2bc3561e8916
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
|
Release files / dtmf-1.1.0-py3-none-any.whl
| Download URL | dtmf-1.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8bf342af0bc9727384c744d1fee0fa02df27a8f1ee600f0ed9c7752e75fa4034
|
|
BLAKE2b-256 checksum How to use checksums |
10964dd079adf004a3c08a12b2134bb9ad1b5eed7a5b8bcef88d173dce045a6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
|
Security for dtmf 1.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.