Browse Source

修复翻译收外部音源问题

newdev_shunjiawei
fdp 1 year ago
parent
commit
372a5e60dd
  1. 8
      lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart
  2. 2
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleAgent.kt
  3. 1
      local_plugins/azure_speech/android/build.gradle.kts
  4. 58
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt
  5. 1
      local_plugins/ble_service/android/build.gradle.kts
  6. 8
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt
  7. 4
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleServicePlugin.kt

8
lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart

@ -73,10 +73,8 @@ class OtaUpgradeController extends GetxController {
} }
// 检查固件信息有效性 // 检查固件信息有效性
if (deviceInfo.firmwareVersion.isEmpty if (deviceInfo.firmwareVersion.isEmpty ||
//|| deviceInfo.firmwareProductId.isEmpty) {
// deviceInfo.firmwareProductId.isEmpty
) {
throw const FormatException('设备固件信息不完整'); throw const FormatException('设备固件信息不完整');
} }
@ -85,7 +83,7 @@ class OtaUpgradeController extends GetxController {
// API请求 // API请求
final response = await Api.getequipmentinfo({ final response = await Api.getequipmentinfo({
"id": "a2", "id": deviceInfo.firmwareProductId,
}); });
// 处理API响应 // 处理API响应

2
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleAgent.kt

@ -128,7 +128,7 @@ object BleAgent : BleService.Callback, AgentServiceListener {
} }
override fun onAudioDataReceived(data: ByteArray) { override fun onAudioDataReceived(data: ByteArray) {
// FileLogger.d(TAG, "onAudioDataReceived, data: ${data.size}") FileLogger.d(TAG, "onAudioDataReceived, data: ${data.size}")
AgentService.pushAudioData(data) AgentService.pushAudioData(data)
// 可选:处理音频数据 // 可选:处理音频数据
} }

1
local_plugins/azure_speech/android/build.gradle.kts

@ -53,4 +53,5 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependencies { dependencies {
// 添加Microsoft语音SDK // 添加Microsoft语音SDK
implementation("com.microsoft.cognitiveservices.speech:client-sdk:1.30.0") implementation("com.microsoft.cognitiveservices.speech:client-sdk:1.30.0")
implementation(project(":ble_service"))
} }

58
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt

@ -14,9 +14,10 @@ import io.flutter.plugin.common.EventChannel
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import com.microsoft.cognitiveservices.speech.audio.* import com.microsoft.cognitiveservices.speech.audio.*
import com.yunqiinnovation.ble_service.BleService
import com.yunqiinnovation.ble_service.BleConst
/** AzureSpeechPlugin */ /** AzureSpeechPlugin */
class AzureSpeechPlugin: FlutterPlugin, CoroutineScope { class AzureSpeechPlugin: FlutterPlugin,BleService.Callback, CoroutineScope {
private val tag = "AzureSpeechPlugin" private val tag = "AzureSpeechPlugin"
private lateinit var context: Context private lateinit var context: Context
private val mainHandler = Handler(Looper.getMainLooper()) private val mainHandler = Handler(Looper.getMainLooper())
@ -37,7 +38,10 @@ class AzureSpeechPlugin: FlutterPlugin, CoroutineScope {
private lateinit var ttsEventChannel: EventChannel private lateinit var ttsEventChannel: EventChannel
private var ttsEventSink: EventChannel.EventSink? = null private var ttsEventSink: EventChannel.EventSink? = null
private lateinit var azureTtsHelper: AzureTtsHelper private lateinit var azureTtsHelper: AzureTtsHelper
// 是否已注册BLE回调
private var isRegisteredToBle = false
// ASR 事件发送方法 // ASR 事件发送方法
private fun sendAsrEvent(event: Map<String, Any>) { private fun sendAsrEvent(event: Map<String, Any>) {
if (asrEventSink == null) { if (asrEventSink == null) {
@ -110,6 +114,19 @@ class AzureSpeechPlugin: FlutterPlugin, CoroutineScope {
// 初始化Azure语音服务 // 初始化Azure语音服务
azureTtsHelper = AzureTtsHelper(context) azureTtsHelper = AzureTtsHelper(context)
azureAsrHelper = AzureAsrHelper(context) azureAsrHelper = AzureAsrHelper(context)
// 2. 初始化BleService并注册回调
if (BleService.initialize(context)) {
if (BleService.addCallback(this)) {
isRegisteredToBle = true
FileLogger.d(tag, "已注册BLE回调")
} else {
FileLogger.w(tag, "BLE回调注册失败")
}
} else {
FileLogger.e(tag, "BLE服务初始化失败")
}
} }
// ASR方法处理器 // ASR方法处理器
@ -359,7 +376,12 @@ class AzureSpeechPlugin: FlutterPlugin, CoroutineScope {
try { try {
// 取消所有协程 // 取消所有协程
job.cancel() job.cancel()
// 取消BLE回调注册
if (isRegisteredToBle) {
BleService.removeCallback(this)
isRegisteredToBle = false
}
// 释放资源 // 释放资源
azureTtsHelper.dispose() azureTtsHelper.dispose()
azureAsrHelper.dispose() azureAsrHelper.dispose()
@ -367,4 +389,34 @@ class AzureSpeechPlugin: FlutterPlugin, CoroutineScope {
FileLogger.e(tag, "释放资源失败: ${e.message}") FileLogger.e(tag, "释放资源失败: ${e.message}")
} }
} }
override fun onScanResult(devices: List<Map<String, Any>>) {
}
override fun onConnectionStateChanged(state: Int) {
// 可选:处理连接状态变化
if (state == BleConst.STATE_CONNECTED) {
FileLogger.d(tag, "Ble设备已连接,准备好语音交互")
} else if (state == BleConst.STATE_DISCONNECTED) {
FileLogger.d(tag, "Ble设备已断开,停止语音服务")
// 设备断开连接,停止语音服务
// stopListening()
}
}
override fun onAudioDataReceived(data: ByteArray) {
FileLogger.d(tag, "AzureSpeechPlugin onAudioDataReceived, data: ${data.size}")
azureAsrHelper.pushAudioData(data)
}
override fun onWakeupSignalReceived() {
}
override fun onDeviceInfoReceived(infoType: Int, infoData: Map<String, Any>) {
}
} }

1
local_plugins/ble_service/android/build.gradle.kts

@ -31,5 +31,4 @@ dependencies {
// 使用从本地Maven仓库引用的AAR依赖 // 使用从本地Maven仓库引用的AAR依赖
implementation("com.jieli.audio:jl_audio_decode:2.0.0") implementation("com.jieli.audio:jl_audio_decode:2.0.0")
implementation(project(":deepvoice_utils")) implementation(project(":deepvoice_utils"))
implementation(project(":azure_speech"))
} }

8
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

@ -661,10 +661,10 @@ object BleService {
"rawData" to responseData "rawData" to responseData
) )
if (responseData.isNotEmpty() && responseData.size >= 2) { if (responseData.isNotEmpty()) {
val productId = "0x${(responseData[0].toInt() and 0xFF).toString(16)}${ // 转换为字符串前,确认是否是有效的ASCII字符
(responseData[1].toInt() and 0xFF).toString(16) val productId =
}" responseData.joinToString(".") { (it.toInt() and 0xFF).toString() }
resultMap["productId"] = productId resultMap["productId"] = productId
FileLogger.i(TAG, "接收到产品ID: $productId") FileLogger.i(TAG, "接收到产品ID: $productId")
} }

4
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleServicePlugin.kt

@ -185,6 +185,10 @@ class BleServicePlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
"getDeviceVersion" -> { "getDeviceVersion" -> {
val success = BleService.getDeviceVersion() val success = BleService.getDeviceVersion()
result.success(success) result.success(success)
}
"getProductId" -> {
val success = BleService.getProductId()
result.success(success)
} }
"getBatteryInfo" -> { "getBatteryInfo" -> {
val success = BleService.getBatteryInfo() val success = BleService.getBatteryInfo()

Loading…
Cancel
Save