Browse Source

Merge branch 'dev' of https://git.yishihui.com/iOS/BFRecordScreenKit into dev

* 'dev' of https://git.yishihui.com/iOS/BFRecordScreenKit:
  1,删除不使用代码 ,2,录音时隐藏变音入口  3,返回时删除缓存音频文件 4,添加 LOG
  1,设置过发音人 再次打开面板时要选择中设置的发音人
  试听时 点击同一个人状态切换逻辑调整
胡志强 3 years ago
parent
commit
540d17b633

+ 33 - 45
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -189,7 +189,7 @@ public class BFRecordScreenController: BFBaseViewController {
     public var isRecording = false { // 是否正在录音
     public var isRecording = false { // 是否正在录音
         didSet {
         didSet {
             withDrawBtn.isHidden = isRecording
             withDrawBtn.isHidden = isRecording
-            changeVoiceBtn.isHidden = isRecording
+            voiceSettingBtn.isHidden = isRecording
             subtitleBtn.isHidden = isRecording
             subtitleBtn.isHidden = isRecording
             soundSettingBtn.isHidden = isRecording
             soundSettingBtn.isHidden = isRecording
             recordBtn.setTitle(isRecording ? "record_pause".BFLocale : (currMediaType == .Camera ? "record_lz".BFLocale : "record_ly".BFLocale), for: .normal)
             recordBtn.setTitle(isRecording ? "record_pause".BFLocale : (currMediaType == .Camera ? "record_lz".BFLocale : "record_ly".BFLocale), for: .normal)
@@ -376,19 +376,6 @@ public class BFRecordScreenController: BFBaseViewController {
         return btn
         return btn
     }()
     }()
 
 
-    lazy var changeVoiceBtn: UIButton = {
-        let btn = UIButton(type: .custom)
-        btn.setImage(imageInRecordScreenKit(by: "changeVoice_n"), for: .normal)
-        btn.setImage(imageInRecordScreenKit(by: "changeVoice_h"), for: .highlighted)
-        btn.setTitle("变声", for: .normal)
-        btn.setTitleColor(.white, for: .normal)
-        btn.setTitleColor(ThemeStyleColor, for: .highlighted)
-        btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
-        btn.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
-        btn.addTarget(self, action: #selector(changeVoiceAction), for: .touchUpInside)
-        return btn
-    }()
-
     lazy var toolV: BFIntroduceToolView = {
     lazy var toolV: BFIntroduceToolView = {
         let toolV = BFIntroduceToolView()
         let toolV = BFIntroduceToolView()
         toolV.centerY = view.centerY
         toolV.centerY = view.centerY
@@ -735,7 +722,6 @@ public class BFRecordScreenController: BFBaseViewController {
         bottomeView.addSubview(recordBtn)
         bottomeView.addSubview(recordBtn)
         bottomeView.addSubview(deleteRecordBtn)
         bottomeView.addSubview(deleteRecordBtn)
         bottomeView.addSubview(withDrawBtn)
         bottomeView.addSubview(withDrawBtn)
-        //        bottomeView.addSubview(changeVoiceBtn)
         bottomeView.addSubview(progressThumV)
         bottomeView.addSubview(progressThumV)
         bottomeView.addSubview(cameraProgressThumV)
         bottomeView.addSubview(cameraProgressThumV)
 
 
@@ -832,7 +818,7 @@ public class BFRecordScreenController: BFBaseViewController {
             wself.voiceSettingView.voices = voices
             wself.voiceSettingView.voices = voices
          
          
         }
         }
-        voiceSettingView.voiceSettingCallBack = {[weak self] actionType ,selectVoice in
+        voiceSettingView.voiceSettingCallBack = {[weak self] actionType ,selectVoice ,isSame in
             guard let wself = self else { return }
             guard let wself = self else { return }
           
           
             if actionType == .VoiceSettingActionConfirm{//要生成真实音频文件
             if actionType == .VoiceSettingActionConfirm{//要生成真实音频文件
@@ -881,28 +867,24 @@ public class BFRecordScreenController: BFBaseViewController {
                 wself.tts?.stopTTS("")
                 wself.tts?.stopTTS("")
             }else if actionType == .VoiceSettingActionSelected{//要进行试听或暂停操作
             }else if actionType == .VoiceSettingActionSelected{//要进行试听或暂停操作
                 BFLog(2, message: "选择了一个发音人操作")
                 BFLog(2, message: "选择了一个发音人操作")
-                if(wself.mSelectVoiced == nil){
-                    //首次选直接转
-                    wself.tts?.startTTS("", taskId: "", isAudition: true,fontName: selectVoice?.voice ?? "")
-                    wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isLoading)
-                }else{ 
-                    if(wself.mSelectVoiced == selectVoice){  //是同一个发音人暂停
-
-                        BFLog(message: "试听播放器状态\(String(describing: wself.tts?.voicePlayer.state.rawValue) )")
-                     
-                        if (wself.tts?.voicePlayer.state == PlayerState.playing){
-                            wself.tts?.stopTTS("")
-                            wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isPause)
-                        }else{
-                            wself.tts?.startTTS("", taskId: "", isAudition: true,fontName: selectVoice?.voice ?? "")
-                            wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isLoading)
-                        }
+           
+                if(isSame){  //是同一个发音人暂停
 
 
-                    } else{//开始试听
+                    BFLog(message: "试听播放器状态\(String(describing: wself.tts?.voicePlayer.state.rawValue) )")
+                 
+                    if (wself.tts?.voicePlayer.state == PlayerState.playing){
+                        wself.tts?.stopTTS("")
+                        wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isPause)
+                    }else{
                         wself.tts?.startTTS("", taskId: "", isAudition: true,fontName: selectVoice?.voice ?? "")
                         wself.tts?.startTTS("", taskId: "", isAudition: true,fontName: selectVoice?.voice ?? "")
                         wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isLoading)
                         wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isLoading)
                     }
                     }
+
+                } else{//开始试听
+                    wself.tts?.startTTS("", taskId: "", isAudition: true,fontName: selectVoice?.voice ?? "")
+                    wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isLoading)
                 }
                 }
+                
  
  
             }
             }
             
             
@@ -929,11 +911,7 @@ public class BFRecordScreenController: BFBaseViewController {
             make.width.height.equalTo(65)
             make.width.height.equalTo(65)
             make.top.equalTo(88)
             make.top.equalTo(88)
         }
         }
-        //        changeVoiceBtn.snp.makeConstraints { make in
-        //            make.right.equalToSuperview()
-        //            make.top.width.height.equalTo(withDrawBtn)
-        //        }
-
+ 
         recordBtn.snp.makeConstraints { make in
         recordBtn.snp.makeConstraints { make in
             make.left.equalTo(withDrawBtn.snp.right)
             make.left.equalTo(withDrawBtn.snp.right)
             make.right.equalTo(-65)
             make.right.equalTo(-65)
@@ -993,9 +971,6 @@ public class BFRecordScreenController: BFBaseViewController {
 
 
         withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
         withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
         withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
         withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
-
-        changeVoiceBtn.imageEdgeInsets = UIEdgeInsets(top: -changeVoiceBtn.imageView!.height - 2, left: 0, bottom: 0, right: -changeVoiceBtn.titleLabel!.width)
-        changeVoiceBtn.titleEdgeInsets = UIEdgeInsets(top: changeVoiceBtn.titleLabel!.height + 2, left: -changeVoiceBtn.imageView!.width, bottom: 0, right: 0)
     }
     }
     // MARK: - 录音机字幕回调相关
     // MARK: - 录音机字幕回调相关
     func initlizeRecordManager() {
     func initlizeRecordManager() {
@@ -1318,7 +1293,8 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: - 按钮事件响应
     // MARK: - 按钮事件响应
 
 
     override public func backBtnClick() {
     override public func backBtnClick() {
-        
+        //add by ak 删除变音文件
+        tts?.deleteWavFiles()
         pause()
         pause()
     }
     }
 
 
@@ -1382,14 +1358,19 @@ public class BFRecordScreenController: BFBaseViewController {
     @objc func soundSetting() {
     @objc func soundSetting() {
         BFLog(message: "设置声音")
         BFLog(message: "设置声音")
 
 
-        audioSettingView.isHidden = false
+        audioSettingView.isHidden = !audioSettingView.isHidden
     }
     }
     
     
     //变声设置
     //变声设置
     @objc func voiceSetting() {
     @objc func voiceSetting() {
         BFLog(message: "设置变音")
         BFLog(message: "设置变音")
+        if(mSelectVoiced != nil){
+            voiceSettingView.selectVoice = mSelectVoiced
+            voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isSelected)
+            voiceSettingView.deleteBtn.isSelected = true
+        }
 
 
-        voiceSettingView.isHidden = false
+        voiceSettingView.isHidden =  !voiceSettingView.isHidden
       
       
     }
     }
     
     
@@ -1454,6 +1435,7 @@ public class BFRecordScreenController: BFBaseViewController {
 
 
             searchStopAtRecordRange()
             searchStopAtRecordRange()
             changeWithDrawBtnLayout(3)
             changeWithDrawBtnLayout(3)
+            
         }
         }
     }
     }
 
 
@@ -2197,9 +2179,11 @@ public class BFRecordScreenController: BFBaseViewController {
         deleteRecordBtn.isHidden = true
         deleteRecordBtn.isHidden = true
 
 
         subtitleBtn.isHidden = true
         subtitleBtn.isHidden = true
+        voiceSettingBtn.isHidden = true
         soundSettingBtn.isHidden = true
         soundSettingBtn.isHidden = true
         withDrawBtn.isHidden = true
         withDrawBtn.isHidden = true
         recordBtn.isHidden = true
         recordBtn.isHidden = true
+        
     }
     }
 
 
     public func pause() {
     public func pause() {
@@ -2836,7 +2820,11 @@ extension BFRecordScreenController: BFTTSManagerDelegte{
     }
     }
     
     
     public func ttsFinish(_ model:BFTTSTaskModel){
     public func ttsFinish(_ model:BFTTSTaskModel){
-        BFLog(message: "文字转语音完成recordId:\(model.recordId) tttaskid:\(model.tTtaskId)")
+        
+        
+        let ttsAudioAsset = AVURLAsset(url: URL(fileURLWithPath: model.wavFilePath), options: avAssertOptions)
+     
+        BFLog(message: "文字转语音完成recordId:\(model.recordId) tttaskid:\(model.tTtaskId)  tss语音时长\(ttsAudioAsset.duration.seconds) 字幕开始\(model.timelineIn.seconds) 字幕结束\(model.timelineOut.seconds) 字幕原时长\(CMTimeSubtract(model.timelineOut, model.timelineIn).seconds)")
         
         
         let voice = PQVoiceModel.init()
         let voice = PQVoiceModel.init()
         voice.wavFilePath = model.wavFilePath
         voice.wavFilePath = model.wavFilePath

+ 12 - 7
BFRecordScreenKit/Classes/RecordScreen/View/BFVoiceSettingView.swift

@@ -42,8 +42,8 @@ class BFVoiceSettingView: UIView {
         }
         }
     }
     }
 
 
-    // 操作回调
-    public var voiceSettingCallBack: ((_ actionType: VoiceSettingActionType, _ selectVoice: PQVoiceModel?) -> Void)?
+    // 操作回调  isSame 是否点击的是同一个人,进行状态切换使用
+    public var voiceSettingCallBack: ((_ actionType: VoiceSettingActionType, _ selectVoice: PQVoiceModel?,_ isSame:Bool ) -> Void)?
 
 
     // 当前选择的分类
     // 当前选择的分类
     var curretnCategory: BFVoiceCategoryModel?
     var curretnCategory: BFVoiceCategoryModel?
@@ -211,7 +211,7 @@ class BFVoiceSettingView: UIView {
     @objc func cancelAction() {
     @objc func cancelAction() {
         hidden()
         hidden()
         if voiceSettingCallBack != nil {
         if voiceSettingCallBack != nil {
-            voiceSettingCallBack!(.voiceSettingActionCancel, selectVoice)
+            voiceSettingCallBack!(.voiceSettingActionCancel, selectVoice,false)
         }
         }
     }
     }
     
     
@@ -219,7 +219,7 @@ class BFVoiceSettingView: UIView {
     @objc func okBtnAction() {
     @objc func okBtnAction() {
         hidden()
         hidden()
         if voiceSettingCallBack != nil {
         if voiceSettingCallBack != nil {
-            voiceSettingCallBack!(.VoiceSettingActionConfirm, selectVoice)
+            voiceSettingCallBack!(.VoiceSettingActionConfirm, selectVoice,false)
         }
         }
     }
     }
 
 
@@ -239,7 +239,7 @@ class BFVoiceSettingView: UIView {
         }
         }
 
 
         if voiceSettingCallBack != nil {
         if voiceSettingCallBack != nil {
-            voiceSettingCallBack!(.voiceSettingActionDelete, selectVoice)
+            voiceSettingCallBack!(.voiceSettingActionDelete, selectVoice,false)
         }
         }
     }
     }
     
     
