|
@@ -15,8 +15,9 @@ import Photos
|
|
|
import UIKit
|
|
|
|
|
|
struct WithDrawModel {
|
|
|
- var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束
|
|
|
+ var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束 3: 删除录音
|
|
|
var timestamp: Double
|
|
|
+ var deletedVoices : [(PQVoiceModel, Int)]?
|
|
|
}
|
|
|
|
|
|
public class BFRecordScreenController: BFBaseViewController {
|
|
@@ -30,6 +31,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
var currItemModelIndex = 0
|
|
|
public var itemModels = [BFRecordItemModel]()
|
|
|
+ var showSubtitleIndex = 0
|
|
|
// var shouldPlayRecordIndex:Int = -1 // 当前应该播放的录音资源序号
|
|
|
var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
|
|
|
var isRecording = false { // 是否正在录音
|
|
@@ -38,6 +40,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
changeVoiceBtn.isHidden = isRecording
|
|
|
recordBtn.setTitle(isRecording ? "松手 完成" : "按住 说话", for: .normal)
|
|
|
recordBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#28BE67", alpha: isRecording ? 0.6 : 1)
|
|
|
+ playBtn.isSelected = isRecording
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,16 +91,33 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if let sself = self, let model = model, FileManager.default.fileExists(atPath: model.wavFilePath ?? "") {
|
|
|
// 加入到语音数组里
|
|
|
// TODO: 原逻辑要删除新录音后边的数据, 新逻辑是覆盖则删除
|
|
|
+ model.endTime = sself.currentAssetProgress.seconds
|
|
|
+
|
|
|
+ let newRange = CMTimeRange(start: CMTime(seconds: model.startTime, preferredTimescale: 1000), end: CMTime(seconds: model.endTime, preferredTimescale: 1000))
|
|
|
+
|
|
|
+ var deletedVoices = [(PQVoiceModel, Int)]()
|
|
|
+
|
|
|
for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
|
|
|
- if model.endTime > m.startTime && model.endTime <= m.endTime
|
|
|
- || model.startTime <= m.startTime && model.startTime > m.endTime
|
|
|
- {
|
|
|
- sself.itemModels[sself.currItemModelIndex].voiceStickers.remove(at: i)
|
|
|
+ let originRange = CMTimeRange(start: CMTime(seconds: m.startTime, preferredTimescale: 1000), end: CMTime(seconds: m.endTime, preferredTimescale: 1000))
|
|
|
+
|
|
|
+ if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0{
|
|
|
+ deletedVoices.append((m, i))
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
+ sself.itemModels[sself.currItemModelIndex].voiceStickers.removeAll { m in
|
|
|
+ let originRange = CMTimeRange(start: CMTime(seconds: m.startTime, preferredTimescale: 1000), end: CMTime(seconds: m.endTime, preferredTimescale: 1000))
|
|
|
+ return CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0
|
|
|
+ }
|
|
|
BFLog(1, message: "添加录音文件:\(model.startTime) -- \(model.endTime)")
|
|
|
-
|
|
|
+ sself.withDrawBtn.setTitle("撤销录制", for: .normal)
|
|
|
+ var event = sself.events.last
|
|
|
+ if event != nil {
|
|
|
+ event!.deletedVoices = deletedVoices
|
|
|
+ sself.events.removeLast()
|
|
|
+ sself.events.append(event!)
|
|
|
+ }
|
|
|
+
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
|
|
|
|
|
|
sself.drawOrUpdateRecordProgessLable()
|
|
@@ -158,6 +178,16 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
return btn
|
|
|
}()
|
|
|
+ lazy var deleteRecordBtn: UIButton = {
|
|
|
+ let btn = UIButton(type: .custom)
|
|
|
+ btn.backgroundColor = .red
|
|
|
+ btn.alpha = 0.5
|
|
|
+ btn.setTitle("删除录制", for: .normal)
|
|
|
+ btn.adjustsImageWhenHighlighted = false
|
|
|
+ btn.addTarget(self, action: #selector(deleteRecorded), for: .touchUpInside)
|
|
|
+ btn.isHidden = true
|
|
|
+ return btn
|
|
|
+ }()
|
|
|
|
|
|
lazy var withDrawBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
@@ -257,16 +287,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
// 显示字幕
|
|
|
lazy var subtitleLabel: PQSubTitleLabel = {
|
|
|
- let test = ""
|
|
|
- let leftPoint: CGFloat = 37
|
|
|
- let height = sizeWithText(text: test, font: UIFont.boldSystemFont(ofSize: 70 * 375 / 1080), size: CGSize(width: cScreenWidth - leftPoint * 2, height: 102))
|
|
|
-
|
|
|
- let subtitleLabel = PQSubTitleLabel(frame: CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height.height, width: cScreenWidth - 37 * 2, height: height.height))
|
|
|
+ let subtitleLabel = PQSubTitleLabel()
|
|
|
subtitleLabel.textAlignment = .center
|
|
|
- subtitleLabel.text = test
|
|
|
-
|
|
|
subtitleLabel.numberOfLines = 0
|
|
|
- subtitleLabel.lineBreakMode = .byClipping
|
|
|
+ subtitleLabel.lineBreakMode = .byWordWrapping
|
|
|
subtitleLabel.isUserInteractionEnabled = true
|
|
|
subtitleLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(editSubtitle)))
|
|
|
return subtitleLabel
|
|
@@ -392,6 +416,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
bottomeView.addSubview(progreddL)
|
|
|
// view.addSubview(toolV)
|
|
|
bottomeView.addSubview(recordBtn)
|
|
|
+ bottomeView.addSubview(deleteRecordBtn)
|
|
|
bottomeView.addSubview(withDrawBtn)
|
|
|
// bottomeView.addSubview(changeVoiceBtn)
|
|
|
bottomeView.addSubview(progressThumV)
|
|
@@ -416,9 +441,16 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
self?.setSubtitleStyle(settingModel: subtitileModel.setting)
|
|
|
}
|
|
|
- subtitleEditView.editSubtitleDone = { [weak self] newtext in
|
|
|
+ subtitleEditView.editSubtitleDone = { [weak self] newtext ,index in
|
|
|
+ //1,刷新 UI
|
|
|
self?.subtitleLabel.text = newtext
|
|
|
- }
|
|
|
+
|
|
|
+ self?.setSubtitleStyle(settingModel: (self?.subtitleSettingView.subtitle.setting)!)
|
|
|
+
|
|
|
+ //更新缓存数据
|
|
|
+ if(index < (self?.itemModels[(self?.currItemModelIndex ?? 0)].titleStickers.count ?? 0)){
|
|
|
+ self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers[index].text = newtext}
|
|
|
+ }
|
|
|
|
|
|
layoutsubview()
|
|
|
|
|
@@ -426,25 +458,30 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
@objc func editSubtitle() {
|
|
|
- BFLog(message: "编辑字幕")
|
|
|
+ BFLog(message: "编辑字幕 index:\(showSubtitleIndex)")
|
|
|
subtitleEditView.isHidden = false
|
|
|
subtitleEditView.textView.becomeFirstResponder()
|
|
|
- subtitleEditView.setNewText(text: subtitleLabel.text ?? "")
|
|
|
+ subtitleEditView.setNewText(text: subtitleLabel.text ?? "",index: showSubtitleIndex)
|
|
|
}
|
|
|
|
|
|
/// 更新字幕,在回放时使用
|
|
|
/// - Parameter time: 当前播放的进度
|
|
|
func updateSubtitle(time: CMTime) {
|
|
|
var findShowSubtitle: PQEditSubTitleModel?
|
|
|
- for subtitle in itemModels[currItemModelIndex].titleStickers {
|
|
|
- if subtitle.timelineIn <= CMTimeGetSeconds(time) * 1_000_000, subtitle.timelineOut >= CMTimeGetSeconds(time) * 1_000_000 {
|
|
|
+ for (index,subtitle) in itemModels[currItemModelIndex].titleStickers.enumerated() {
|
|
|
+ if subtitle.timelineIn <= CMTimeGetSeconds(time) , subtitle.timelineOut >= CMTimeGetSeconds(time) {
|
|
|
findShowSubtitle = subtitle
|
|
|
BFLog(message: "找到要显示的字幕 in \(findShowSubtitle?.timelineIn ?? 0.0) out \(findShowSubtitle?.timelineOut ?? 0.0) text:\(findShowSubtitle?.text ?? "") currTime is \(CMTimeGetSeconds(time))")
|
|
|
+ showSubtitleIndex = index
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if findShowSubtitle != nil {
|
|
|
subtitleLabel.text = findShowSubtitle?.text
|
|
|
+ setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
|
|
|
+
|
|
|
+ }else{
|
|
|
+ subtitleLabel.text = ""
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -459,15 +496,17 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
subtitleLabel.textColor = settingModel.fontColor
|
|
|
|
|
|
let leftPoint: CGFloat = 37
|
|
|
- let height = sizeWithText(text: subtitleLabel.text ?? "", font: UIFont.systemFont(ofSize: CGFloat(settingModel.subtitleSize * 375 / 1080)), size: CGSize(width: cScreenWidth - leftPoint * 2, height: 102))
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ let height = sizeTextFits(attributedText: nil, text: subtitleLabel.text ?? "", numberOfLines: 0, font: subtitleLabel.font, maxSize: CGSize(width: cScreenWidth - leftPoint * 2, height: CGFloat.greatestFiniteMagnitude)).height
|
|
|
+
|
|
|
// 下 //设置位置
|
|
|
if subtitleSettingView.subtitle.setting.subtitlePoint == 0 {
|
|
|
- subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height.height, width: cScreenWidth - 37 * 2, height: height.height)
|
|
|
+ subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height, width: cScreenWidth - 37 * 2, height: height)
|
|
|
} else if subtitleSettingView.subtitle.setting.subtitlePoint == 1 { // 中
|
|
|
- subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth / 2.0 - height.height / 2.0, width: cScreenWidth - 37 * 2, height: height.height)
|
|
|
+ subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth / 2.0 - height / 2.0, width: cScreenWidth - 37 * 2, height: height)
|
|
|
} else { // 上
|
|
|
- subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.12, width: cScreenWidth - 37 * 2, height: height.height)
|
|
|
+ subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.12, width: cScreenWidth - 37 * 2, height: height)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -501,6 +540,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
make.height.equalTo(42)
|
|
|
make.top.equalTo(withDrawBtn).offset(6)
|
|
|
}
|
|
|
+ deleteRecordBtn.snp.makeConstraints { make in
|
|
|
+ make.left.equalTo(withDrawBtn.snp.right)
|
|
|
+ make.right.equalTo(-65)
|
|
|
+ make.height.equalTo(42)
|
|
|
+ make.top.equalTo(withDrawBtn).offset(6)
|
|
|
+ }
|
|
|
|
|
|
// openCameraBtn.snp.makeConstraints { make in
|
|
|
// make.right.equalToSuperview().offset(-12)
|
|
@@ -610,16 +655,34 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
audioSettingView.isHidden = false
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @objc func deleteRecorded(){
|
|
|
+ if isStopAtRecordRange != -1, isStopAtRecordRange < itemModels[currItemModelIndex].voiceStickers.count {
|
|
|
+ let model = itemModels[currItemModelIndex].voiceStickers[isStopAtRecordRange]
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.remove(at: isStopAtRecordRange)
|
|
|
+ drawOrUpdateRecordProgessLable()
|
|
|
+ searchStopAtRecordRange()
|
|
|
+ events.append(WithDrawModel(type: 3, timestamp: self.currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)]))
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@objc func startRecord() {
|
|
|
BFLog(1, message: "start \(UIControl.Event.touchDown)")
|
|
|
|
|
|
+ // 停止进度条滚动
|
|
|
let point = progressThumV.progressView.contentOffset
|
|
|
progressThumV.progressView.setContentOffset(point, animated: false)
|
|
|
|
|
|
- isRecording = true
|
|
|
pause()
|
|
|
+ isRecording = true
|
|
|
|
|
|
+ let model = PQVoiceModel()
|
|
|
+ model.startTime = currentAssetProgress.seconds
|
|
|
+ model.volume = 100
|
|
|
+ recorderManager.voiceModel = model
|
|
|
+ recorderManager.startRecord(index: 1)
|
|
|
+
|
|
|
movie?.startProcessing()
|
|
|
assetPlayer?.volume = 0
|
|
|
assetPlayer?.play()
|
|
@@ -629,11 +692,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
avatarView.beginRecord()
|
|
|
}
|
|
|
|
|
|
- let model = PQVoiceModel()
|
|
|
- model.startTime = currentAssetProgress.seconds
|
|
|
- model.volume = 100
|
|
|
- recorderManager.voiceModel = model
|
|
|
- recorderManager.startRecord(index: 1)
|
|
|
+
|
|
|
|
|
|
// 添加撤销记录点
|
|
|
events.append(WithDrawModel(type: 2, timestamp: model.startTime))
|
|
@@ -657,14 +716,13 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
DispatchQueue.global().async {
|
|
|
self.speechTranscriberUtil?.endTranscriber()
|
|
|
}
|
|
|
- playBtn.isSelected = true
|
|
|
+// playBtn.isSelected = true
|
|
|
// 存储录音
|
|
|
isRecording = false
|
|
|
+ pause()
|
|
|
|
|
|
- recorderManager.voiceModel?.endTime = currentAssetProgress.seconds
|
|
|
recorderManager.endRecord()
|
|
|
|
|
|
- pause()
|
|
|
if !avatarView.isHidden {
|
|
|
avatarView.endRecord()
|
|
|
}
|
|
@@ -688,10 +746,35 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}) {
|
|
|
let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
|
|
|
itemModels[currItemModelIndex].voiceStickers.remove(at: modelIndex)
|
|
|
+
|
|
|
+ var tuples = action.deletedVoices
|
|
|
+ if tuples != nil, tuples!.count > 0 {
|
|
|
+ tuples!.sort { tuple1, tuple2 in
|
|
|
+ tuple1.1 < tuple2.1
|
|
|
+ }
|
|
|
+ tuples?.forEach({ tuple in
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
drawOrUpdateRecordProgessLable()
|
|
|
jumpTime = model.startTime
|
|
|
}
|
|
|
- } else {}
|
|
|
+ } else if action.type == 3 {
|
|
|
+ // 删除录音
|
|
|
+ var tuples = action.deletedVoices
|
|
|
+ if tuples != nil, tuples!.count > 0 {
|
|
|
+ tuples!.sort { tuple1, tuple2 in
|
|
|
+ tuple1.1 < tuple2.1
|
|
|
+ }
|
|
|
+ tuples?.forEach({ tuple in
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ drawOrUpdateRecordProgessLable()
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
events.removeLast()
|
|
|
let dur = itemModels[currItemModelIndex].materialDuraion
|
|
|
if dur > 0 {
|
|
@@ -701,6 +784,13 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
hadPrepareToPlayRecord = false
|
|
|
progressThumV.progress = jumpTime
|
|
|
}
|
|
|
+
|
|
|
+ if let event = events.last, event.type == 2{
|
|
|
+ withDrawBtn.setTitle("撤销录制", for: .normal)
|
|
|
+ }else{
|
|
|
+ withDrawBtn.setTitle("撤销", for: .normal)
|
|
|
+ }
|
|
|
+ searchStopAtRecordRange()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -715,6 +805,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
searchStopAtRecordRange()
|
|
|
} else {
|
|
|
events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress.seconds))
|
|
|
+ withDrawBtn.setTitle("撤销", for: .normal)
|
|
|
play()
|
|
|
}
|
|
|
}
|
|
@@ -742,10 +833,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
hadPrepareToPlayRecord = false
|
|
|
BFLog(1, message: isDragingProgressSlder ? "drag false" : "drag tr")
|
|
|
searchStopAtRecordRange()
|
|
|
+ withDrawBtn.setTitle("撤销", for: .normal)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func searchStopAtRecordRange() {
|
|
|
- // TODO: 判断是否停止录音区间,是则删除相关录音,画笔,头像,字幕
|
|
|
+ // TODO: 滑动,播放暂停,撤销时,判断是否停止录音区间,是则删除相关录音,画笔,头像,字幕
|
|
|
let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
|
|
|
elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
|
|
|
}
|
|
@@ -753,11 +846,17 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
if elems.count > 0 {
|
|
|
// TODO: 停在了录音区间,显示删除按钮
|
|
|
+ deleteRecordBtn.isHidden = false
|
|
|
+ recordBtn.isHidden = true
|
|
|
+
|
|
|
isStopAtRecordRange = elems.first!.0
|
|
|
- BFLog(1, message: "停在了录音区间 里")
|
|
|
+ BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange)")
|
|
|
} else {
|
|
|
+ deleteRecordBtn.isHidden = true
|
|
|
+ recordBtn.isHidden = false
|
|
|
+
|
|
|
isStopAtRecordRange = -1
|
|
|
- BFLog(1, message: "停在了录音区间 外")
|
|
|
+ BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange)")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -980,10 +1079,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
assetPlayer?.volume = 0
|
|
|
avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) { [weak self] time in
|
|
|
// 进度监控
|
|
|
-
|
|
|
- self?.currentAssetProgress = time
|
|
|
- BFLog(1, message: "curr:\(CMTimeGetSeconds(time))")
|
|
|
- if CMTimeGetSeconds(item?.duration ?? CMTime.zero) > 0 {
|
|
|
+ self?.currentAssetProgress = CMTime(seconds: time.seconds, preferredTimescale: 1000)
|
|
|
+ BFLog(1, message: "curr:\(CMTimeGetSeconds(self?.currentAssetProgress ?? .zero))")
|
|
|
+ if CMTimeGetSeconds(item.duration) > 0 {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
|
|
|
let su = !(self?.isDragingProgressSlder ?? false) || (self?.isRecording ?? false && self?.isNormalPlaying ?? false)
|
|
@@ -1032,12 +1130,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
func changeProgress(progress: Float) {
|
|
|
if let duration = assetPlayer?.currentItem?.duration {
|
|
|
- currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 100), timescale: 100)
|
|
|
+ currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self!.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
|
|
|
}
|
|
|
|
|
|
- assetPlayer!.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { _ in
|
|
|
+ assetPlayer!.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000)) { _ in
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1094,16 +1192,21 @@ extension BFRecordScreenController: PQSpeechTranscriberUtilDelegate {
|
|
|
|
|
|
BFLog(message: "识别结果:dicResult is \(String(describing: dicResult)) \((payload?["result"])!)")
|
|
|
DispatchQueue.main.async {
|
|
|
- // 1,显示字幕
|
|
|
-// self.subtitleLabel.text = ((payload?["result"]) as? String) ?? ""
|
|
|
- self.setSubtitleStyle(settingModel: self.subtitleSettingView.subtitle.setting)
|
|
|
-
|
|
|
+
|
|
|
// 2,保存字幕数据
|
|
|
let newSubtitle = PQEditSubTitleModel()
|
|
|
newSubtitle.timelineIn = self.itemModels[self.currItemModelIndex].titleStickers.last?.timelineOut ?? 0
|
|
|
// 当前已处理的音频时长,单位:毫秒。
|
|
|
- newSubtitle.timelineOut = Float64(((payload?["time"]) as? Int) ?? 0) * 1_000_000
|
|
|
- newSubtitle.text = ((payload?["result"]) as? String) ?? ""
|
|
|
+
|
|
|
+ newSubtitle.timelineOut = Float64(((payload?["time"]) as? Int) ?? 0) / 1_000.0 + (self.recorderManager.voiceModel?.startTime ?? 0.0)
|
|
|
+ var showText = ((payload?["result"]) as? String) ?? ""
|
|
|
+ if(showText.count > 30){
|
|
|
+ showText = showText.substring(to: 30)
|
|
|
+ showText += "..."
|
|
|
+ }
|
|
|
+ newSubtitle.text = showText
|
|
|
+
|
|
|
+ BFLog(message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn) timelineOut \(newSubtitle.timelineOut) text \(newSubtitle.text)")
|
|
|
newSubtitle.setting = self.subtitleSettingView.subtitle.setting
|
|
|
|
|
|
self.itemModels[self.currItemModelIndex].titleStickers.append(newSubtitle)
|