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)
工作原理
- 解析 WAV 文件头 → 提取格式信息
- 转换为单声道、去除直流偏置、归一化音量
- 重采样至 8kHz(电话标准采样率)
- 使用 Goertzel 算法测量每个 DTMF 频率的能量
- 当两个主导频率(一个行频、一个列频)超过阈值时判定为有效数字
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320916ef7f3e446b5fc043577724c49bcb52271eb1115141974a1114cfadd0df
|
|
| MD5 |
a0c686a908e98fd7c814d438259d230a
|
|
| BLAKE2b-256 |
7ef242a3b441969506939ba958a0c857d012fe5f012c4d2f31d49808133ee3e2
|
Provenance
The following attestation bundles were made for pydtmf-1.0.0.tar.gz:
Publisher:
workflow.yml on Moxin1044/PyDTMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydtmf-1.0.0.tar.gz -
Subject digest:
320916ef7f3e446b5fc043577724c49bcb52271eb1115141974a1114cfadd0df - Sigstore transparency entry: 2027721170
- Sigstore integration time:
-
Permalink:
Moxin1044/PyDTMF@33f8d43311a17a4790abf71c5a2d4e8e35a4a6ee -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@33f8d43311a17a4790abf71c5a2d4e8e35a4a6ee -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e9c264ef9213a40e0ff12587a96316866bbfca7bef63ca063fbdc011694cbf2
|
|
| MD5 |
3629a701543ebf8f75fd2a423abdc7c2
|
|
| BLAKE2b-256 |
bc347a181fa449d04281d4c370d1ebbcf84cb50cf165c668bbe72263a1ebf9ef
|
Provenance
The following attestation bundles were made for pydtmf-1.0.0-py3-none-any.whl:
Publisher:
workflow.yml on Moxin1044/PyDTMF
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydtmf-1.0.0-py3-none-any.whl -
Subject digest:
8e9c264ef9213a40e0ff12587a96316866bbfca7bef63ca063fbdc011694cbf2 - Sigstore transparency entry: 2027721593
- Sigstore integration time:
-
Permalink:
Moxin1044/PyDTMF@33f8d43311a17a4790abf71c5a2d4e8e35a4a6ee -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@33f8d43311a17a4790abf71c5a2d4e8e35a4a6ee -
Trigger Event:
push
-
Statement type: