Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

newdev_shunjiawei
tanlongsheng 10 months ago
parent
commit
a06d3e059c
  1. 2
      android/app/src/main/AndroidManifest.xml
  2. 5
      lib/modules/agent/views/message_bubble.dart
  3. 56
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  4. 4
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt

2
android/app/src/main/AndroidManifest.xml

@ -41,7 +41,7 @@
<!-- 添加悬浮窗权限,可能有助于解决前台服务启动问题 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- 添加发送短信权限 -->
<uses-permission android:name="android.permission.SEND_SMS" />
<!-- <uses-permission android:name="android.permission.SEND_SMS" /> -->
<!-- 添加读取联系人权限 -->
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!-- 添加拨打电话权限 -->

5
lib/modules/agent/views/message_bubble.dart

@ -166,6 +166,7 @@ class MessageBubble extends GetView<AgentController> {
// 如果是识别中的消息,添加特殊样式
if (isRecognizing) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
@ -177,7 +178,9 @@ class MessageBubble extends GetView<AgentController> {
fontSize: 14,
height: 1.4,
),
overflow: TextOverflow.ellipsis,
// 允许自动换行,不再强制单行
softWrap: true,
maxLines: null,
),
),
const SizedBox(width: 8),

56
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -149,6 +149,8 @@ object AgentService : CoroutineScope {
private var isplaymusic = false;
//是否保留最终结果
private var isKeepResult = true;
// 识别结果
private var recognitionResult = ""
// 打断防抖相关
private var lastInterruptTime = 0L
@ -666,20 +668,33 @@ object AgentService : CoroutineScope {
val success = azureAsrHelper?.setupEventListeners(object :
AzureAsrHelper.ContinuousRecognizeCallback {
override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) {
Log.d(TAG, "liwei-------- onRecognizing: $sessionid")
if (recognizing.isNotEmpty()&&isKeepResult==true) {
// 检测到语音,更新状态
_hasSpeechDetected.set(true)
Log.d(TAG, "ai识别中重置定时器")
restartIdleCheck()
var text = ""
if (currentRecognitionMode == "push_to_talk") {
text = recognitionResult + recognizing
sendEvent(
"recognizing", mapOf(
"sessionid" to currsessionId,
"text" to text,
"language" to detectedLanguage
)
)
}else{
text = recognizing
sendEvent(
"recognizing", mapOf(
"sessionid" to sessionid,
"text" to recognizing,
"text" to text,
"language" to detectedLanguage
)
)
}
// 如果TTS正在播放或AI正在生成,检查是否需要打断
if (isTtsSpeaking || isAiStreaming) {
@ -709,7 +724,12 @@ object AgentService : CoroutineScope {
}
override fun onResult(sessionid:String,result: String, detectedLanguage: String) {
Log.d(TAG, "liwei-------- onResult: $sessionid ")
if (result.isNotEmpty()&&isKeepResult==true) {//加入是否结束要输出最后的结果判读
// 保存识别结果
if (currentRecognitionMode == "push_to_talk") { //按住说话
recognitionResult += result
}else{
sendEvent(
"recognition_result", mapOf(
"sessionid" to sessionid,
@ -717,10 +737,9 @@ object AgentService : CoroutineScope {
"language" to detectedLanguage
)
)
processWithChatApi(sessionid,result)
}
}
_hasSpeechDetected.set(false)
@ -729,25 +748,43 @@ object AgentService : CoroutineScope {
}
override fun onSessionStarted(sessionid:String) {
Log.d(TAG, "liwei-------- onSessionStarted: $sessionid")
sendEvent("recognition_started", mapOf("sessionid" to sessionid, "status" to "started"))
// 使用模式感知的空闲检测启动方法
recognitionResult = ""
currsessionId = sessionid
audioPlayer?.playAudio(R.raw.start)
}
override fun onSessionStopped(sessionid:String) {
Log.d(TAG, "liwei-------- onSessionStopped: $sessionid")
if (currentRecognitionMode == "push_to_talk") { //按住说话
if (recognitionResult.isNotEmpty()){
sendEvent(
"recognition_result", mapOf(
"sessionid" to currsessionId,
"text" to recognitionResult
)
)
processWithChatApi(currsessionId,recognitionResult)
}
sendEvent("recognition_stopped", mapOf("sessionid" to currsessionId, "status" to "stopped"))
}else{
sendEvent("recognition_stopped", mapOf("sessionid" to sessionid, "status" to "stopped"))
_isRecognitionActive.set(false)
stopIdleCheck()
audioPlayer?.playAudio(R.raw.stop)
}
stopIdleCheck()
_isRecognitionActive.set(false)
}
override fun onCanceled(sessionid: String,reason: String, errorDetails: String) {
Log.d(TAG, "liwei-------- onCanceled: $sessionid $reason $errorDetails")
_isRecognitionActive.set(false)
stopIdleCheck()
Log.d(TAG, "recognition_canceled:")
BleService.closeCodec()
sendEvent(
"recognition_canceled", mapOf(
@ -759,6 +796,7 @@ object AgentService : CoroutineScope {
}
override fun onError(sessionid:String, code: Int, error: String) {
Log.d(TAG, "liwei-------- onError: $sessionid $code $error")
_isRecognitionActive.set(false)
stopIdleCheck()
BleService.closeCodec()

4
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt

@ -421,10 +421,10 @@ class AzureAsrHelper(private val context: Context) {
EventHandler<SessionEventArgs> { _, _ ->
// 直接在当前线程调用回调
Log.d(tag, "会话结束事件")
if (audioSourceType == AudioSourceType.EXTERNAL) {
// if (audioSourceType == AudioSourceType.EXTERNAL) {
callback.onSessionStopped(currsessionid)
audioStream?.isContinuousRecognitionActive = false
}
// }
}
)

Loading…
Cancel
Save