dtmf


Namedtmf JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/gdereese/dtmf
SummaryPackage for working with DTMF - a system for signaling over the voice band of a telephony system using multi-frequency tones.
upload_time2024-12-06 13:12:49
maintainerNone
docs_urlNone
authorGary DeReese
requires_python<3.13,>=3.10
licenseMIT
keywords dtmf parser telephony voip
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dtmf

![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/gdereese/dtmf/CI/main?style=for-the-badge)
![PyPI](https://img.shields.io/pypi/v/dtmf?style=for-the-badge)

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

```shell
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`-`9`
* `A`-`D`
* `*` or `E`
* `#` or `F`

In addition to the 16 DTMF symbols, dial strings support the following additional symbols:

* `P` or `,` for a momentary pause (usually 2 seconds)

## Usage

### Parsing a dial string

```python
from dtmf import parse

dial_str = "5551234,500#"

obj = parse(dial_str)

print(repr(obj))
```

**Output:**

```text
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

```python
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:**

```text
5551234,500#
```

### Detecting DTMF tones in an audio buffer

```python
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:**

```text
  0 - 105 : 5
105 - 210 : 5
210 - 315 : 5
315 - 420 : 5
420 - 525 : None
...
```

### Generating DTMF audio from a dial string

```python
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](https://github.com/gdereese/dtmf/issues) to report any issues.

## Contributing

### Installing for development

```shell
poetry install
```

### Linting source files

```shell
poetry run pylint --rcfile .pylintrc src/dtmf
```

### Running tests

```shell
poetry run pytest
```

## License

This library is licensed under the terms of the [MIT](https://choosealicense.com/licenses/MIT/) license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gdereese/dtmf",
    "name": "dtmf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.10",
    "maintainer_email": null,
    "keywords": "dtmf, parser, telephony, voip",
    "author": "Gary DeReese",
    "author_email": "garydereese@sbcglobal.net",
    "download_url": "https://files.pythonhosted.org/packages/06/7e/da1eec0de16f335c18c5000cb96b29e5414f1109d00e739b2bc3561e8916/dtmf-1.1.0.tar.gz",
    "platform": null,
    "description": "# dtmf\n\n![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/gdereese/dtmf/CI/main?style=for-the-badge)\n![PyPI](https://img.shields.io/pypi/v/dtmf?style=for-the-badge)\n\nPackage for working with DTMF - a system for signaling over the voice band of a telephony system using multi-frequency tones.\n\n## Features\n\n* Parses dial strings (digits, symbols, etc.) into an object representation\n* Constructs dial strings from element objects\n* Detects the presence and position of DTMF tones in an audio buffer\n* Generates DTMF audio from dial strings\n\n## Installation\n\n```shell\npip install dtmf\n```\n\n## What is DTMF?\n\nDual-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.\n\nDTMF 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:\n\n|            | **1209 Hz** | **1336 Hz** | **1477 Hz** | **1633 Hz** |\n| ---------- | :---------: | :---------: | :---------: | :---------: |\n| **697 Hz** | 1           | 2           | 3           | A           |\n| **770 Hz** | 4           | 5           | 6           | B           |\n| **852 Hz** | 7           | 8           | 9           | C           |\n| **941 Hz** | *           | 0           | #           | D           |\n\n### Dial string syntax\n\nA 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.\n\nDial strings use the following DTMF symbols:\n\n* `0`-`9`\n* `A`-`D`\n* `*` or `E`\n* `#` or `F`\n\nIn addition to the 16 DTMF symbols, dial strings support the following additional symbols:\n\n* `P` or `,` for a momentary pause (usually 2 seconds)\n\n## Usage\n\n### Parsing a dial string\n\n```python\nfrom dtmf import parse\n\ndial_str = \"5551234,500#\"\n\nobj = parse(dial_str)\n\nprint(repr(obj))\n```\n\n**Output:**\n\n```text\nString([\n    Tone(\"5\"),\n    Tone(\"5\"),\n    Tone(\"5\"),\n    Tone(\"1\"),\n    Tone(\"2\"),\n    Tone(\"3\"),\n    Tone(\"4\"),\n    Pause(),\n    Tone(\"5\"),\n    Tone(\"0\"),\n    Tone(\"0\"),\n    Tone(\"#\")\n])\n```\n\n### Constructing a dial string\n\n```python\nimport dtmf.model as model\n\nobj = model.String([\n    model.Tone(\"5\"),\n    model.Tone(\"5\"),\n    model.Tone(\"5\"),\n    model.Tone(\"1\"),\n    model.Tone(\"2\"),\n    model.Tone(\"3\"),\n    model.Tone(\"4\"),\n    model.Pause(),\n    model.Tone(\"5\"),\n    model.Tone(\"0\"),\n    model.Tone(\"0\"),\n    model.Tone(\"#\")\n])\n\nprint(str(obj))\n```\n\n**Output:**\n\n```text\n5551234,500#\n```\n\n### Detecting DTMF tones in an audio buffer\n\n```python\nfrom dtmf import detect\n\n# list of audio samples as floats\ndata = [...]\nsample_rate = 8000\n\nresults = detect(data, sample_rate)\n\nfor result in results:\n    print(f\"{result.start:<3d} - {result.end:>5d} : {result.tone!s}\")\n```\n\n**Output:**\n\n```text\n  0 - 105 : 5\n105 - 210 : 5\n210 - 315 : 5\n315 - 420 : 5\n420 - 525 : None\n...\n```\n\n### Generating DTMF audio from a dial string\n\n```python\nfrom dtmf import generate\nimport dtmf.model as model\n\nobj = model.String([\n    model.Tone(\"5\"),\n    model.Tone(\"5\"),\n    model.Tone(\"5\"),\n    model.Tone(\"1\"),\n    model.Tone(\"2\"),\n    model.Tone(\"3\"),\n    model.Tone(\"4\"),\n    model.Pause(),\n    model.Tone(\"5\"),\n    model.Tone(\"0\"),\n    model.Tone(\"0\"),\n    model.Tone(\"#\")\n])\n\naudio = generate(obj)\n```\n\n## Support\n\nPlease use the project's [Issues page](https://github.com/gdereese/dtmf/issues) to report any issues.\n\n## Contributing\n\n### Installing for development\n\n```shell\npoetry install\n```\n\n### Linting source files\n\n```shell\npoetry run pylint --rcfile .pylintrc src/dtmf\n```\n\n### Running tests\n\n```shell\npoetry run pytest\n```\n\n## License\n\nThis library is licensed under the terms of the [MIT](https://choosealicense.com/licenses/MIT/) license.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package for working with DTMF - a system for signaling over the voice band of a telephony system using multi-frequency tones.",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/gdereese/dtmf",
        "Repository": "https://github.com/gdereese/dtmf"
    },
    "split_keywords": [
        "dtmf",
        " parser",
        " telephony",
        " voip"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10964dd079adf004a3c08a12b2134bb9ad1b5eed7a5b8bcef88d173dce045a6d",
                "md5": "5743aa121e6c3663477401b7376b525b",
                "sha256": "8bf342af0bc9727384c744d1fee0fa02df27a8f1ee600f0ed9c7752e75fa4034"
            },
            "downloads": -1,
            "filename": "dtmf-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5743aa121e6c3663477401b7376b525b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.10",
            "size": 8586,
            "upload_time": "2024-12-06T13:12:47",
            "upload_time_iso_8601": "2024-12-06T13:12:47.688639Z",
            "url": "https://files.pythonhosted.org/packages/10/96/4dd079adf004a3c08a12b2134bb9ad1b5eed7a5b8bcef88d173dce045a6d/dtmf-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "067eda1eec0de16f335c18c5000cb96b29e5414f1109d00e739b2bc3561e8916",
                "md5": "92b685d4f66080a5fcc1c686c27e05ec",
                "sha256": "0155cb3b5a84042a8698e8ccef23f68a590a0e11d04cb7309c0f6eb1acb7ea9d"
            },
            "downloads": -1,
            "filename": "dtmf-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "92b685d4f66080a5fcc1c686c27e05ec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.10",
            "size": 6578,
            "upload_time": "2024-12-06T13:12:49",
            "upload_time_iso_8601": "2024-12-06T13:12:49.186150Z",
            "url": "https://files.pythonhosted.org/packages/06/7e/da1eec0de16f335c18c5000cb96b29e5414f1109d00e739b2bc3561e8916/dtmf-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 13:12:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gdereese",
    "github_project": "dtmf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dtmf"
}
        
Elapsed time: 4.72153s