|
@@ -20,7 +20,7 @@ struct WithDrawModel {
|
|
var timestamp: Double
|
|
var timestamp: Double
|
|
var deletedVoices: [(PQVoiceModel, Int)]?
|
|
var deletedVoices: [(PQVoiceModel, Int)]?
|
|
// add by ak 保存删除的字幕数据用于恢复
|
|
// add by ak 保存删除的字幕数据用于恢复
|
|
- var deletedTittles:[(PQEditSubTitleModel,Int)]?
|
|
|
|
|
|
+ var deletedTittles: [(PQEditSubTitleModel, Int)]?
|
|
}
|
|
}
|
|
|
|
|
|
public class BFRecordScreenController: BFBaseViewController {
|
|
public class BFRecordScreenController: BFBaseViewController {
|
|
@@ -33,7 +33,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
public var assets = [PHAsset]()
|
|
public var assets = [PHAsset]()
|
|
var currItemModelIndex = 0
|
|
var currItemModelIndex = 0
|
|
public var itemModels = [BFRecordItemModel]()
|
|
public var itemModels = [BFRecordItemModel]()
|
|
- //add by ak 当前的显示的字幕位置
|
|
|
|
|
|
+ // add by ak 当前的显示的字幕位置
|
|
var showSubtitleIndex = 0
|
|
var showSubtitleIndex = 0
|
|
// var shouldPlayRecordIndex:Int = -1 // 当前应该播放的录音资源序号
|
|
// var shouldPlayRecordIndex:Int = -1 // 当前应该播放的录音资源序号
|
|
var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
|
|
var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
|
|
@@ -405,7 +405,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
_ = disablePopGesture()
|
|
_ = disablePopGesture()
|
|
|
|
|
|
// add by ak 取 nsl token
|
|
// add by ak 取 nsl token
|
|
- BFRecordScreenViewModel.getNlsAccessToken { [weak self] token, appkey in
|
|
|
|
|
|
+ BFRecordScreenViewModel.getNlsAccessToken {[weak self] token, appkey in
|
|
BFLog(message: "nls appkey is \(appkey), token is \(token)")
|
|
BFLog(message: "nls appkey is \(appkey), token is \(token)")
|
|
self?.speechTranscriberUtil = PQSpeechTranscriberUtil(token, appid: appkey)
|
|
self?.speechTranscriberUtil = PQSpeechTranscriberUtil(token, appid: appkey)
|
|
}
|
|
}
|
|
@@ -439,11 +439,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .defaultToSpeaker)
|
|
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .defaultToSpeaker)
|
|
}
|
|
}
|
|
|
|
|
|
- avatarView.recordEndCallBack = { [weak self] _, materialsModel in
|
|
|
|
|
|
+ avatarView.recordEndCallBack = { _, materialsModel in
|
|
BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
|
|
BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
|
|
}
|
|
}
|
|
|
|
|
|
- audioSettingView.callBack = { [weak self] haveSpeak, noHaveSpeak in
|
|
|
|
|
|
+ audioSettingView.callBack = { haveSpeak, noHaveSpeak in
|
|
|
|
|
|
BFLog(message: "haveSpeak is\(haveSpeak),noHaveSpeak is\(noHaveSpeak)")
|
|
BFLog(message: "haveSpeak is\(haveSpeak),noHaveSpeak is\(noHaveSpeak)")
|
|
}
|
|
}
|
|
@@ -685,33 +685,26 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
audioSettingView.isHidden = false
|
|
audioSettingView.isHidden = false
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/// 删除指定段落的所有字幕 数据
|
|
/// 删除指定段落的所有字幕 数据
|
|
/// - Parameter voiceModel: 删除的音频数据
|
|
/// - Parameter voiceModel: 删除的音频数据
|
|
- func deleteTitles(voiceModel:PQVoiceModel){
|
|
|
|
- BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startTime: \(voiceModel.startTime) model.end: \(voiceModel.endTime)")
|
|
|
|
- for title in itemModels[currItemModelIndex].titleStickers {
|
|
|
|
- if let index = itemModels[currItemModelIndex].titleStickers.firstIndex(of: title) {
|
|
|
|
-
|
|
|
|
- if title.timelineIn >= voiceModel.startTime && title.timelineOut <= voiceModel.endTime{
|
|
|
|
-
|
|
|
|
- //删除前数据存入缓存
|
|
|
|
- let sutbitle = itemModels[currItemModelIndex].titleStickers[index]
|
|
|
|
- events.append(WithDrawModel(type: 4, timestamp: currentAssetProgress.seconds, deletedTittles: [(sutbitle,isStopAtRecordRange)]))
|
|
|
|
-
|
|
|
|
- itemModels[currItemModelIndex].titleStickers.remove(at: index)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
|
|
|
|
-
|
|
|
|
- //清空字幕UI
|
|
|
|
- subtitleLabel.text = ""
|
|
|
|
-
|
|
|
|
|
|
+ func deleteTitles(voiceModel: PQVoiceModel) {
|
|
|
|
+ BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startTime: \(voiceModel.startTime) model.end: \(voiceModel.endTime)")
|
|
|
|
+ for title in itemModels[currItemModelIndex].titleStickers {
|
|
|
|
+ if let index = itemModels[currItemModelIndex].titleStickers.firstIndex(of: title) {
|
|
|
|
+ if title.timelineIn >= voiceModel.startTime, title.timelineOut <= voiceModel.endTime {
|
|
|
|
+ // 删除前数据存入缓存
|
|
|
|
+ let sutbitle = itemModels[currItemModelIndex].titleStickers[index]
|
|
|
|
+ events.append(WithDrawModel(type: 4, timestamp: currentAssetProgress.seconds, deletedTittles: [(sutbitle, isStopAtRecordRange)]))
|
|
|
|
+
|
|
|
|
+ itemModels[currItemModelIndex].titleStickers.remove(at: index)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
|
|
|
|
+
|
|
|
|
+ // 清空字幕UI
|
|
|
|
+ subtitleLabel.text = ""
|
|
}
|
|
}
|
|
|
|
|
|
@objc func deleteRecorded() {
|
|
@objc func deleteRecorded() {
|
|
@@ -721,9 +714,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
drawOrUpdateRecordProgessLable()
|
|
drawOrUpdateRecordProgessLable()
|
|
searchStopAtRecordRange()
|
|
searchStopAtRecordRange()
|
|
events.append(WithDrawModel(type: 3, timestamp: currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)]))
|
|
events.append(WithDrawModel(type: 3, timestamp: currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)]))
|
|
-
|
|
|
|
|
|
+
|
|
deleteTitles(voiceModel: model)
|
|
deleteTitles(voiceModel: model)
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -767,6 +759,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
}
|
|
}
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
assetPlayer?.play()
|
|
assetPlayer?.play()
|
|
|
|
+ // 暂停状态
|
|
|
|
+ (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = true
|
|
} else {
|
|
} else {
|
|
recorderManager.audioRecorder?.recorderProgross = { [weak self] progress in
|
|
recorderManager.audioRecorder?.recorderProgross = { [weak self] progress in
|
|
self?.imageRecordProgress(isRecord: true, progress: progress)
|
|
self?.imageRecordProgress(isRecord: true, progress: progress)
|
|
@@ -800,7 +794,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
@objc func withdrawAction() {
|
|
@objc func withdrawAction() {
|
|
pause()
|
|
pause()
|
|
if let action = events.last {
|
|
if let action = events.last {
|
|
-
|
|
|
|
var jumpTime = action.timestamp
|
|
var jumpTime = action.timestamp
|
|
if action.type == 2 {
|
|
if action.type == 2 {
|
|
// 撤销录制
|
|
// 撤销录制
|
|
@@ -902,7 +895,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
|
|
let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
|
|
elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
|
|
elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
isEndPlay = false
|
|
isEndPlay = false
|
|
|
|
|
|
if elems.count > 0 {
|
|
if elems.count > 0 {
|
|
@@ -982,7 +975,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startTime), \(recordedAudio.endTime),, \(recordedAudio.wavFilePath)")
|
|
|
|
|
|
+ BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startTime), \(recordedAudio.endTime), \(recordedAudio.wavFilePath ?? "")")
|
|
|
|
|
|
// 创建播放器
|
|
// 创建播放器
|
|
if recordPlayer == nil || (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString).lastPathComponent {
|
|
if recordPlayer == nil || (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString).lastPathComponent {
|
|
@@ -1009,7 +1002,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
self?.currentPlayRecordIndex = -1
|
|
self?.currentPlayRecordIndex = -1
|
|
didPlayToEndTime(recordedAudio, newItem)
|
|
didPlayToEndTime(recordedAudio, newItem)
|
|
}
|
|
}
|
|
- _ = recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) { [weak self] time in
|
|
|
|
|
|
+ _ = recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) { time in
|
|
periodicTimeObserver(time, newItem)
|
|
periodicTimeObserver(time, newItem)
|
|
} as? NSKeyValueObservation
|
|
} as? NSKeyValueObservation
|
|
}
|
|
}
|
|
@@ -1022,7 +1015,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
guard let self = self else {
|
|
guard let self = self else {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(self.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale),\(CMTimeGetSeconds(currentT) >= recordedAudio.startTime),\(CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2)")
|
|
|
|
|
|
+ BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(self.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startTime),\(CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2)")
|
|
|
|
|
|
if !hadPrepareToPlayRecord,
|
|
if !hadPrepareToPlayRecord,
|
|
recordPlayer?.currentItem?.duration.timescale != 0,
|
|
recordPlayer?.currentItem?.duration.timescale != 0,
|
|
@@ -1038,7 +1031,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
if finished, self?.isNormalPlaying ?? false {
|
|
if finished, self?.isNormalPlaying ?? false {
|
|
self?.recordPlayer?.play()
|
|
self?.recordPlayer?.play()
|
|
|
|
|
|
- BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(self?.recordPlayer?.currentItem?.duration ?? .zero)), \(self?.recordPlayer?.currentItem?.currentTime().seconds)")
|
|
|
|
|
|
+ BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(self?.recordPlayer?.currentItem?.duration ?? .zero)), \(self?.recordPlayer?.currentItem?.currentTime().seconds ?? 0)")
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -1067,17 +1060,13 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
}
|
|
}
|
|
|
|
|
|
func play() {
|
|
func play() {
|
|
-
|
|
|
|
- BFLog(1, message: "开始播放 \(currentAssetProgress.seconds) \( AVAudioSession.sharedInstance().category)")
|
|
|
|
- //add by ak 播放前设置 AVAudioSession 为播放状态
|
|
|
|
|
|
+ BFLog(1, message: "开始播放 \(currentAssetProgress.seconds) \(AVAudioSession.sharedInstance().category)")
|
|
|
|
+ // add by ak 播放前设置 AVAudioSession 为播放状态
|
|
do {
|
|
do {
|
|
try AVAudioSession.sharedInstance().setCategory(.playback)
|
|
try AVAudioSession.sharedInstance().setCategory(.playback)
|
|
try AVAudioSession.sharedInstance().setActive(true)
|
|
try AVAudioSession.sharedInstance().setActive(true)
|
|
- } catch {
|
|
|
|
|
|
+ } catch {}
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
isNormalPlaying = true
|
|
isNormalPlaying = true
|
|
if isEndPlay {
|
|
if isEndPlay {
|
|
isEndPlay = false
|
|
isEndPlay = false
|
|
@@ -1182,8 +1171,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
// 播放对应的录音音频
|
|
// 播放对应的录音音频
|
|
self?.playRecord(at: time, periodicTimeObserver: { currentT, currentItem in
|
|
self?.playRecord(at: time, periodicTimeObserver: { currentT, currentItem in
|
|
BFLog(message: "播放一段进度:\(currentT),\(currentItem)")
|
|
BFLog(message: "播放一段进度:\(currentT),\(currentItem)")
|
|
- }, didPlayToEndTime: { startT, currentItem in
|
|
|
|
- BFLog(message: "播放一段结束:\(startT),\(currentItem)")
|
|
|
|
|
|
+ }, didPlayToEndTime: { startT, _ in
|
|
|
|
+ BFLog(message: "播放一段结束:\(startT?.endTime ?? 0)")
|
|
}, playFailed: { _, _ in })
|
|
}, playFailed: { _, _ in })
|
|
}
|
|
}
|
|
} as? NSKeyValueObservation
|
|
} as? NSKeyValueObservation
|
|
@@ -1383,6 +1372,8 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
// 更新当前page
|
|
// 更新当前page
|
|
currItemModelIndex = page
|
|
currItemModelIndex = page
|
|
let recordItem = itemModels[currItemModelIndex]
|
|
let recordItem = itemModels[currItemModelIndex]
|
|
|
|
+ // 重绘录音区域
|
|
|
|
+ drawOrUpdateRecordProgessLable()
|
|
// 更新缩略图
|
|
// 更新缩略图
|
|
progressThumV.recordItem = recordItem
|
|
progressThumV.recordItem = recordItem
|
|
progressThumV.isHidden = false
|
|
progressThumV.isHidden = false
|