使用说明
MCP音频服务器
用于音频处理和和弦分析的模型上下文协议(MCP)服务器。
快速开始
使用Docker Compose进行最快的设置:
# Clone the repository
git clone https://github.com/yourusername/mcp-audio-server.git
cd mcp-audio-server
# Start the server
docker compose up -d
样品申请
# Analyze a WAV file
curl -X POST http://localhost:8000/analyze_chords \
-H "Content-Type: application/json" \
-d '{
"audio_data": "'$(base64 -i tests/fixtures/tempo/120bpm_with_chord.wav)'",
"format": "wav",
"options": {"model": "basic"}
}'
示例响应:
{
"schema_version": "1.0.0",
"key": "C",
"tempo": 120.5,
"chords": [
{
"time": 0.0,
"label": "C",
"confidence": 0.92
},
{
"time": 1.0,
"label": "G",
"confidence": 0.87
}
],
"duration": 4.0,
"processing_info": {
"sample_rate": 44100,
"channels": 1,
"processing_time": 0.245,
"model_used": "basic"
},
"correlation_id": "550e8400-e29b-41d4-a716-446655440000"
}
特性
- 使用FFmpeg对音频文件进行解码和归一化
- 音乐分析功能:
- 速度检测(BPM)
- 密钥检测
- 弦分析和跟踪
- 具有结构化响应的RESTful API
- 输入和输出的JSON模式验证
- 使用描述性消息进行稳健的错误处理
- 具有并发控制的资源管理
- 缓存以优化性能
- 结构化日志和指标的可观察性
- 全面的测试套件
- 使用Docker进行容器化部署
安装
Docker(推荐)
docker compose up -d
手动安装
-
先决条件:
- Python 3.10或更高版本
- 转码
- 诗歌
-
安装依赖项:
poetry install -
运行服务器:
poetry run uvicorn mcp_audio_server.main:app --host 0.0.0.0 --port 8000
API文档
完整的OpenAPI规范可在 /docs 当服务器正在运行时:
http://localhost:8000/docs
端点
| 端点 | 描述 |
|---|---|
POST /analyze_chords |
分析音频的和弦、键和节奏 |
GET /health |
健康检查端点 |
GET /ready |
负载平衡器的准备情况检查 |
GET /metrics |
Prometheus指标(重定向到指标服务器) |
请求格式
{
"audio_data": "base64-encoded-audio-data",
"format": "wav", // "wav", "mp3", "ogg", "m4a", "flac"
"options": {
"model": "basic" // "basic" or "advanced"
}
}
响应格式
{
"schema_version": "1.0.0",
"key": "C",
"tempo": 120.0,
"chords": [
{
"time": 0.0,
"label": "C",
"confidence": 0.9
}
],
"duration": 4.0,
"processing_info": {
"sample_rate": 44100,
"channels": 1,
"processing_time": 0.245,
"model_used": "basic"
},
"correlation_id": "550e8400-e29b-41d4-a716-446655440000"
}
错误响应
{
"error_code": "DECODING_ERROR",
"message": "Failed to decode audio file: Invalid file format",
"details": {
"format": "wav",
"error": "Invalid WAV header"
},
"correlation_id": "550e8400-e29b-41d4-a716-446655440000"
}
发展
看 贡献.md 发展指南。
测试
# Run all tests with coverage reporting
pytest
# Run specific tests
pytest tests/analysis/test_tempo.py
文档
API文档由FastAPI应用程序生成,可在 /docs.
要重建文档站点,请执行以下操作:
# Install documentation dependencies
poetry install --with docs
# Build documentation
poetry run mkdocs build
# Serve documentation locally
poetry run mkdocs serve
许可证和合规性
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
依赖项
所有依赖关系都记录在 依赖者.md 持有各自的许可证。
更新日志
看 更改日志.md 查看项目的版本历史和更改。