|
@@ -20,7 +20,7 @@ struct WithDrawModel {
|
|
|
var timestamp: Double
|
|
|
var deletedVoices: [(PQVoiceModel, Int)]?
|
|
|
// add by ak 保存删除的字幕数据用于恢复
|
|
|
- var deletedTittles: [(PQEditSubTitleModel, Int)]?
|
|
|
+ var deletedTittles: [PQEditSubTitleModel]?
|
|
|
}
|
|
|
|
|
|
public class BFRecordScreenController: BFBaseViewController {
|
|
@@ -477,7 +477,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let header = dicResult?["header"] as? [String: Any]
|
|
|
let payload = dicResult?["payload"] as? [String: Any]
|
|
|
|
|
|
- BFLog(1, message: "识别结果:) \((payload)!),taskId:\((header?["task_id"] as? String) ?? "taskId"), 识别时间:\((((payload?["begin_time"]) as? Int) ?? 0)) ~ \((((payload?["time"]) as? Int) ?? 0)) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
|
|
|
+ BFLog(1, message: "识别结果:) \(payload?["result"]),taskId:\((header?["task_id"] as? String) ?? "taskId"), 识别时间:\((((payload?["begin_time"]) as? Int) ?? 0)) ~ \((((payload?["time"]) as? Int) ?? 0)) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
|
|
|
DispatchQueue.main.async {
|
|
|
// 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startCMTime.seconds 为开始的录制的时间,开始和结束都要加上这个时差
|
|
|
|
|
@@ -548,7 +548,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
var deletedVoices = [(PQVoiceModel, Int)]()
|
|
|
// 要删除的字幕
|
|
|
- var deletedTitlesTemp = [(PQEditSubTitleModel, Int)]()
|
|
|
+ var deletedTitlesTemp = [PQEditSubTitleModel]()
|
|
|
+
|
|
|
+ // 查找要删除的音频和字幕数据
|
|
|
for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
|
|
|
let originRange = CMTimeRange(start: m.startCMTime, end: CMTime(seconds: m.endCMTime.seconds - 0.02, preferredTimescale: 1000))
|
|
|
if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0 {
|
|
@@ -563,6 +565,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
m.wavFilePath == tempM.wavFilePath
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
BFLog(1, message: "添加录音文件:\(model.startCMTime.seconds) -- \(model.endCMTime.seconds)")
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
|
|
|
// 如果是图片素材同时有需要删除的录音时需要调整录音文件开始结束时间
|
|
@@ -921,22 +925,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
/// 删除指定段落的所有字幕 数据
|
|
|
/// - Parameter voiceModel: 删除的音频数据
|
|
|
- func deleteTitles(voiceModel: PQVoiceModel) -> [(PQEditSubTitleModel, Int)] {
|
|
|
+ func deleteTitles(voiceModel: PQVoiceModel) -> [PQEditSubTitleModel] {
|
|
|
BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startCMTime.seconds: \(voiceModel.startCMTime.seconds) model.end: \(voiceModel.endCMTime.seconds)")
|
|
|
- var deleteTemp = [(PQEditSubTitleModel, Int)]()
|
|
|
+ var deleteTemp = [PQEditSubTitleModel]()
|
|
|
|
|
|
- for (ind, sticker) in itemModels[currItemModelIndex].titleStickers.enumerated() {
|
|
|
- if sticker.audioFilePath == voiceModel.wavFilePath {
|
|
|
- deleteTemp.append((sticker, ind))
|
|
|
- }
|
|
|
- }
|
|
|
// 从原数组中删除
|
|
|
- let arr = itemModels[currItemModelIndex].titleStickers.filter { model in
|
|
|
- !deleteTemp.contains { tuple in
|
|
|
- tuple.0.audioFilePath == model.audioFilePath
|
|
|
+ itemModels[currItemModelIndex].titleStickers.removeAll { m in
|
|
|
+ let su = (m.audioFilePath == voiceModel.wavFilePath)
|
|
|
+ if su {
|
|
|
+ deleteTemp.append(m)
|
|
|
}
|
|
|
+ return su
|
|
|
}
|
|
|
- itemModels[currItemModelIndex].titleStickers = arr
|
|
|
+
|
|
|
BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
|
|
|
|
|
|
// 清空字幕UI
|
|
@@ -1144,13 +1145,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
|
|
|
itemModels[currItemModelIndex].voiceStickers.remove(at: modelIndex)
|
|
|
indirectionView?.deleteItem(index: modelIndex)
|
|
|
+
|
|
|
// 删除对应字幕
|
|
|
- let deleteTitiles = deleteTitles(voiceModel: model)
|
|
|
- for title in deleteTitiles {
|
|
|
- itemModels[currItemModelIndex].titleStickers.removeAll { model in
|
|
|
- title.0.timelineIn == model.timelineIn
|
|
|
- }
|
|
|
+ itemModels[currItemModelIndex].titleStickers.removeAll { m in
|
|
|
+ m.audioFilePath == model.wavFilePath
|
|
|
}
|
|
|
+
|
|
|
// 恢复被覆盖的音频
|
|
|
var tuples = action.deletedVoices
|
|
|
if tuples != nil, tuples!.count > 0 {
|
|
@@ -1165,7 +1165,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let titleTuples = action.deletedTittles
|
|
|
if titleTuples != nil, titleTuples!.count > 0 {
|
|
|
titleTuples?.forEach { titleTuple in
|
|
|
- itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
|
|
|
+ itemModels[currItemModelIndex].titleStickers.append(titleTuple)
|
|
|
}
|
|
|
}
|
|
|
jumpTime = model.startCMTime.seconds
|
|
@@ -1206,7 +1206,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let titleTuples = action.deletedTittles
|
|
|
if titleTuples != nil, titleTuples!.count > 0 {
|
|
|
titleTuples?.forEach { titleTuple in
|
|
|
- itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
|
|
|
+ itemModels[currItemModelIndex].titleStickers.append(titleTuple)
|
|
|
}
|
|
|
}
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
@@ -1599,6 +1599,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
func play() {
|
|
|
BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
|
|
|
recorderManager?.voiceModel = nil
|
|
|
+
|
|
|
+ itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
|
|
|
+ m1.timelineIn < m2.timelineIn
|
|
|
+ }
|
|
|
|
|
|
isNormalPlaying = true
|
|
|
if isEndPlay {
|