@@ -295,15 +295,20 @@ extension BFVoiceSettingView: UICollectionViewDelegate, UICollectionViewDataSour
 
 
             voicesCollectView.reloadData()
             voicesCollectView.reloadData()
         } else {
         } else {
+            //是否点击的是同一个人
+            let isSame = selectVoice == voices[curretnCategory?.cateName ?? ""]?[indexPath.item] ? true : false
+         
             selectVoice?.voiceStatue = .isNormal
             selectVoice?.voiceStatue = .isNormal
             selectVoice = voices[curretnCategory?.cateName ?? ""]?[indexPath.item]
             selectVoice = voices[curretnCategory?.cateName ?? ""]?[indexPath.item]
             selectVoice?.voiceStatue = .isSelected
             selectVoice?.voiceStatue = .isSelected
             deleteBtn.isSelected = true
             deleteBtn.isSelected = true
             voicesCollectView.reloadData()
             voicesCollectView.reloadData()
-
+            
             if voiceSettingCallBack != nil {
             if voiceSettingCallBack != nil {
-                voiceSettingCallBack!(.VoiceSettingActionSelected, selectVoice)
+                voiceSettingCallBack!(.VoiceSettingActionSelected, selectVoice,isSame)
             }
             }
+            
+
         }
         }
     }
     }
 }
 }