From: liangzhenying <867174124@qq.com> Date: Sat, 31 Jan 2026 07:03:22 +0000 (+0800) Subject: 北科AI增加点击按钮打断 X-Git-Tag: 北科AI按钮打断~1 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=9630db51659a08ec592ee33ba5579fee09c65774;p=mirrors%2FShenYin.git 北科AI增加点击按钮打断 --- diff --git a/ShenYin/ShenYin/Sdk/LogManager.swift b/ShenYin/ShenYin/Sdk/LogManager.swift index 8735333..f61e054 100644 --- a/ShenYin/ShenYin/Sdk/LogManager.swift +++ b/ShenYin/ShenYin/Sdk/LogManager.swift @@ -9,7 +9,7 @@ import Foundation /// 日记管理 class Logger { - static var isDebug: Bool = true + static var isDebug: Bool = false fileprivate static let shared = Logger() private var fileHandle:FileHandle? diff --git a/ShenYin/ShenYin/UI/Raisound/MSVoiceChat.swift b/ShenYin/ShenYin/UI/Raisound/MSVoiceChat.swift index 1334588..d0cfc92 100644 --- a/ShenYin/ShenYin/UI/Raisound/MSVoiceChat.swift +++ b/ShenYin/ShenYin/UI/Raisound/MSVoiceChat.swift @@ -29,6 +29,7 @@ public class MSVoiceChat { /// 设备ID/用户ID var deviceId:String = "" + var lastEvent:MSVoiceChatEvent? /// 连接状态 @@ -204,6 +205,7 @@ extension MSVoiceChat:WebSocketDelegate{ guard let data = text.data,let model = JSON.decode(MSVoiceChatEvent.self, from: data) else{ return } + lastEvent = model if model.event == "started"{ beginSpeedch() } diff --git a/ShenYin/ShenYin/UI/Raisound/RSChatVC.swift b/ShenYin/ShenYin/UI/Raisound/RSChatVC.swift index 9f7d47d..20ffd6a 100644 --- a/ShenYin/ShenYin/UI/Raisound/RSChatVC.swift +++ b/ShenYin/ShenYin/UI/Raisound/RSChatVC.swift @@ -98,7 +98,7 @@ class RSChatVC:BaseVC{ CCAiManager.stopPlay() } else if event.event == "asr.completed"{ - + recordMamager.stop() } else if event.event == "llm.created"{ toolBar.recordBtn.state = .respose @@ -126,6 +126,10 @@ class RSChatVC:BaseVC{ else if event.event == "tts.started"{ CCAiManager.preparePlayBlueTooth() } + else if event.event == "tts.completed"{ + recordMamager.start() + toolBar.recordBtn.state = .active + } } RSManager.shared.chat.ttsCallBack = { data in PcmSound.sharedInstance().feed(data) @@ -150,13 +154,10 @@ class RSChatVC:BaseVC{ } extension RSChatVC:RSRecordBarDelegate{ - func recordBarCancel(_ toolBar: RSRecordBar) { - recordMamager.stop() - RSManager.shared.chat.cancelSpeedch() - if let item = dataList.last,item.content.isEmpty{ - dataList.removeLast() - refreshData() - } + func recordBarIntterupt(_ toolBar: RSRecordBar) { + recordMamager.start() + CCAiManager.stopPlay() + toolBar.recordBtn.state = .active } func recordBarStart(_ toolBar: RSRecordBar) { diff --git a/ShenYin/ShenYin/UI/Raisound/RSRecordBar.swift b/ShenYin/ShenYin/UI/Raisound/RSRecordBar.swift index 9f96597..c92ccae 100644 --- a/ShenYin/ShenYin/UI/Raisound/RSRecordBar.swift +++ b/ShenYin/ShenYin/UI/Raisound/RSRecordBar.swift @@ -7,12 +7,13 @@ @objc protocol RSRecordBarDelegate { func recordBarStart(_ toolBar:RSRecordBar) - func recordBarCancel(_ toolBar:RSRecordBar) + func recordBarIntterupt(_ toolBar:RSRecordBar) func recordBarStop(_ toolBar:RSRecordBar) } class RSRecordBar:BaseView{ let startBtn = CustomButton() + let interruptBtn = CustomButton() let endBtn = CustomButton() let recordBtn = RSRecordStateView() @@ -32,16 +33,27 @@ class RSRecordBar:BaseView{ v.yc.setCornerRadius(16) v.backgroundColor = .color(.cellBg) v.setTitleColor(.color(.first), for: .normal) + v.setTitleColor(.color(.secondary), for: .highlighted) v.titleLabel?.font = .bold(16) v.setTitle("结束对话".l10n, for: .normal) v.addTarget(self, action: #selector(endBtnAction), for: .touchUpInside) v.isHidden = true } + interruptBtn.do { v in + v.yc.setCornerRadius(16) + v.backgroundColor = .color(.cellBg) + v.setTitleColor(.color(.first), for: .normal) + v.setTitleColor(.color(.secondary), for: .highlighted) + v.titleLabel?.font = .bold(16) + v.setTitle("打断".l10n, for: .normal) + v.addTarget(self, action: #selector(interruptBtnAction), for: .touchUpInside) + v.isHidden = true + } recordBtn.do { v in v.isHidden = true } - addSubviews([startBtn,endBtn,recordBtn]) + addSubviews([startBtn,interruptBtn,endBtn,recordBtn]) startBtn.snp.makeConstraints { make in make.left.right.equalToSuperview().inset(18) @@ -52,9 +64,14 @@ class RSRecordBar:BaseView{ make.width.equalTo(100) make.top.height.equalToSuperview() } + interruptBtn.snp.makeConstraints { make in + make.right.equalTo(endBtn.snp.left).offset(-10) + make.width.equalTo(100) + make.top.height.equalToSuperview() + } recordBtn.snp.makeConstraints { make in make.left.equalToSuperview().inset(18) - make.right.equalTo(endBtn.snp.left).offset(-10) + make.right.equalTo(interruptBtn.snp.left).offset(-10) make.top.height.equalToSuperview() } NotificationManager.add(self, selector: #selector(deviceChange(_:)), forName: .deviceValidChange) @@ -66,6 +83,7 @@ class RSRecordBar:BaseView{ } startBtn.isHidden = true endBtn.isHidden = false + interruptBtn.isHidden = false recordBtn.isHidden = false recordBtn.state = .active delegate?.recordBarStart(self) @@ -73,9 +91,13 @@ class RSRecordBar:BaseView{ @objc func endBtnAction(){ startBtn.isHidden = false endBtn.isHidden = true + interruptBtn.isHidden = true recordBtn.isHidden = true delegate?.recordBarStop(self) } + @objc func interruptBtnAction(){ + delegate?.recordBarIntterupt(self) + } @objc func deviceChange(_ noti:Notification){ updateState() } diff --git a/ShenYin/ShenYin/UI/Raisound/RSRoleVC.swift b/ShenYin/ShenYin/UI/Raisound/RSRoleVC.swift index 5c2d3d4..3e5506d 100644 --- a/ShenYin/ShenYin/UI/Raisound/RSRoleVC.swift +++ b/ShenYin/ShenYin/UI/Raisound/RSRoleVC.swift @@ -17,7 +17,7 @@ class RSRoleVC: BaseVC{ // Do any additional setup after loading the view. } override func setupViews() { - self.navBar.title = "音色".l10n + self.navBar.title = "角色".l10n tableView.do { v in v.backgroundColor = .color(.bgColor)