guoyu/语音识别问题解决方案.md
2025-12-06 20:11:36 +08:00

78 lines
2.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 语音识别问题解决方案
## 问题描述
```
找不到名称"vosk"
uts插件[xwq-speech-to-text]编译失败,无法使用
uni_module [xwq-speech-to-text] (Android) 存在三方依赖或资源引用
```
## 根本原因
1. UTS 插件需要编译成原生代码才能运行
2. Vosk 是第三方依赖库,本地编译环境找不到
3. **必须使用云端打包**,让云端服务器处理依赖
## 解决方案3步
### 1⃣ 修复代码(已完成)
✅ 已修复 `interface.uts` 类型定义问题
- 文件:`fronted_uniapp/uni_modules/xwq-speech-to-text/utssdk/interface.uts`
- 添加了 `errorMsg` 字段到 `ResultData` 类型
### 2⃣ 云端制作自定义基座(需要您操作)⭐ 关键步骤
在 HBuilderX 中:
```
发行 → 原生App-云打包
```
-**勾选 "打包为自定义调试基座"**(重要!)
- 选择 Android 平台
- 证书可用 DCloud 公共证书
- 等待 5-10 分钟
- 下载并安装生成的 APK 到手机
然后配置运行方式:
```
运行 → 运行到手机或模拟器 → 运行配置
→ 选择 "自定义调试基座"
```
### 3⃣ 准备模型文件
- 下载https://alphacephei.com/vosk/models
- 推荐:`vosk-model-small-cn-0.22.zip`
- 放到:`fronted_uniapp/static/` 目录
## 详细文档
- 🎯 [【操作指南】云端打包自定义基座](fronted_uniapp/【操作指南】云端打包自定义基座.md) ⭐ **推荐阅读**
- 📖 [语音识别插件编译说明](fronted_uniapp/语音识别插件编译说明.md)
- 🔍 [检查语音识别插件状态](fronted_uniapp/检查语音识别插件状态.md)
- ⚙️ [配置本地Android编译环境](fronted_uniapp/配置本地Android编译环境.md)
## 快速检查清单
- [x] 代码修复完成
- [ ] **云端打包**自定义调试基座(勾选"打包为自定义调试基座"
- [ ] 安装基座到手机
- [ ] 配置 HBuilderX 使用"自定义调试基座"运行
- [ ] 下载模型文件到 static 目录
- [ ] 测试功能
## 关键要点
### ❌ 错误做法
- 使用标准基座运行
- 尝试本地编译(会报"找不到名称vosk"
- 使用 `发行 → 原生App-制作自定义调试基座`(本地编译)
### ✅ 正确做法
- 使用 `发行 → 原生App-云打包` + 勾选"打包为自定义调试基座"
- 让云端服务器处理 Vosk 依赖
- 配置 HBuilderX 使用自定义基座运行
## 为什么必须云端打包?
```
UTS 插件 + 第三方依赖Vosk
本地编译 ❌ 找不到 org.vosk 包
云端编译 ✅ 自动下载和编译所有依赖
```