使用说明
语音识别MCP服务
该服务通过stdio和MCP模式提供语音识别和文本提取功能。
特性
- 文件语音识别
- 基于base64编码数据的语音识别
- 文本提取
- 支持stdio和MCP模式
- 结构化语音识别结果
- 符合AIO协议的响应
项目结构
voice_service.py-核心服务实施stdio_server.py-stdio模式入口点mcp_server.py-MCP模式入口点build.py-为可执行文件构建脚本build_exec.sh-构建执行脚本test_*.sh-不同功能的测试脚本
安装
- 克隆存储库:
git clone https://github.com/AIO-2030/mcp_voice_identify.git
cd mcp_voice_identify
- 安装依赖项:
pip install -r requirements.txt
- 在中设置环境变量
.env:
API_URL=your_api_url
API_KEY=your_api_key
用法
stdio模式
- 运行服务:
python stdio_server.py
- 通过stdin发送JSON-RPC请求:
{
"jsonrpc": "2.0",
"method": "help",
"params": {},
"id": 1
}
- 或者使用可执行文件:
./dist/voice_stdio
MCP模式
- 运行服务:
python mcp_server.py
- 或者使用可执行文件:
./dist/voice_mcp
响应格式
该服务遵循AIO协议进行响应格式化。以下是不同响应类型的示例:
语音识别响应
{
"jsonrpc": "2.0",
"output": {
"type": "voice",
"message": "Voice processed successfully",
"text": "test test test",
"metadata": {
"language": "en",
"emotion": "unknown",
"audio_type": "speech",
"speaker": "woitn",
"raw_text": "test test test"
}
},
"id": 1
}
帮助信息响应
{
"jsonrpc": "2.0",
"result": {
"type": "voice_service",
"description": "This service provides voice recognition and text extraction services",
"author": "AIO-2030",
"version": "1.0.0",
"github": "https://github.com/AIO-2030/mcp_voice_identify",
"transport": ["stdio"],
"methods": [
{
"name": "help",
"description": "Show this help information."
},
{
"name": "identify_voice",
"description": "Identify voice from file",
"inputSchema": {
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Voice file path"
}
},
"required": ["file_path"]
}
},
{
"name": "identify_voice_base64",
"description": "Identify voice from base64 encoded data",
"inputSchema": {
"type": "object",
"properties": {
"base64_data": {
"type": "string",
"description": "Base64 encoded voice data"
}
},
"required": ["base64_data"]
}
},
{
"name": "extract_text",
"description": "Extract text",
"inputSchema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Text to extract"
}
},
"required": ["text"]
}
}
]
},
"id": 1
}
错误响应
{
"jsonrpc": "2.0",
"output": {
"type": "error",
"message": "503 Server Error: Service Unavailable",
"error_code": 503
},
"id": 1
}
响应字段
该服务提供三种类型的响应:
-
语音识别响应(使用
output字段):字段 描述 示例值 type 响应类型 “语音” message 状态消息 “语音处理成功” text 识别的文本内容 “测试测试” 元数据 附加信息 见下文 -
帮助信息响应(使用
result字段):字段 描述 示例值 type 服务类型 “voice_Service” description 服务描述 “此服务提供…” 作者 服务作者 “AIO-2030” version 服务版本 “1.0.0” github github存储库URL “https://github.com/..." transport 支持的传输模式 [“stdio”] methods 可用方法 查看方法列表 -
错误响应(使用
output字段):字段 描述 示例值 type 响应类型 “错误” message 错误消息 “503服务器错误:服务不可用” error_code HTTP状态码 503
元数据字段
这 metadata 语音识别响应中的字段包含:
| 字段 | 描述 | 示例值 |
|---|---|---|
| 语言 | 语言代码 | “en” |
| 情绪 | 情绪状态 | “未知” |
| audio_type | 音频类型 | “语音” |
| 说话者 | 说话者标识符 | “woitn” |
| raw_text | 原始识别文本 | “测试测试” |
构建可执行文件
- 使构建脚本可执行:
chmod +x build_exec.sh
- 生成stdio模式可执行文件:
./build_exec.sh
- 构建MCP模式可执行文件:
./build_exec.sh mcp
可执行文件将在以下位置创建:
- stdio模式:
dist/voice_stdio - MCP模式:
dist/voice_mcp
测试
运行测试脚本:
chmod +x test_*.sh
./test_help.sh
./test_voice_file.sh
./test_voice_base64.sh
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
