Rdzleo 128f7ca02e init: KWS 软件唤醒 APK 工程骨架(基于 sherpa-onnx 改造)
工程结构:
- com.lila.wakeup 包名,基于 sherpa-onnx v1.13.0 SherpaOnnxKws demo 改造
- 9 个 Kotlin 模块: WakeupForegroundService / KwsStateMachine / AudioCapture
  / KwsEngine / BootReceiver / ProtocolReceiver / BroadcastSender / Config
  / MainActivity
- 5 个 Lila 中文唤醒词(你好Lila/hello Lila/Lila同学/Lila你好/小Lila)
- 仅 arm64-v8a(OrangePi CM5 / RK3588)
- 协议 v2.1: 双向 setPackage / silence_ms 3000 / 2min 兜底
- 数字人 APP 包名: com.qy.lila

构建通过项:
- Gradle Sync OK(腾讯云 Gradle 镜像 + 阿里云 Maven 镜像)
- APK 编译成功 55MB,含 25MB onnxruntime + 24MB 模型 + 9 个 Kotlin .dex
- adb install OK,Service onCreate 被调用,sherpa-onnx 加载模型

已知问题(下一 commit 修复):
- KwsEngine.kt 的 OnlineModelConfig modelType 设为 'zipformer'
  实际应为 'zipformer2',native 加载在 InitEncoder 后崩溃
- 修复方法: 用 sherpa-onnx 官方 getKwsModelConfig(0) 工厂函数

参考文档:
- 协议: ~/OrangePi_CM5_Project/docs/.../KWS唤醒协议-V2.md (v2.1)
- 设计: ~/OrangePi_CM5_Project/docs/.../KWS服务设计.md
- 评估: ~/OrangePi_CM5_Project/docs/.../KWS唤醒方案适配评估_Unity.md
2026-04-30 09:55:49 +08:00

51 lines
1.6 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

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.

package com.lila.wakeup
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
/**
* 开机自启接收器。
*
* 监听 BOOT_COMPLETED / LOCKED_BOOT_COMPLETED / QUICKBOOT_POWERON 三种开机广播,
* 收到后启动 [WakeupForegroundService] 进入监听状态。
*
* Android 限制:
* - 普通 APK 必须用户手动启动过一次 APP 后BootReceiver 才会生效(系统安全限制)。
* - 升级到方案 B系统签名 + /system/priv-app/)后此限制取消。
*/
class BootReceiver : BroadcastReceiver() {
companion object {
private const val TAG = "KwsService.Boot"
}
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
Log.i(TAG, "Received boot broadcast: $action")
when (action) {
Intent.ACTION_BOOT_COMPLETED,
Intent.ACTION_LOCKED_BOOT_COMPLETED,
"android.intent.action.QUICKBOOT_POWERON" -> {
startWakeupService(context)
}
else -> {
Log.w(TAG, "Ignored unknown action: $action")
}
}
}
private fun startWakeupService(context: Context) {
val serviceIntent = Intent(context, WakeupForegroundService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
}
Log.i(TAG, "WakeupForegroundService started after boot")
}
}