Skip to main content

Pure Python DTMF/MF tone detection using the Goertzel algorithm

Project description

PyDTMF 🔢🎵

纯 Python 实现的 DTMF/MF 双音多频信号检测库 — 零外部依赖。

使用 Goertzel 算法从 WAV 音频文件中检测 DTMF(双音多频)和 Bell MF(多频)拨号音。

功能特点

  • DTMF 检测 — 数字 0-9、*、#、A、B、C、D
  • Bell MF 检测 — 多频信令音检测
  • 纯 Python — 无 C 扩展、无 NumPy,仅使用标准库
  • WAV 支持 — 8/16/24/32 位 PCM,任意采样率
  • 音频预处理 — 自动转单声道、去直流偏置、音量归一化、重采样至 8kHz

安装

pip install git+https://github.com/Moxin1044/PyDTMF.git

或者直接复制 PyDTMF/ 目录即可使用 — 无需安装。

使用方法

命令行

python -m PyDTMF recording.wav
python -m PyDTMF recording.wav --mf          # 同时检测 MF 信号
python -m PyDTMF recording.wav --no-optimize  # 跳过预处理

Python API

from PyDTMF import from_wav, detect, from_pcm

# 从 WAV 文件检测
dtmf, mf = detect("recording.wav")
print(f"DTMF: {dtmf}")

# 从 WAV 字节数据检测(例如从网络下载)
with open("recording.wav", "rb") as f:
    dtmf, mf = from_wav(f.read())

# 从原始 PCM 采样数据检测
dtmf, mf = from_pcm(samples, sample_rate=44100, channels=1)

# 同时检测 MF 信号
dtmf, mf = from_pcm(samples, detect_mf_mode=True)

工作原理

  1. 解析 WAV 文件头 → 提取格式信息
  2. 转换为单声道、去除直流偏置、归一化音量
  3. 重采样至 8kHz(电话标准采样率)
  4. 使用 Goertzel 算法测量每个 DTMF 频率的能量
  5. 当两个主导频率(一个行频、一个列频)超过阈值时判定为有效数字

DTMF 频率表

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

许可证

GNU General Public License v2.0。

Project details


Download files

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

Source Distribution

pydtmf-1.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

pydtmf-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pydtmf-1.0.0.tar.gz.

File metadata

  • Download URL: pydtmf-1.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydtmf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 320916ef7f3e446b5fc043577724c49bcb52271eb1115141974a1114cfadd0df
MD5 a0c686a908e98fd7c814d438259d230a
BLAKE2b-256 7ef242a3b441969506939ba958a0c857d012fe5f012c4d2f31d49808133ee3e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydtmf-1.0.0.tar.gz:

Publisher: workflow.yml on Moxin1044/PyDTMF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydtmf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydtmf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydtmf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e9c264ef9213a40e0ff12587a96316866bbfca7bef63ca063fbdc011694cbf2
MD5 3629a701543ebf8f75fd2a423abdc7c2
BLAKE2b-256 bc347a181fa449d04281d4c370d1ebbcf84cb50cf165c668bbe72263a1ebf9ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydtmf-1.0.0-py3-none-any.whl:

Publisher: workflow.yml on Moxin1044/PyDTMF

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page