+++ /dev/null
-//
-// Client.swift
-// Magpie
-//
-// Created by incar on 2024/1/9.
-//
-
-//import Foundation
-//import Moya
-//import HandyJSON
-//import DeviceKit
-//// 相关api
-//enum CommomApi
-//{
-// case sms(phone:String,type:SmsType)
-// case countryList
-// case list(pageNO: Int = 1, pageSize: Int = 10)
-// case register(param:[String:Any])
-// case login(phone:String,code:String)
-//}
-//
-//// 实现TargetType协议
-//extension CommomApi: TargetType
-//{
-// // url
-// var baseURL: URL
-// {
-//// return URL(string: "https://app-api.raisound.com")!
-//// http://118.145.178.188:32000/uc/country/list
-//// return URL(string: "https://app-api.deepchords.com")!
-// return URL(string: "http://118.145.178.188:32000")!
-// }
-//
-// /// 请求路径
-// var path: String {
-// switch self {
-// case .sms(_,_):
-// return "/uc/sms"
-// case .countryList:
-// return "/uc/country/list"
-// case .list:
-// return "list"
-// case .register( let param):
-// return "/uc/sign-up?smsCode=\(param["smsCode"]!)"
-// case .login(_,_):
-// return "/uc/phone/reg-login"
-// }
-// }
-//
-// /// 请求方式
-// var method: Moya.Method {
-// switch self {
-// case .sms(_,_):
-// return .get
-// case .register(_):
-// return .post
-// case .login(_,_):
-// return .post
-// default:
-// return .get
-// }
-// }
-//
-// /// 解析格式
-// var sampleData: Data {
-// return "{}".data(using: String.Encoding.utf8)!
-// }
-////https://sz.58.com/esf-ajax/activity/ashen_switch/?city_id=4
-//// let idfv = UIDevice.current.identifierForVendor?.uuidString
-// var task: Task {
-// // 公共参数
-//// var params: [String: Any] = ["token": "Gz1qYLXeBW8MZuUfDlr9wsAYuVS1cZFMJY9BbaF842L2gRps747o4w=="]
-// var params: [String: Any] = [:]
-//
-// // 收集参数
-// switch self {
-// case let .sms(phone, type):
-// params["phone"] = phone
-// params["type"] = type
-// case let .list(pageNO, pageSize):
-// params["pageNO"] = pageNO
-// params["pageSize"] = pageSize
-// case let .register(para):
-// params += para
-// case let .login(phone,code):
-// params["phone"] = phone
-// params["smsCode"] = code
-// break
-// default:
-// break
-// }
-// return .requestParameters(parameters: params, encoding: URLEncoding.default)
-// }
-//
-// /// 公共请求头
-// var headers: [String : String]? {
-// return [
-// "devtype": "iOS",
-// "devid": UIDevice().identifierForVendor?.uuidString ?? "unknow",
-//// "Content - Type": "application/json"
-// ]
-// }
-//
-//
-////https://gz.fang.anjuke.com/xinfang/harmony/adviser/adviser/getMainAdviserBlock?client_source=3&limit=100&target_id=523085&target_type=1&adviser_id=&adviser_type=1&loupan_id=523085&layout_id=&page_source=2
-//}
-//
-//class HttpClient{
-// static let instance = HttpClient()
-// let provider = MoyaProvider<CommomApi>()
-//
-// func request<T: HandyJSON>(_ target: CommomApi,completionHandler:@escaping ((T, String) -> Void)){
-// provider.request(target){ (response) in
-// Logger.debug("url = \(target.baseURL.absoluteString + target.path)")
-// Logger.debug("param = \(target.task)")
-//
-//
-// switch response {
-// case .success(let value):
-// let data = value.data
-//// print("reponse data=>",data.hexEncodedString())
-// var responseStr = "response转字符串失败"
-// if let str = String(data: data, encoding: .utf8) {
-// responseStr = str
-// }
-// Logger.debug("reponse text=>",responseStr)
-// if let res = T.deserialize(from: responseStr){
-// completionHandler(res,responseStr)
-// return
-// }
-// completionHandler(T(),"解析请求失败")
-// break
-// case .failure(let error):
-// completionHandler(T(),"请求失败".l10n)
-// Logger.debug("***************\n网络连接失败!\n\(error)\n********************")
-// }
-// }
-// }
-//
-//}
import UIKit
import CoreBluetooth
import AVFAudio
+
+//#if FEATURE_X
import DeepChordsSdk
+//#endif
+
class DCPeripheral{
var device:CBPeripheral!
}
extension JoyChat : JoyGemChatManagerDelegate {
-
func chatManager(_ manager: JoyGemChatManager, audioData data: Data?, index: UInt, sampleRate: UInt, finish isFinish: Bool) {
PcmSound.sharedInstance().delegate = self
if (!isTtsPlaying) {
isTtsPlaying = true
Logger.debug("开始播放")
JoyGemChatManager.shared().playAudioStart()
+ App.shared.preparePlay()
}
Logger.debug("收到音频数据", data?.count ?? 0)
PcmSound.sharedInstance().feed(data)
case .startRecord:
if (isTtsPlaying) {
isTtsPlaying = false
- PcmSound.sharedInstance().cleanup()
- PcmSound.sharedInstance().setup(16000, withchannels: 1)
-
- var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
- // if App.shared.isInBackground{
- // options = [.mixWithOthers]
- // }
-
-
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
- try AVAudioSession.sharedInstance().setActive(true)
- } catch {
- Logger.debug(error)
- }
+ App.shared.preparePlay()
}
break
case .stopRecord:
callRecord = JoyCallRecord()
chat = JoyChat()
chat.loadChatCache()
-
- let options: AVAudioSession.CategoryOptions = [.allowBluetooth]
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
- try AVAudioSession.sharedInstance().setActive(true)
- } catch {
- Logger.debug(error)
- }
}
func setupLog(){
}
func joyGemAuthSuccessCallback() {
Logger.debug("鉴权成功")
- PcmSound.sharedInstance().setup(16000, withchannels: 1)
- let options: AVAudioSession.CategoryOptions = [.allowBluetooth]
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
- try AVAudioSession.sharedInstance().setActive(true)
- } catch {
- Logger.debug(error)
- }
+ App.shared.preparePlay()
DeviceCache.saveLastConnected(mac: JoyBleManager.shared.connectPeripheral!.mac)
DeviceCache.shared.add(JoyBleManager.shared.connectPeripheral!.device.identifier.uuidString, mac: JoyBleManager.shared.connectPeripheral!.mac)
//
-// JoySdkManager.swift
// ShenYin
//
// Created by liangshi on 2025/8/28.
}
return getTopViewController(from: vc)
}
+ func preparePlay(){
+ PcmSound.sharedInstance().stopAudioUnit()
+ PcmSound.sharedInstance().cleanup()
+ PcmSound.sharedInstance().setup(16000, withchannels: 1)
+
+ let options: AVAudioSession.CategoryOptions = [.allowBluetooth]
+ do {
+ try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
+ try AVAudioSession.sharedInstance().setActive(true)
+ } catch {
+ Logger.debug(error)
+ }
+ }
func willLogin(){
CacheManager.shared.user.tokenIsValid {[weak self] success in
return "AE00"
}
static func isOtadata(_ characteristic:CBCharacteristic)->Bool{
-// guard let <#constant#> = <#expression#> else { return <#return value#> }
return (characteristic.service?.uuid.uuidString == otaServiceUUId) && (characteristic.uuid.uuidString == "AE02" || characteristic.uuid.uuidString == "AE01")
}
}
ProgressHUDHelper.shared.hide()
YLprogressHUD.showAutoHiden("升级成功".l10n)
Logger.debug("升级成功")
-// let mac = JoyBleManager.shared.connectPeripheral?.mac ?? ""
-// JoyBleManager.shared.cancel()
-// JoyBleManager.shared.connect(mac: mac) { result in
-//
-// }
}
else if result == .fail{
ProgressHUDHelper.shared.hide()
refreshData()
toolBar.textField.text = ""
-
-
-// JoyGemAIManager.shared().translate(text, from: from, to: to) {[weak self] result, finish in
-// guard let self = self else{return}
-// if !finish{
-// dataList.last!.response = dataList.last!.response + result
-// refreshData()
-// }
-//
-// } error: { error in
-//
-// }
-
}
}
var recordFilePath : String?
var startIndex = 0//记录开始录音的次数,用于区分返回的数据
- deinit {
- PcmSound.sharedInstance().stopAudioUnit()
- PcmSound.sharedInstance().cleanup()
- }
+// deinit {
+// PcmSound.sharedInstance().stopAudioUnit()
+// PcmSound.sharedInstance().cleanup()
+// }
override func setupViews() {
navBar.title = "中英互译".l10n
tableView.register(Chinese2EnglishCell.self, forCellReuseIdentifier: Chinese2EnglishCell.reuseID)
bg.image = UIImage(named: "translate_bg")
-
-
}
override func setupLayout() {
toolBar.snp.makeConstraints { make in
}
override func setupData() {
JoyGemSIManager.shared().delegate = self
-
- PcmSound.sharedInstance().delegate = self;
- PcmSound.sharedInstance().setup(16000, withchannels: 1)
-// do {
-// try AVAudioSession.sharedInstance().setActive(true)
-// } catch {
-// print(error)
-// }
-
+
if TipsCache.needShow(type: .chinese2english) {
RecordTipsView(type: .chinese2english).show()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationController?.fd_fullscreenPopGestureRecognizer?.isEnabled = false
+
+ PcmSound.sharedInstance().delegate = self;
+ App.shared.preparePlay()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.fd_fullscreenPopGestureRecognizer?.isEnabled = true
+ App.shared.preparePlay()
}
override func navleftViewTapped() {
if toolBar.recordBtn.isSelected {
CustomAlert.showWith(title: "提示".l10n, messgage: "当前正在录音,确定放弃当前录音吗".l10n, cancelCallback: {}) {
- JoyGemSIManager.shared().stop()
- PcmSound.sharedInstance().stopAudioUnit()
- PcmSound.sharedInstance().cleanup()
+// JoyGemSIManager.shared().stop()
+// PcmSound.sharedInstance().stopAudioUnit()
+// PcmSound.sharedInstance().cleanup()
super.navleftViewTapped()
}
}
func siManager(_ manager: JoyGemSIManager, didUpdateAudioData data: Data, sampleRate: UInt) {
PcmSound.sharedInstance().feed(data)
}
- // func siManager(_ manager: JoyGemSIManager, didUpdateAudioData data: Data) {
- // PcmSound.sharedInstance().feed(data)
- // }
-
+
func siManager(_ manager: JoyGemSIManager, onError code: JoyGemErrorCode) {
}
func remaining(_ frames: UInt) {
}
-
-
}
var model:HomeDeviceModel!{
didSet{
-// titleLabel.text = model.productName + model.mac.prefix(5)
titleLabel.text = model.productName
icon.kf.setImage(with: model.image.yc.asUrl)
} catch {
print(error)
}
- PcmSound.sharedInstance().setup(16000, withchannels: 1)
if TipsCache.needShow(type: .dialog) {
RecordTipsView(type: .dialog).show()
textView.text = text
textView.scrollToBottom()
}
-
- let options: AVAudioSession.CategoryOptions = [.allowBluetooth]
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
- try AVAudioSession.sharedInstance().setActive(true)
- } catch {
- Logger.debug(error)
- }
if autoStart{
startRecord()
}