Przeglądaj źródła

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

* 'dev' of https://git.yishihui.com/iOS/BFRecordScreenKit:
  界面关闭时 停止 TTS
  1,返回时关闭TTS 2,修改注释
  1,合成时有发音人时 逻辑处理。
  1,显示文字加宽
  1,添加统计 2, 显示转音进度
胡志强 3 lat temu
rodzic
commit
8a99523ebe

+ 45 - 27
BFRecordScreenKit/Classes/BFRecordExport.swift

@@ -74,7 +74,8 @@ public class BFRecordExport {
                 if needSort {
                 } else {
                     // 音频排序
-                    itemModel.voiceStickers.sort { m1, m2 in
+                    var useVoices = itemModel.getUsedVoices()
+                    useVoices.sort { m1, m2 in
                         m1.startCMTime.seconds < m2.startCMTime.seconds
                     }
                     // 字幕排序
@@ -110,13 +111,13 @@ public class BFRecordExport {
     }
     
     func parseImage(synthesisAll: Bool, itemModel: BFRecordItemModel, totalDur:Double) -> Double{
-        if !synthesisAll, itemModel.voiceStickers.count == 0 {
+        if !synthesisAll, itemModel.getUsedVoices().count == 0 {
             // 图片无录音在保留模式里不合成
             return 0
         }
 
         var duration = itemModel.materialDuraion.seconds
-        if itemModel.voiceStickers.count == 0 {
+        if itemModel.getUsedVoices().count == 0 {
             // 图片无录音保持2s
             duration = 2
             let voice = PQEditVisionTrackMaterialsModel()
@@ -128,7 +129,7 @@ public class BFRecordExport {
             voiceList.append(voice)
         } else {
             //
-            for mod in itemModel.voiceStickers {
+            for mod in itemModel.getUsedVoices() {
                 let sticker = PQEditVisionTrackMaterialsModel()
                 sticker.model_in = 0
                 sticker.out = mod.endCMTime.seconds - mod.startCMTime.seconds
@@ -172,9 +173,6 @@ public class BFRecordExport {
                 exportCompletion?(error as Error, nil)
                 return subDur
             }
-
-//                    voiceList.append(contentsOf: itemModel.voiceStickers)
-
             if synthesisAll {
                 let drangs = itemModel.dealedDurationRanges
                 for srange in drangs {
@@ -186,10 +184,7 @@ public class BFRecordExport {
                     subDur += range.duration.seconds
 
                     if srange.isRecord {
-                        // 处理voice
-                        if let mod = itemModel.voiceStickers.first(where: { m in
-                            m.startCMTime.seconds == range.start.seconds
-                        }) {
+                        itemModel.getUsedVoices().forEach { mod in
                             let sticker = PQEditVisionTrackMaterialsModel()
                             sticker.model_in = 0
                             sticker.out = mod.endCMTime.seconds - mod.startCMTime.seconds
@@ -234,16 +229,39 @@ public class BFRecordExport {
                     videoStickers.append(sticker)
 
                     let voiceSticker = itemModel.voiceStickers[index]
-                    let voice = PQEditVisionTrackMaterialsModel()
-                    voice.model_in = 0
-                    voice.out = voiceSticker.endCMTime.seconds - voiceSticker.startCMTime.seconds
-                    voice.timelineIn = totalDur + subDur
-                    voice.timelineOut = totalDur + subDur + voice.out
-                    voice.aptDuration = voice.out
-                    voice.duration = voice.out
-                    voice.locationPath = voiceSticker.wavFilePath
-                    voice.volumeGain = 100 // Float64(model.volume)
-                    voiceList.append(voice)
+                    // mdf by ak 
+                    if(itemModel.voiceChangeStickers.count > 0){//有变音
+                        
+                        let voiceChangeModels = itemModel.voiceChangeStickers.filter { mod in
+                            mod.recordId == voiceSticker.recordId
+                        }
+                        for voice in voiceChangeModels{
+                            BFLog(2, message: "当前变音所属:\(voiceSticker.recordId ?? "") text:\(voice.wavFilePath ?? "")")
+                            let voiceChangeSt = PQEditVisionTrackMaterialsModel()
+                            voiceChangeSt.model_in = 0
+                            voiceChangeSt.out = voice.endCMTime.seconds - voice.startCMTime.seconds
+                            voiceChangeSt.timelineIn = totalDur + subDur + (voice.startCMTime.seconds - voiceSticker.startCMTime.seconds)
+                            voiceChangeSt.timelineOut = voiceChangeSt.timelineIn + voiceChangeSt.out
+                            voiceChangeSt.aptDuration = voiceChangeSt.out
+                            voiceChangeSt.duration = voiceChangeSt.out
+                            voiceChangeSt.locationPath = voice.wavFilePath
+                            voiceChangeSt.volumeGain = 100 // Float64(model.volume)
+                            voiceList.append(voiceChangeSt)
+                        }
+                        
+                    }else{//无变音
+                        let voice = PQEditVisionTrackMaterialsModel()
+                        voice.model_in = 0
+                        voice.out = voiceSticker.endCMTime.seconds - voiceSticker.startCMTime.seconds
+                        voice.timelineIn = totalDur + subDur
+                        voice.timelineOut = totalDur + subDur + voice.out
+                        voice.aptDuration = voice.out
+                        voice.duration = voice.out
+                        voice.locationPath = voiceSticker.wavFilePath
+                        voice.volumeGain = 100 // Float64(model.volume)
+                        voiceList.append(voice)
+                    }
+                
 
                     let titleModels = itemModel.titleStickers.filter { mod in
                         mod.recordId == voiceSticker.recordId
@@ -287,7 +305,7 @@ public class BFRecordExport {
         }
         
         // 音频分解
-        for mod in itemModel.voiceStickers {
+        for mod in itemModel.getUsedVoices() {
             let sticker = PQEditVisionTrackMaterialsModel()
             sticker.model_in = 0
             sticker.type = StickerType.VOICE.rawValue
@@ -321,7 +339,7 @@ public class BFRecordExport {
 
     public func clearFileCache() {
         data?.forEach { itemModel in
-            itemModel.voiceStickers.forEach { model in
+            itemModel.getUsedVoices().forEach { model in
                 if let localPath = model.wavFilePath {
                     try? FileManager.default.removeItem(atPath: localPath)
                 }
@@ -382,10 +400,10 @@ public class BFRecordExport {
         // 处理导出
 
         guard let voiceCount = data?.reduce(0, { partialResult, itemModell in
-            itemModell.voiceStickers.count + partialResult
+            itemModell.getUsedVoices().count + partialResult
         }) else {
-            BFLog(1, message: "voiceStickers count += nil")
-            let error = NSError(domain: "err", code: ExportError.VoiceLost.rawValue, userInfo: ["msg": "voiceStickers count += nil"])
+            BFLog(1, message: "getUsedVoices() count += nil")
+            let error = NSError(domain: "err", code: ExportError.VoiceLost.rawValue, userInfo: ["msg": "getUsedVoices() count += nil"])
             exportCompletion?(error as Error, nil)
             return
         }
@@ -393,7 +411,7 @@ public class BFRecordExport {
         guard let totalDuration = data?.reduce(0.0, { partialResult, itemModell in
             var modelDuraion = 0.0
             if itemModell.mediaType == .Image {
-                if itemModell.voiceStickers.count == 0, synthesisAll {
+                if itemModell.getUsedVoices().count == 0, synthesisAll {
                     modelDuraion += 2
                 } else {
                     modelDuraion = itemModell.materialDuraion.seconds

+ 16 - 6
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -40,7 +40,8 @@ public class BFRecordScreenController: BFBaseViewController {
     // 字幕按钮点击上报
     public var subTitleBtnClickHandle: ((_ isOn: Bool) -> Void)?
 //    public var currentRecordId: String? // 当前录制Id
-
+    //选了发音人点了确定
+    public var voiceBtnClickHandle: ((_ voice: PQVoiceModel?) -> Void)?
     // MARK: - 素材参数
     lazy var rsvmanager : BFRecordScreenVideoManager = {
         let m = BFRecordScreenVideoManager()
@@ -451,7 +452,7 @@ public class BFRecordScreenController: BFBaseViewController {
         return btn
     }()
     
-    // 字幕设置
+    // 变音设置
     lazy var voiceSettingBtn: UIButton = {
         let btn = UIButton(type: .custom)
         btn.setImage(imageInRecordScreenKit(by: "TTS"), for: .normal)
@@ -667,6 +668,7 @@ public class BFRecordScreenController: BFBaseViewController {
         super.viewWillDisappear(animated)
         UIApplication.shared.keyWindow?.isUserInteractionEnabled = true
         pause()
+        tts?.stopTTS("")
         UIApplication.shared.isIdleTimerDisabled = false
     }
 
@@ -834,8 +836,12 @@ public class BFRecordScreenController: BFBaseViewController {
             guard let wself = self else { return }
           
             if actionType == .VoiceSettingActionConfirm{//要生成真实音频文件
-                wself.tts?.stopTTS("")
                 BFLog(2, message: "确认选择发音人操作")
+                if(wself.voiceBtnClickHandle != nil && selectVoice != nil){
+                    wself.voiceBtnClickHandle!(selectVoice!)
+                }
+                wself.tts?.stopTTS("")
+            
                 
                 //切换了发音人
                 if(wself.mSelectVoiced != selectVoice){
@@ -1312,6 +1318,7 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: - 按钮事件响应
 
     override public func backBtnClick() {
+        
         pause()
     }
 
@@ -2008,7 +2015,7 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(3, message: "未找到可播放录音")
             return
         }
-//        BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startCMTime.seconds) ~ \(recordedAudio.endCMTime.seconds), \(recordedAudio.wavFilePath ?? "")")
+        BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startCMTime.seconds) ~ \(recordedAudio.endCMTime.seconds), \(recordedAudio.wavFilePath ?? "")")
 
         // 创建播放器
         if (recordPlayer.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString?)?.lastPathComponent {
@@ -2832,10 +2839,13 @@ extension BFRecordScreenController: BFTTSManagerDelegte{
         voice.startCMTime = model.timelineIn
         voice.endCMTime = model.timelineOut
         voice.ttsTaskID = model.tTtaskId
+        voice.recordId = model.recordId
         itemModels[currItemModelIndex].voiceChangeStickers.append(voice)
         
-        //
-        loadingView.titleL.text = "变音中 \(itemModels[currItemModelIndex].voiceChangeStickers.count / itemModels[currItemModelIndex].titleStickers.count)%"
+        //显示转换进度
+        let progress =  Float(itemModels[currItemModelIndex].voiceChangeStickers.count * 100 / itemModels[currItemModelIndex].titleStickers.count)
+        BFLog(message: "TTS 进度:\(Int(progress))")
+        loadingView.titleL.text = "变音中 \(Int(progress))%"
         
         if(voiceChangeStickerFinish(itemIndex: currItemModelIndex)){
             loadingView.loadHidden()

+ 1 - 1
BFRecordScreenKit/Classes/RecordScreen/View/BFLoadingView.swift

@@ -69,7 +69,7 @@ class BFLoadingView: UIView {
         let imageH: CGFloat = 90
         loadingImage.frame = CGRect(x: (frame.width - imageW) / 2, y: (frame.height - imageW) / 2, width: imageW, height: imageH)
 
-        titleL.frame = CGRect(x: (cScreenWidth - 88) / 2, y: loadingImage.frame.maxY + 10, width: 88, height: 22)
+        titleL.frame = CGRect(x: (cScreenWidth - 150) / 2, y: loadingImage.frame.maxY + 10, width: 150, height: 22)
     }
 
     ///   显示动画