|
@@ -89,6 +89,15 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// MARK: - 录制参数
|
|
|
public var assets = [PHAsset]()
|
|
|
|
|
|
+ /// 显示数据处理中加载动画
|
|
|
+ lazy var loadingView: BFLoadingView = {
|
|
|
+ var loadingView = BFLoadingView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
+ loadingView.isHidden = true
|
|
|
+
|
|
|
+ return loadingView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
var currItemModelIndex = 0 {
|
|
|
didSet{
|
|
|
if currItemModelIndex < 0 || currItemModelIndex >= itemModels.count{
|
|
@@ -806,12 +815,20 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
guard let wself = self else { return }
|
|
|
|
|
|
if actionType == .VoiceSettingActionConfirm{//要生成真实音频文件
|
|
|
+ wself.tts?.stopTTS("")
|
|
|
BFLog(2, message: "确认选择发音人操作")
|
|
|
wself.mSelectVoiced = selectVoice
|
|
|
wself.voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isSelected)
|
|
|
if(wself.mSelectVoiced != nil){
|
|
|
- wself.tts?.startTTS("", taskId: "", isAudition: false,fontName: selectVoice?.voice ?? "")
|
|
|
+ //显示 UI
|
|
|
wself.voiceIconView.setNetImage(url: "\(wself.mSelectVoiced?.avatarUrl ?? "")")
|
|
|
+ if(!wself.voiceChangeStickerFinish(itemIndex: wself.currItemModelIndex)){
|
|
|
+
|
|
|
+ wself.loadingView.loading()
|
|
|
+ }
|
|
|
+ //静默转换语音
|
|
|
+ wself.tts?.runNextTask()
|
|
|
+
|
|
|
|
|
|
}else{
|
|
|
wself.voiceIconView.image = nil
|
|
@@ -856,7 +873,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ UIApplication.shared.keyWindow?.addSubview(loadingView)
|
|
|
+}
|
|
|
|
|
|
func layoutsubview() {
|
|
|
bottomeView.snp.makeConstraints { make in
|
|
@@ -1023,6 +1042,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// BFLog(1, message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn.seconds) timelineOut \(newSubtitle.timelineOut.seconds) text: \(newSubtitle.text)")
|
|
|
newSubtitle.setting = wself.subtitleSettingView.subtitle.setting
|
|
|
tempItem?.titleStickers.append(newSubtitle)
|
|
|
+
|
|
|
+ //add by ak 有字幕&设置发音人 添加到转换缓存
|
|
|
+ if(wself.mSelectVoiced != nil){
|
|
|
+ let ttsModel = BFTTSTaskModel.init()
|
|
|
+ ttsModel.timelineIn = newSubtitle.timelineIn
|
|
|
+ ttsModel.timelineOut = newSubtitle.timelineOut
|
|
|
+ ttsModel.fontName = wself.mSelectVoiced?.voice ?? ""
|
|
|
+ ttsModel.recordId = recordId ?? ""
|
|
|
+ ttsModel.tTtaskId = getUniqueId(desc: "tTtaskId")
|
|
|
+ ttsModel.text = showText
|
|
|
+ wself.tts?.pushTaskCache(ttsModel)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2022,8 +2054,17 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// assetPlayer.volume = noSpeakVolume
|
|
|
// }
|
|
|
// }
|
|
|
+
|
|
|
+ //add by ak 使用的音频数据
|
|
|
+ var useVoiceStickers = [PQVoiceModel]()
|
|
|
+ if(itemModels[currItemModelIndex].voiceChangeStickers.count > 0){
|
|
|
+ useVoiceStickers = itemModels[currItemModelIndex].voiceChangeStickers
|
|
|
+ }else{
|
|
|
+ useVoiceStickers = itemModels[currItemModelIndex].voiceStickers
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- if itemModels[currItemModelIndex].voiceStickers.first(where: { m in
|
|
|
+ if useVoiceStickers.first(where: { m in
|
|
|
CMTimeCompare(m.startCMTime, currentT) <= 0 && CMTimeCompare(currentT, m.endCMTime) <= 0
|
|
|
}) != nil {
|
|
|
if assetPlayer.volume != haveSpeakVolume {
|
|
@@ -2041,7 +2082,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// 先排序,再查找下一个需要播放的录音
|
|
|
- let list = itemModels[currItemModelIndex].voiceStickers.sorted { m1, m2 in
|
|
|
+ let list = useVoiceStickers.sorted { m1, m2 in
|
|
|
CMTimeCompare(m1.startCMTime, m2.startCMTime) < 0
|
|
|
}
|
|
|
let (shouldPlayRecordIndex, recordedAudio) = list.enumerated().first { model in
|
|
@@ -2838,7 +2879,7 @@ public extension BFRecordScreenController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// MARK: - TTS 试听回调
|
|
|
+// MARK: - TTS 试听&转语音回调
|
|
|
extension BFRecordScreenController: BFTTSManagerDelegte{
|
|
|
public func playerDidStart() {
|
|
|
BFLog(message: "试听开始播放")
|
|
@@ -2848,4 +2889,51 @@ extension BFRecordScreenController: BFTTSManagerDelegte{
|
|
|
BFLog(message: "试听播放完成")
|
|
|
voiceSettingView.flushSelectVoiceStatus(voiceStatue: .isSelected)
|
|
|
}
|
|
|
+
|
|
|
+ public func ttsFinish(_ model:BFTTSTaskModel){
|
|
|
+ BFLog(message: "文字转语音完成recordId:\(model.recordId) tttaskid:\(model.tTtaskId)")
|
|
|
+
|
|
|
+ let voice = PQVoiceModel.init()
|
|
|
+ voice.wavFilePath = model.wavFilePath
|
|
|
+ voice.startCMTime = model.timelineIn
|
|
|
+ voice.endCMTime = model.timelineOut
|
|
|
+ itemModels[currItemModelIndex].voiceChangeStickers.append(voice)
|
|
|
+
|
|
|
+ //
|
|
|
+ loadingView.titleL.text = "变音中 \(itemModels[currItemModelIndex].voiceChangeStickers.count / itemModels[currItemModelIndex].titleStickers.count)%"
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 查看发音人文件是否已经全都完成,如果没有完成不能进行预览,合成操作
|
|
|
+ /// - Parameter itemIndex: 段落 ID ,不传值是所有段落
|
|
|
+ /// - Returns: 是否全都完成
|
|
|
+ func voiceChangeStickerFinish(itemIndex:Int = -100) -> Bool{
|
|
|
+ if(mSelectVoiced == nil){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ var isFinish = true
|
|
|
+ //所有任务数也就是字幕的个数
|
|
|
+ var AllCount = 0
|
|
|
+ //完成的任务数(已经有发音人地址的)
|
|
|
+ var FinishCount = 0
|
|
|
+
|
|
|
+ if(itemIndex >= 0){//只查看当前段落
|
|
|
+ AllCount = itemModels[currItemModelIndex].titleStickers.count
|
|
|
+ FinishCount = itemModels[currItemModelIndex].voiceChangeStickers.count
|
|
|
+
|
|
|
+ }else{//所有段落
|
|
|
+ for itemModel in itemModels{
|
|
|
+ AllCount += itemModel.titleStickers.count
|
|
|
+ FinishCount += itemModel.voiceChangeStickers.count
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BFLog(message: "总任务数:\(AllCount) 已经完成数:\(FinishCount)")
|
|
|
+ if(FinishCount < AllCount){
|
|
|
+ isFinish = false
|
|
|
+ }
|
|
|
+
|
|
|
+ return isFinish
|
|
|
+ }
|
|
|
+
|
|
|
}
|