Skip to content

Python package for working with ToneScript, a syntax for describing the characteristics of the call progress tones used in telephony.

License

Notifications You must be signed in to change notification settings

gdereese/tonescript

Repository files navigation

tonescript

GitHub Workflow Status (branch) PyPI

Python package for working with ToneScript, a syntax for describing the characteristics of the call progress tones used in telephony. It is the primary method for configuring tones in Sipura, Linksys, and Cisco VoIP systems.

Features

  • Parses ToneScript into its components: frequencies, cadence sections, and tone segments
  • Constructs ToneScript from component objects
  • Renders ToneScript objects into WAV audio files

Installation

pip install tonescript

Usage

Parsing a ToneScript

import tonescript as ts

# standard North American dial tone
script = "350@-13,440@-13;10(*/0/1+2)"

tone = ts.parse(script)

print(str(tone))

Output:

Frequency components:
    1) 350 Hz @ -13 dBm
    2) 440 Hz @ -13 dBm
Cadence sections:
    1) For 10 s:
        1) Always on, frequencies 1, 2

Constructing a ToneScript

from decimal import Decimal

import tonescript as ts
import tonescript.model as ts_model

# standard North American dial tone
tone = ts_model.ToneScript(
    ts_model.FreqScript([
        ts_model.FrequencyComponent(350, Decimal("-13")),
        ts_model.FrequencyComponent(440, Decimal("-13"))
    ]),
    ts_model.CadScript([
        ts_model.CadenceSection(Decimal("10"), [
            ts_model.ToneSegment(Decimal("inf"), Decimal("0"), [1, 2])
        ])
    ])
)

script = ts.unparse(tone)

print(script)

Output:

350@-13,440@-13;10(*/0/1+2)

Rendering a ToneScript into a WAV audio file

import tonescript as ts

# standard North American dial tone
tone = ts.parse("350@-13,440@-13;10(*/0/1+2)")

# 16-bit PCM, 44.1 kHz sample rate
ts.render(tone, "./dial_tone.wav", 44100, 2)

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/tonescript

Running tests

poetry run pytest

Building HTML documentation

For development

poetry run pdoc --template-dir docs_template --http : tonescript

For distribution or deployment

poetry run pdoc --template-dir docs_template --html tonescript

License

This library is licensed under the terms of the MIT license.

About

Python package for working with ToneScript, a syntax for describing the characteristics of the call progress tones used in telephony.

Topics

Resources

License

Stars

Watchers

Forks

Languages