音频智能多通道处理器(或音频智能控制模块,具体翻译取决于上下文和具体应用)
🎧 一个基于MCP(模型上下文协议)的音频处理服务器。它提供了用于转录、特征分析、分类、元数据提取和格式转换的工具。
目录
- 安装
- 跑步
- 工具
- 示例用法
- 输出和目录结构
- 注意事项和提示
安装
- 应安装 Python 3.10+ 和(可选)支持 CUDA 的 PyTorch。
- 安装依赖项:
pip install -r requirements.txt- pydub 需要 FFmpeg。请确保您的系统上已安装 FFmpeg 并将其添加到 PATH 中。
- Windows: choco install ffmpeg 或者 winget install Gyan.FFmpeg - macOS: brew install ffmpeg - Linux: sudo apt-get install ffmpeg
跑步
通过标准输入输出启动MCP服务器
服务器运行于 stdio 通过传输,并由MCP客户端启动。对于直接测试:
python main.py在这种模式下,如果没有MCP客户端,它将不会产生有意义的输出;典型的使用方式是通过客户端进行。
示例客户端(LangGraph + Gemini)
try.py 推出/启动了 main.py MCP服务器已关闭/结束 stdio发现工具,并将其连接到一个ReAct代理中:
python try.py默认示例使用以下文件发送转录请求: audio/。
工具
服务器名称: CustomAudioMCP
所有工具均可接受文件路径列表。无效路径或不支持的格式将返回错误。支持的格式: .wav, .mp3, .ogg, .flac。
转录本(或:文字记录、文字稿)
- 目的:将音频文件转换为文本(使用Whisper基础模型)。
- 输入:
- file_paths: List[str] - language: str = "en" - output_dir: str = "output" - overwrite: bool = False
- 输出:
- { "transcripts": { " ": { "transcription": str, "transcript_file": str } | { "error": str } } }
- 注:以16kHz的采样率处理并输出结果
output/transcripts/。
特征分析
- 目的:提取基本特征,如音高、节奏、时长;生成波形PNG图像。
- 输入:
- file_paths: List[str] - output_dir: str = "output" - overwrite: bool = False
- 输出:
- { "analyses": { " ": { "features": { "mean_pitch": float, "tempo": float, "duration_s": float }, "waveform_plot": str } | { "error": str } } }
- 注:波形图已保存至
output/waveforms/。
音频分类
- 目的:对音频内容进行分类(使用在AudioSet上微调的AST模型)。
- 输入:
- file_paths: List[str] - output_dir: str = "output" - output_csv: Optional[str] = None - overwrite: bool = False
- 输出:
- { "classifications": { " ": { "label": str, "confidence": float } | { "error": str }, "csv_path"?: str, "csv_error"?: str } }
- 注:可选地将CSV写入
output/classifications/。
元数据提取
- 目的:提取诸如时长、采样率、声道数和标签等元数据;并将其保存为JSON格式。
- 输入:
- file_paths: List[str] - output_dir: str = "output" - overwrite: bool = False
- 输出:
- { "metadata": { " ": { "metadata": { "duration_ms": int, "bitrate": int, "channels": int, "tags": object }, "metadata_file": str } | { "error": str } } }
- 注:JSON 文件保存在
output/metadata/。
音频转换
- 目的:将文件转换为目标音频格式。
- 输入:
- file_paths: List[str] - target_format: str = "wav" - output_dir: str = "output" - overwrite: bool = False
- 输出:
- { "converted_files": { " ": { "converted_file": str } | { "error": str } } }
- 注:输出结果写在下方
output/converted/。
示例用法
以下示例代表MCP客户端会将其转换为工具调用的伪输入:
{
"tool": "transcript",
"args": { "file_paths": ["audio/speech-94649.wav"], "language": "en" }
}{
"tool": "feature_analysis",
"args": { "file_paths": ["audio/speech-94649.wav"] }
}{
"tool": "audio_classification",
"args": { "file_paths": ["audio/speech-94649.wav"], "output_csv": "labels.csv" }
}{
"tool": "metadata_extraction",
"args": { "file_paths": ["audio/speech-94649.wav"] }
}{
"tool": "audio_conversion",
"args": { "file_paths": ["audio/speech-94649.wav"], "target_format": "mp3" }
}输出和目录结构
output/
- transcripts/: *_transcript_.txt - waveforms/: *_waveform_.png - classifications/: labels.csv (可选) - metadata/: *_metadata_.json - converted/: *_converted_.
注意事项和提示
- 如果可用GPU,
cuda将自动使用;否则cpu。 - 首次运行可能会因为模型下载而耗时较长。
- 如果一个
config.json如果文件存在,它会更新默认设置,例如output_dir,sample_rate,和overwrite_files。 - 工具会为不支持的格式或不存在的路径返回错误信息。
即将推出的特性/功能
| 🧩(拼图块) 工具名称 🎯 目的 | 🧾(一个带有票据或收据符号的emoji,可直译为“票据/收据符号”或根据上下文具体含义翻译) 描述 | |
|---|---|---|
| 降噪 | 噪音消除 | 使用过滤器消除背景噪音 noisereduce 或者 torchaudio。 |
| 静音检测 | 沉默检测 | 检测音频中的静音段,以便自动修剪或分割。 |
| 说话人区分(或说话人分割) | 说话人日记化(或说话人分割) | 利用……区分谁在说话 pyannote.audio 或者 resemblyzer。 |
| 情绪识别 | 情感识别 | 使用梅尔频谱图(MelSpectrogram)+ 卷积神经网络(CNN)/变换器(Transformer)来预测“快乐”或“悲伤”等情感。 |
| 自动编辑 | 智能音频编辑 | 自动去除静音、降低噪音并均衡音量(流水线式处理)。 |
| 语音相似度 | 语音相似度 | 判断两个语音样本是否属于同一说话者。 |
| 关键词识别 | 关键词识别 | 在音频中检测特定关键词(例如,“嘿,助手”)。 |
