Skip to main content

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。

Metadata

Release files for PyDTMF 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyDTMF 1.0.0
File Size Uploaded Provenance Actions
pydtmf-1.0.0.tar.gz 8.1 kB With provenance Details for pydtmf-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyDTMF 1.0.0
File Interpreter ABI Platform Actions
pydtmf-1.0.0-py3-none-any.whl Python 3 none any Details for pydtmf-1.0.0-py3-none-any.whl

Total release size: 15.7 kB

Release files / pydtmf-1.0.0.tar.gz

Download URL pydtmf-1.0.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
320916ef7f3e446b5fc043577724c49bcb52271eb1115141974a1114cfadd0df
BLAKE2b-256 checksum
How to use checksums
7ef242a3b441969506939ba958a0c857d012fe5f012c4d2f31d49808133ee3e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.

Transparency log

Release files / pydtmf-1.0.0-py3-none-any.whl

Download URL pydtmf-1.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e9c264ef9213a40e0ff12587a96316866bbfca7bef63ca063fbdc011694cbf2
BLAKE2b-256 checksum
How to use checksums
bc347a181fa449d04281d4c370d1ebbcf84cb50cf165c668bbe72263a1ebf9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.

Transparency log

Security for PyDTMF 1.0.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydtmf-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

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