功能: - Tauri v2 GUI 应用 - 系统托盘支持 - 日志输出到文件 - 带时间戳的版本号 - 前端资源嵌入 修复: - 前端路径使用相对路径 - 移除 devUrl 配置 - 窗口置顶设置
4.9 KiB
4.9 KiB
impress_asr_input_rust 构建指南
项目概述
本项目是一款高性能跨平台桌面语音识别输入工具,包含:
- CLI 工具 (
impress_asr): 命令行语音识别工具 - GUI 应用 (
impress_asr_gui): 基于 Tauri 的图形界面应用(需要额外依赖)
快速开始
1. 环境要求
- Rust 1.75+
- Node.js 18+ (用于前端构建)
- Git
2. 构建 CLI 版本(无系统依赖)
# 克隆仓库
cd impress_asr_input_rust
# 构建前端资源
cd web
npm install
npm run build
cd ..
# 构建 CLI 工具
cargo build --release
# 运行
./target/release/impress_asr --help
3. 构建 GUI 版本(需要系统依赖)
Linux (Ubuntu/Debian)
# 安装系统依赖
sudo apt-get update
sudo apt-get install -y \
pkg-config \
libglib2.0-dev \
libgtk-3-dev \
libwebkit2gtk-4.1-dev \
libappindicator3-dev \
librsvg2-dev \
libasound2-dev \
libssl-dev
# 构建
cargo build --release --features gui
# 运行
./target/release/impress_asr_gui
macOS
# 安装 Xcode 命令行工具
xcode-select --install
# 构建
cargo build --release --features gui
Windows
# 安装 Visual Studio Build Tools 2019+
# 确保安装 "Desktop development with C++"
# 构建
cargo build --release --features gui
下载模型
语音识别需要 ONNX 模型文件。以下是推荐的模型来源:
SenseVoice Small(推荐)
# 从 ModelScope 下载
wget -O models/sensevoice-small.onnx \
"https://modelscope.cn/api/v1/models/iic/SenseVoiceSmall/file?FilePath=model.onnx"
# 或从 HuggingFace 下载
wget -O models/sensevoice-small.onnx \
"https://huggingface.co/FunAudioLLM/SenseVoiceSmall/resolve/main/model.onnx"
FunASR Paraformer(中文优化)
wget -O models/paraformer.onnx \
"https://modelscope.cn/api/v1/models/iic/paraformer-zh/file?FilePath=model.onnx"
使用指南
CLI 工具
# 列出音频设备
./target/release/impress_asr devices
# 识别音频文件
./target/release/impress_asr recognize audio.wav
# 下载模型
./target/release/impress_asr download --name sensevoice-small
# 录制音频(需要 cpal 库支持)
./target/release/impress_asr record -o output.wav
GUI 应用
# 启动应用
./target/release/impress_asr_gui
# 或使用系统托盘
# 应用启动后会在系统托盘显示图标
# 右键点击可访问常用功能
项目结构
impress_asr_input_rust/
├── src/
│ ├── bin/
│ │ └── cli.rs # CLI 入口
│ ├── app/ # Tauri 应用层 (GUI)
│ ├── audio/ # 音频处理
│ ├── asr/ # 语音识别核心
│ ├── config/ # 配置管理
│ ├── tray/ # 系统托盘 (GUI)
│ ├── utils/ # 工具函数
│ ├── main.rs # GUI 入口
│ └── lib.rs # 库导出
├── web/ # React 前端
│ ├── src/
│ │ ├── pages/
│ │ │ ├── RecordPage.tsx
│ │ │ ├── FileConvertPage.tsx
│ │ │ └── SettingsPage.tsx
│ └── dist/ # 构建产物
├── models/ # ONNX 模型目录
└── resources/ # 资源文件
特性说明
编译特性
| 特性 | 描述 | 依赖 |
|---|---|---|
gui |
启用图形界面 | Tauri, global-hotkey, 系统库 |
onnx |
启用 ONNX 推理 | onnxruntime-ng |
默认构建
默认构建仅包含 CLI 工具,不依赖任何系统库:
cargo build --release
完整功能构建
cargo build --release --features gui,onnx
故障排除
构建错误:找不到 pkg-config
# Ubuntu/Debian
sudo apt-get install pkg-config
# macOS
brew install pkg-config
# Arch Linux
sudo pacman -S pkg-config
构建错误:ALSA 未找到
# Ubuntu/Debian
sudo apt-get install libasound2-dev
# Arch Linux
sudo pacman -S alsa-lib
运行时错误:模型文件不存在
确保模型文件已下载到正确位置:
ls -la models/sensevoice-small.onnx
# 如果不存在,下载模型
./target/release/impress_asr download
GUI 无法启动
- 确认已安装所有系统依赖
- 检查
tauri.conf.json配置 - 确保前端已构建:
cd web && npm run build
性能优化
发布构建优化
项目已配置以下优化:
[profile.release]
lto = true # 链接时优化
codegen-units = 1 # 单一代码单元,更好优化
opt-level = 3 # 最高优化级别
strip = true # 移除调试符号
模型优化
- 量化模型: 使用 INT8 量化模型可减少 50-75% 大小
- 模型选择: SenseVoice Small 在速度和精度间取得良好平衡
- GPU 加速: 启用 CUDA 或 DirectML 后端(需要
onnx特性)
许可证
MIT License