语音知识库问答 Skill
本地语音知识库问答系统,支持 ASR 语音转写、向量存储、语义检索和 LLM 问答。所有推理均在本地完成,数据不出机器。
Trigger
/voice-kb
识别场景
当用户消息包含以下意图时触发本 Skill:
- 用户上传音频/视频文件并要求转写或提取内容
- 用户要求将音频/文本入库到知识库
- 用户对已入库的内容提问
- 用户要求管理知识库集合(列出、删除)
- 用户提到"语音知识库"、"音频问答"、"语音转文字"等关键词
执行流程
Step 0: 确认服务状态
在执行任何操作前,先检查服务是否已启动:
curl -s http://localhost:8000/health
如果服务未启动,提示用户启动:
服务未启动,请先启动语音知识库服务:
cd voice-kb-skill
set EMBEDDING_MODEL_PATH=<你的BGE-M3模型路径>
python voice_kb_server.py
或双击 start.bat
注意:首次请求会触发模型加载(嵌入模型 ~30s,LLM ~60s),超时属正常现象,应告知用户耐心等待。
Step 1: 转写音频
用户上传音频文件时,调用 /transcribe 端点:
curl -X POST http://localhost:8000/transcribe \
-F "file=@<音频文件路径>"
返回 JSON 包含 text 字段(转写文本)和 processing_time。
输出格式:将转写文本以清晰格式展示给用户,标注转写耗时。
Step 2: 文本入库
将文本内容存入向量数据库:
curl -X POST http://localhost:8000/ingest \
-H "Content-Type: application/json" \
-d '{"text": "<文本内容>", "collection_name": "<集合名>"}'
collection_name默认为default,用户可指定自定义名称- 返回
chunks_count(分块数)和total_docs(总文档数)
Step 3: 音频入库(转写+入库一步完成)
curl -X POST http://localhost:8000/ingest-audio \
-F "file=@<音频文件路径>" \
-F "collection_name=<集合名>"
Step 4: 知识库问答
对已入库内容提问:
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{"question": "<问题>", "collection_name": "<集合名>", "top_k": 3}'
返回 answer(LLM 生成的答案)、sources(检索到的相关片段)、processing_time。
输出格式:
- 先展示答案
- 再列出参考来源(每条来源的前 100 字)
- 标注处理耗时
Step 5: 全流程(转写+入库+问答)
curl -X POST http://localhost:8000/full-pipeline \
-F "file=@<音频文件路径>" \
-F "collection_name=<集合名>" \
-F "question=<可选问题>"
Step 6: 管理集合
列出所有集合:
curl -s http://localhost:8000/collections
删除集合:
curl -X DELETE http://localhost:8000/collections/<集合名>
环境变量配置
通过环境变量覆盖默认路径(在 .env 文件或启动前 set):
| 变量 | 默认值 | 说明 |
|------|--------|------|
| WHISPER_MODEL_PATH | ./models/OpenVINO/whisper-tiny-int4-ov | Whisper ASR 模型路径 |
| LLM_MODEL_ID | OpenVINO/Qwen3.5-4B-int4-ov | LLM 魔搭模型 ID |
| LLM_MODEL_LOCAL | ./models/OpenVINO/Qwen3___5-4B-int4-ov | LLM 本地路径 |
| EMBEDDING_MODEL_PATH | ./models/bge-m3 | BGE-M3 嵌入模型路径 |
| CHROMA_DB_PATH | ./chroma_db | ChromaDB 存储路径 |
| DEVICE | CPU | 推理设备 (CPU/GPU/NPU) |
| CHUNK_SIZE | 500 | 文本分块大小 |
| CHUNK_OVERLAP | 50 | 分块重叠字符数 |
依赖安装
使用 uv 管理依赖:
cd voice-kb-skill
pip install uv # 安装 uv(如果没有)
uv sync # 安装所有依赖到 .venv
或手动安装:
uv pip install fastapi uvicorn chromadb python-multipart
uv pip install openvino-genai modelscope librosa soundfile
uv pip install sentence-transformers FlagEmbedding
模型下载
首次运行时模型会自动从魔搭下载,也可手动预下载:
python whisper_openvino_inference.py # 下载 Whisper
# Qwen3.5 和 BGE-M3 在首次请求时自动下载
技术架构
| 组件 | 技术 | 说明 | |------|------|------| | ASR | Whisper-tiny-int4-ov | OpenVINO GenAI,~41MB | | 嵌入 | BGE-M3 | sentence-transformers,多语言 | | LLM | Qwen3.5-4B-int4-ov | OpenVINO GenAI,INT4 量化 | | 向量库 | ChromaDB | 本地持久化存储 | | 服务 | FastAPI + Uvicorn | 异步 HTTP 服务 |
注意事项
- 首次请求较慢:模型懒加载,首次 ASR ~30s,首次 LLM ~60s,后续请求正常
- LLM 思考模型:Qwen3.5 是思考模型,服务端自动剥离思考过程,只返回最终答案
- Whisper-tiny 精度:tiny 模型适合快速验证,生产环境建议使用 whisper-base 或 whisper-small
- 数据安全:所有处理在 localhost 完成,无外部网络调用
- 音频格式:支持 wav/mp3/flac/m4a 等常见格式(librosa 自动解码)
Voice Knowledge Base Skill
A local voice knowledge base Q&A skill that combines ASR (Automatic Speech Recognition), vector database storage, and LLM-powered question answering. All processing happens locally for maximum privacy and security.
Trigger
/voice-kb
Description
This skill enables users to:
- Transcribe audio/video files to text using Whisper ASR
- Store transcribed text in a local vector database (ChromaDB)
- Ask natural language questions about the stored content
- Get AI-generated answers based on semantic search results
All models run locally using OpenVINO, ensuring data privacy and zero network latency.
Usage
Start the Service
First, ensure the voice KB server is running:
# 使用 uv 启动
uv run python voice_kb_server.py
# 或直接
python voice_kb_server.py
The server runs at http://localhost:8000
Commands
1. Transcribe Audio
Convert audio/video to text:
/voice-kb transcribe <audio_file_path>
Example:
/voice-kb transcribe meeting_recording.wav
2. Ingest Text
Add text content to the knowledge base:
/voice-kb ingest <text_or_file_path> [--collection <name>]
Example:
/voice-kb ingest "人工智能正在改变我们的生活方式..." --collection tech_notes
/voice-kb ingest ./notes.txt --collection study_materials
3. Ingest Audio
Transcribe audio and automatically store in knowledge base:
/voice-kb ingest-audio <audio_file_path> [--collection <name>]
Example:
/voice-kb ingest-audio lecture.mp3 --collection lectures
4. Ask Questions
Query the knowledge base:
/voice-kb ask <question> [--collection <name>] [--top-k <n>]
Example:
/voice-kb ask "会议讨论了哪些重要议题?" --collection meetings
/voice-kb ask "What were the key decisions?" --collection meetings --top-k 5
5. Full Pipeline
One-step: transcribe audio, store in KB, and optionally answer a question:
/voice-kb pipeline <audio_file_path> [--collection <name>] [--question <q>]
Example:
/voice-kb pipeline interview.wav --collection interviews --question "受访者提到了哪些关键观点?"
6. Manage Collections
List all knowledge base collections:
/voice-kb list
Delete a collection:
/voice-kb delete <collection_name>
Implementation
The skill communicates with the local FastAPI server via HTTP requests:
- Server:
voice_kb_server.py(FastAPI + OpenVINO + ChromaDB) - ASR Model: Whisper-tiny-int4-ov (OpenVINO GenAI)
- LLM Model: Qwen3.5-4B-int4-ov (OpenVINO GenAI)
- Embedding: BGE-M3 (sentence-transformers)
- Vector DB: ChromaDB (persistent local storage)
API Endpoints
| Endpoint | Method | Description |
|----------|--------|-------------|
| /health | GET | Health check |
| /transcribe | POST | Audio to text |
| /ingest | POST | Text to KB |
| /ingest-audio | POST | Audio to KB |
| /query | POST | Q&A |
| /full-pipeline | POST | End-to-end |
| /collections | GET | List collections |
| /collections/{name} | DELETE | Delete collection |
Technical Stack
- OpenVINO GenAI: High-performance local inference on CPU/GPU/NPU
- Whisper ASR: 99-language speech recognition
- BGE-M3: State-of-the-art multilingual embeddings
- Qwen3.5: Advanced Chinese/English LLM
- ChromaDB: Local vector database with persistence
- FastAPI: Modern async HTTP server
Quick Start (uv 安装)
# 1. 安装 uv(如果还没有)
pip install uv
# 2. 安装所有依赖
uv sync
# 3. 下载模型(首次运行自动下载,或手动执行)
python whisper_openvino_inference.py # 下载 Whisper
# 4. 配置环境变量(可选,复制模板并修改路径)
copy .env.example .env
# 5. 启动服务
python voice_kb_server.py
# 或双击 start.bat
服务启动后访问 http://localhost:8000
Installation (uv)
# 使用 uv 一键安装所有依赖
uv sync
# 或手动安装
uv pip install fastapi uvicorn chromadb python-multipart
uv pip install openvino-genai modelscope librosa soundfile
uv pip install sentence-transformers FlagEmbedding
Privacy & Security
- All data processing happens on localhost
- No external network calls during inference
- Models and data never leave the user's machine
- Suitable for sensitive enterprise documents and personal data
Performance
- Whisper-tiny: ~41MB, real-time transcription
- Qwen3.5-4B: Compact yet powerful for RAG tasks
- BGE-M3: Fast multilingual embeddings
- ChromaDB: Sub-second semantic search
Error Handling
The skill handles common errors gracefully:
- Service not running: Clear instructions to start server
- Empty audio: Informative error messages
- Missing collection: Auto-create or helpful 404
- Model loading: Lazy loading with status feedback
微信扫一扫