public func initSDK(){
- StarburstConfig.shared().switch(to: .ble)
- StarburstConfig.shared().appId = "app_ro4n4nwljr20kwqo"
+// StarburstConfig.shared().switch(to: .ble)
+// StarburstConfig.shared().appId = "app_ro4n4nwljr20kwqo"
//MARK: 配置缓存路径
StarburstConfig.shared().sdkFolder = NSTemporaryDirectory()
StarburstConfig.shared().isDebug = true
// "x-tt-env": "ppe_tischarge_test",
// ]
// voicechat配置
- StarburstConfig.shared().user_custom_prompt_init = "1.用户位置在上海市杨浦区。2.用户名称叫小明。"
+// StarburstConfig.shared().user_custom_prompt_init = "1.用户位置在上海市杨浦区。2.用户名称叫小明。"
StarburstSdk.shared().authCallback = {[weak self] (code,msg) in
self?.authCallback?(Int(code),msg ?? "")
}
}
- public func stop(){
+ public func stopChat(){
DCChat.shared.stopChat()
}
+ public func startChat(){
+ DCChat.shared.startChat()
+ }
public func getVcSpeekerList(finished:@escaping ([DCRole]?,Bool)->Void){
DCChat.shared.getVcSpeekerList(finished: finished)
}
-// func setupSdk(){
-// 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 {
-// DCLogger.debug(error)
-// }
-//
-// setupChat()
-// }
+ func preparePlay(){
+ PcmSound.sharedInstance().cleanup()
+ PcmSound.sharedInstance().setup(16000, withchannels: 1)
+
+ var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
+ do {
+ try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
+ try AVAudioSession.sharedInstance().setActive(true)
+ } catch {
+ DCLogger.debug(error)
+ }
+ }
func setupChat(){
+ preparePlay()
DCChat.shared.role = role
DCChat.shared.asrCallback = {[weak self] (text,index) in
guard let self = self else{return}
}
DCLogger.debug("收到音频数据", data?.count ?? 0,sampleRate)
PcmSound.sharedInstance().feed(data)
-
-// if finish {
-// self.saveToFile(data: self.audioData!)
-// self.audioData = nil
-// } else {
-// if self.audioData == nil {
-// self.audioData = Data()
-// }
-// self.audioData?.append(data!)
-// }
}
DCChat.shared.codeCallback = {[weak self] code in
guard let self = self else { return }
}
}
DCChat.shared.finishCallback = {[weak self] path in
+ self?.preparePlay()
self?.finishCallback?(path)
}
}
- func saveToFile(data: Data) {
- let filePath = NSHomeDirectory() + "/Documents/1.mp3"
- let url = URL(fileURLWithPath: filePath)
- do {
- try data.write(to: url)
- print("\(filePath)")
-
- var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
- try AVAudioSession.sharedInstance().setActive(true)
- } catch {
- DCLogger.debug(error)
- }
- //这个要传开始播放的tts的dialogid
- DCChat.shared.startPlayTtsAudio()
- PlayerManager.shared.play(filePath: filePath,dialoIg:0) { (success,dialoIg) in
- print("播放结束 = \(success)")
- DCChat.shared.stopPlayTtsAudio()
- }
- } catch let error {
- print("\(error)")
- }
- }
+// func saveToFile(data: Data) {
+// let filePath = NSHomeDirectory() + "/Documents/1.mp3"
+// let url = URL(fileURLWithPath: filePath)
+// do {
+// try data.write(to: url)
+// print("\(filePath)")
+//
+// var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
+// do {
+// try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
+// try AVAudioSession.sharedInstance().setActive(true)
+// } catch {
+// DCLogger.debug(error)
+// }
+// //这个要传开始播放的tts的dialogid
+// DCChat.shared.startPlayTtsAudio()
+// PlayerManager.shared.play(filePath: filePath,dialoIg:0) { (success,dialoIg) in
+// print("播放结束 = \(success)")
+// DCChat.shared.stopPlayTtsAudio()
+// }
+// } catch let error {
+// print("\(error)")
+// }
+// }
}
extension DCChatManager : PcmSoundDelegate {
func remaining(_ frames: UInt) {