|
|
|
@ -98,7 +98,8 @@ class AgentServiceImpl: NSObject { |
|
|
|
var micCapture: MicrophoneCapture! |
|
|
|
// 语音识别模式 |
|
|
|
public var currentRecognitionMode: String = "normal" |
|
|
|
|
|
|
|
// 识别结果 |
|
|
|
private var recognitionResult = "" |
|
|
|
internal var audioPlayer: AudioPlayer? |
|
|
|
// private var locationInfo:[String: String]? |
|
|
|
|
|
|
|
@ -2178,13 +2179,16 @@ class AudioPlayer { |
|
|
|
extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
|
func onResult(sessionid:String ,_ text: String, _ detectedLanguage: String) { |
|
|
|
if !text.isEmpty && isKeepResult { |
|
|
|
var data: [String: Any] = ["sessionid":sessionid,"text": text] |
|
|
|
if !detectedLanguage.isEmpty { |
|
|
|
data["language"] = detectedLanguage |
|
|
|
if (currentRecognitionMode == "push_to_talk") { //按住说话 |
|
|
|
recognitionResult += text |
|
|
|
}else{ |
|
|
|
var data: [String: Any] = ["sessionid":sessionid,"text": text] |
|
|
|
if !detectedLanguage.isEmpty { |
|
|
|
data["language"] = detectedLanguage |
|
|
|
} |
|
|
|
sendEvent(name: "recognition_result", data: data) |
|
|
|
processTextInput(sessionid: sessionid,text, speakResponse: true) |
|
|
|
} |
|
|
|
sendEvent(name: "recognition_result", data: data) |
|
|
|
|
|
|
|
processTextInput(sessionid: sessionid,text, speakResponse: true) |
|
|
|
} |
|
|
|
|
|
|
|
let previousHasSpeech = hasSpeechDetected |
|
|
|
@ -2204,12 +2208,20 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
|
print("onRecognizing restartIdleCheck") |
|
|
|
restartIdleCheck() |
|
|
|
} |
|
|
|
|
|
|
|
var data: [String: Any] = ["sessionid":sessionid,"text": recognizing] |
|
|
|
if !detectedLanguage.isEmpty { |
|
|
|
data["language"] = detectedLanguage |
|
|
|
if (currentRecognitionMode == "push_to_talk") { //按住说话 |
|
|
|
var data: [String: Any] = ["sessionid":currsessionId,"text": recognitionResult+recognizing] |
|
|
|
if !detectedLanguage.isEmpty { |
|
|
|
data["language"] = detectedLanguage |
|
|
|
} |
|
|
|
sendEvent(name: "recognizing", data: data) |
|
|
|
}else{ |
|
|
|
var data: [String: Any] = ["sessionid":sessionid,"text": recognizing] |
|
|
|
if !detectedLanguage.isEmpty { |
|
|
|
data["language"] = detectedLanguage |
|
|
|
} |
|
|
|
sendEvent(name: "recognizing", data: data) |
|
|
|
} |
|
|
|
sendEvent(name: "recognizing", data: data) |
|
|
|
|
|
|
|
|
|
|
|
if isSpeaking || isAiStreaming { |
|
|
|
interruptCurrentResponse() |
|
|
|
@ -2219,6 +2231,8 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
|
|
|
|
|
func onSessionStarted(sessionid:String) { |
|
|
|
sendEvent(name: "recognition_started", data: ["sessionid":sessionid,"status": "started"]) |
|
|
|
recognitionResult = "" |
|
|
|
currsessionId = sessionid |
|
|
|
isRecognizing = true |
|
|
|
hasSpeechDetected = false |
|
|
|
// 新增:会话真正启动,复位"启动中"状态 |
|
|
|
@ -2239,13 +2253,25 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
|
} |
|
|
|
|
|
|
|
func onSessionStopped(sessionid:String) { |
|
|
|
sendEvent(name: "recognition_stopped", data: ["sessionid":sessionid,"status": "stopped"]) |
|
|
|
isRecognizing = false |
|
|
|
hasSpeechDetected = false |
|
|
|
stopIdleCheck() |
|
|
|
if (currentRecognitionMode == "ble_wakeup") { |
|
|
|
audioPlayer?.playStopSound() |
|
|
|
if (currentRecognitionMode == "push_to_talk") { //按住说话 |
|
|
|
if (!recognitionResult.isEmpty){ |
|
|
|
var data: [String: Any] = ["sessionid":currsessionId,"text": recognitionResult] |
|
|
|
sendEvent(name: "recognition_result", data: data) |
|
|
|
processTextInput(sessionid: currsessionId, recognitionResult, speakResponse: true) |
|
|
|
} |
|
|
|
sendEvent(name: "recognition_stopped", data: ["sessionid":currsessionId,"status": "stopped"]) |
|
|
|
}else{ |
|
|
|
sendEvent(name: "recognition_stopped", data: ["sessionid":sessionid,"status": "stopped"]) |
|
|
|
isRecognizing = false |
|
|
|
hasSpeechDetected = false |
|
|
|
stopIdleCheck() |
|
|
|
if (currentRecognitionMode == "ble_wakeup") { |
|
|
|
audioPlayer?.playStopSound() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func onCanceled(sessionid:String ,_ reason: String, _ errorDetails: String) { |
|
|
|
|