本项目借助MCP(Multi-Channel Processing)多通道处理框架,实现了文件查找和语音转写两大实用功能。通过HTTP服务器提供REST API,用户可方便地搜索指定路径下的文件;同时利用fastspeech库,能将音频精准转换为文字并提供详细转录信息。
首先,安装项目所需的依赖:
npm install
pip install -r requirements.txt # 确保你已经创建了requirements.txt文件
编译TypeScript代码并生成JavaScript文件:
npm run build
运行src/index.ts:
ts-node src/index.ts
运行main.py:
python main.py
默认情况下,服务器将在8080端口启动。
运行src/whisper-index.ts:
ts-node src/whisper-index.ts
运行whisper_server.py:
python whisper_server.py
默认情况下,服务器将在8081端口启动。
fastspeech库将音频转换为文字,并提供详细的转录信息。npm install
pip install -r requirements.txt # 确保你已经创建了requirements.txt文件
npm run build
发送GET请求到http://localhost:8080/search?path=/target/directory以获取指定路径下的所有文件。
curl http://localhost:8080/search?path=/home/user/documents
{
"files": [
"/home/user/documents/report.pdf",
"/home/user/documents/data.csv"
],
"directories": [
"/home/user/documents/subfolder"
]
}
发送POST请求到http://localhost:8081/transcribe,并在请求体中包含音频数据。
curl -X POST http://localhost:8081/transcribe \
--header "Content-Type: application/json" \
--data '{"audio":"JVBERi0xLjUK...","language":"zh-CN"}'
{
"text": "这是一个语音转写示例。",
"segments": [
{
"start": 0.0,
"end": 2.5,
"text": "这是"
},
{
"start": 2.5,
"end": 4.0,
"text": "一个语音转写示例。"
}
],
"language": "zh-CN",
"language_probability": 0.98
}
项目的目录结构如下:
project/
├── src/
│ ├── index.ts # 文件查找的MCP服务器实现(直接实现)
│ ├── index-http.ts # HTTP服务器文件查找的MCP代理实现
│ ├── whisper-index.ts # 语音转写的MCP服务器实现(直接实现)
│ └── whisper-index-http.ts # HTTP服务器语音转写的MCP代理实现
├── build/
│ ├── index.js # 编译后的JavaScript文件,用于文件查找的MCP服务器
│ ├── index-http.js # 编译后的JavaScript文件,用于HTTP服务器文件查找的MCP代理
│ ├── whisper-index.js # 编译后的JavaScript文件,用于语音转写的MCP服务器
│ └── whisper-index-http.js # 编译后的JavaScript文件,用于HTTP服务器语音转写的MCP代理
├── tsconfig.json # TypeScript配置文件
├── package.json # 项目依赖和描述
├── main.py # Python实现的文件查找HTTP服务器
└── whisper_server.py # Python实现的语音转写HTTP服务器
fastspeech时,如果需要GPU加速,请确保安装了必要的显卡驱动和计算库(如CUDA)。你可以将项目打包为Docker镜像以便在生产环境中运行。创建一个Dockerfile如下:
FROM node:16-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install --production
FROM python:3.8-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY --from=builder /app/ .
# 设置默认Python路径
ENV PATH=/usr/local/bin:$PATH
EXPOSE 8080 8081
CMD ["python", "main.py", "--port", "8080"]
然后构建和运行镜像:
docker build -t mcp .
docker run -p 8080:8080 -p 8081:8081 mcp
确保项目的根目录下有以下文件和子目录:
project/
├── src/
│ ├── index.ts
│ └── whisper-index.ts
├── build/
│ ├── index.js
│ └── whisper-index.js
├── package.json
├── tsconfig.json
├── main.py
└── whisper_server.py
确保你已经安装了Node.js和Python的开发环境,并且安装了项目所需的依赖项。
{
"name": "mcp",
"version": "1.0.0",
"description": "Multi-Channel Processing for file search and speech transcription.",
"scripts": {
"build": "tsc -p tsconfig.json"
},
"dependencies": {
"typescript": "^4.5.2",
"fastspeech": "^0.13.0"
}
}
numpy
flask
pydub
欢迎任何贡献!请遵循以下步骤:
git checkout -b feature/your-featuregit add . && git commit -m '你的提交信息'git push origin feature/your-feature本项目使用MIT许可证,详情请参阅LICENSE文件。