|
@@ -34,6 +34,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
public var recordEndHandle: ((_ currentRecord: PQVoiceModel?) -> Void)?
|
|
|
// 字幕按钮点击上报
|
|
|
public var subTitleBtnClickHandle: ((_ isOn: Bool) -> Void)?
|
|
|
+ public var currentRecordId: String? // 当前录制Id
|
|
|
|
|
|
// MARK: - 录制参数
|
|
|
|
|
@@ -484,11 +485,21 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// 录音字幕回调
|
|
|
- recorderManager?.subtitleRecordHandle = { [weak self] asrResult, audioFilePath, _ in
|
|
|
- if asrResult == nil {
|
|
|
+ recorderManager?.subtitleRecordHandle = { [weak self] eventCode, recordId, asrResult, audioFilePath, _ in
|
|
|
+ if asrResult == nil || (asrResult?.count ?? 0) <= 0 {
|
|
|
BFLog(message: "识别结果为空????不能生成字幕数据")
|
|
|
return
|
|
|
}
|
|
|
+ if eventCode == 2 || eventCode == 26 {
|
|
|
+ self?.currentRecordId = nil
|
|
|
+ }
|
|
|
+ if eventCode == 0 {
|
|
|
+ self?.currentRecordId = recordId
|
|
|
+ }
|
|
|
+ // 只有为24时才有字幕返回
|
|
|
+ if eventCode != 24 {
|
|
|
+ return
|
|
|
+ }
|
|
|
DispatchQueue.global().async {
|
|
|
let dicResult: [String: Any]? = jsonStringToDictionary(asrResult!)
|
|
|
let header = dicResult?["header"] as? [String: Any]
|
|
@@ -499,9 +510,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let newSubtitle = PQEditSubTitleModel()
|
|
|
// 任务全局唯一ID,请记录该值,便于排查问题。 每次 startRecorder 和 stopRecoder 之间 task_Id都不会变化
|
|
|
let taskID = header?["task_id"] as? String
|
|
|
- let finish = header?["task_id"] as? String
|
|
|
-
|
|
|
newSubtitle.taskID = taskID ?? ""
|
|
|
+ newSubtitle.recordId = self?.currentRecordId
|
|
|
BFLog(1, message: "对应关系:字幕所属地址:taskID:\(taskID ?? ""),\((audioFilePath ?? "b").replacingOccurrences(of: documensDirectory, with: "")), 开始录音输入:\((self?.recorderManager?.voiceModel?.wavFilePath ?? "aa").replacingOccurrences(of: documensDirectory, with: ""))")
|
|
|
// 这里加300ms 是因为返回结果为了切到字,时长提前一些时间,具体时间官方没说和原音频有关系。这里我们先延后300ms 单位:毫秒。
|
|
|
var tempVoice: PQVoiceModel?
|
|
@@ -510,7 +520,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
self?.itemModels.enumerated().forEach { index, item in
|
|
|
if tempVoice == nil {
|
|
|
tempVoice = item.voiceStickers.first { voice in
|
|
|
- voice.titleTaskId == taskID
|
|
|
+ voice.recordId == self?.currentRecordId
|
|
|
}
|
|
|
if tempVoice != nil {
|
|
|
tempItem = item
|
|
@@ -519,7 +529,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
// 2:如果通过titleTaskId没找到录音文件,则通过
|
|
|
- if tempVoice == nil && (self?.isRecording ?? false) && self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last?.titleTaskId == nil {
|
|
|
+ if tempVoice == nil && (self?.isRecording ?? false) && self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last?.recordId == nil {
|
|
|
BFLog(3, message: "字幕回调-如果通过titleTaskId没找到录音文件:taskID=\(taskID ?? ""),audioFilePath=\(audioFilePath ?? "")")
|
|
|
tempVoice = self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last
|
|
|
}
|
|
@@ -532,9 +542,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(3, message: "字幕回调-最终没找到录音文件:taskID=\(taskID ?? ""),audioFilePath=\(audioFilePath ?? "")")
|
|
|
return
|
|
|
}
|
|
|
- if currentVoice.titleTaskId == nil {
|
|
|
- currentVoice.titleTaskId = taskID
|
|
|
- }
|
|
|
newSubtitle.timelineIn = currentVoice.startCMTime + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
|
|
|
newSubtitle.timelineOut = currentVoice.startCMTime + CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
|
|
|
newSubtitle.audioFilePath = currentVoice.wavFilePath
|
|
@@ -731,11 +738,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if !SWNetRequest.isNetReachabled() {
|
|
|
cShowHUB(superView: view, msg: "网络不佳,字幕可能无法生成")
|
|
|
}
|
|
|
- if(PQENVUtil.shared.channel == "Development"){
|
|
|
+ if PQENVUtil.shared.channel == "Development" {
|
|
|
view.addSubview(neoNuiDebugLabel)
|
|
|
view.addSubview(audioQueueRecoderLabel)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@objc func editSubtitle() {
|
|
@@ -982,7 +988,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
// 从原数组中删除
|
|
|
itemModels[currItemModelIndex].titleStickers.removeAll { m in
|
|
|
- let su = (m.taskID == voiceModel.titleTaskId)
|
|
|
+ let su = (m.recordId == voiceModel.recordId)
|
|
|
if su {
|
|
|
deleteTemp.append(m)
|
|
|
}
|
|
@@ -1021,7 +1027,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
item.endCMTime = item.endCMTime - currDuration
|
|
|
|
|
|
let titlsList = itemModels[currItemModelIndex].titleStickers.filter { tm in
|
|
|
- tm.taskID == item.titleTaskId
|
|
|
+ tm.recordId == item.recordId
|
|
|
}
|
|
|
|
|
|
for titleM in titlsList {
|
|
@@ -1077,6 +1083,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let model = PQVoiceModel()
|
|
|
model.startCMTime = currentAssetProgress
|
|
|
model.currIndex = currItemModelIndex
|
|
|
+ model.recordId = getUniqueId(desc: "recordId")
|
|
|
model.volume = 100
|
|
|
recorderManager?.voiceModel = model
|
|
|
BFLog(3, message: "开始录制-开始:currentAssetProgress=\(currentAssetProgress.seconds),cuInde=\(currItemModelIndex),\(model)")
|
|
@@ -1169,7 +1176,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(2, message: "删除\(voiceModel?.wavFilePath ?? "")对应的字幕 前 count\(subtitleCount)")
|
|
|
if subtitleCount > 0 {
|
|
|
for title in itemModels[currItemModelIndex].titleStickers {
|
|
|
- if title.taskID == voiceModel?.titleTaskId ?? "none" {
|
|
|
+ if title.recordId == voiceModel?.recordId ?? "none" {
|
|
|
if let index = itemModels[currItemModelIndex].titleStickers.firstIndex(of: title) {
|
|
|
itemModels[currItemModelIndex].titleStickers.remove(at: index)
|
|
|
}
|
|
@@ -1253,11 +1260,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 注:之后的录音和字幕增加对应的时长
|
|
|
item.startCMTime = item.startCMTime + currDuration
|
|
|
item.endCMTime = item.endCMTime + currDuration
|
|
|
-
|
|
|
- let titlsList = itemModels[currItemModelIndex].titleStickers.filter({ tm in
|
|
|
- tm.taskID == item.titleTaskId
|
|
|
- })
|
|
|
-
|
|
|
+
|
|
|
+ let titlsList = itemModels[currItemModelIndex].titleStickers.filter { tm in
|
|
|
+ tm.recordId == item.recordId
|
|
|
+ }
|
|
|
+
|
|
|
for titleM in titlsList {
|
|
|
titleM.timelineIn = titleM.timelineIn + currDuration
|
|
|
titleM.timelineOut = titleM.timelineOut + currDuration
|