From 200bba87f0060cfbc92c6ff45026313c188b6452 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期三, 17 四月 2024 19:14:20 +0800
Subject: [PATCH] sort frame_queue
---
runtime/onnxruntime/src/audio.cpp | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/runtime/onnxruntime/src/audio.cpp b/runtime/onnxruntime/src/audio.cpp
index ef5d5f3..f1285af 100644
--- a/runtime/onnxruntime/src/audio.cpp
+++ b/runtime/onnxruntime/src/audio.cpp
@@ -1111,7 +1111,7 @@
}
}
-void Audio::CutSplit(OfflineStream* offline_stream)
+void Audio::CutSplit(OfflineStream* offline_stream, std::vector<int> &index_vector)
{
std::unique_ptr<VadModel> vad_online_handle = make_unique<FsmnVadOnline>((FsmnVad*)(offline_stream->vad_handle).get());
AudioFrame *frame;
@@ -1138,6 +1138,7 @@
}
int speech_start_i = -1, speech_end_i =-1;
+ std::vector<AudioFrame*> vad_frames;
for(vector<int> vad_segment:vad_segments)
{
if(vad_segment.size() != 2){
@@ -1152,16 +1153,31 @@
}
if(speech_start_i!=-1 && speech_end_i!=-1){
- frame = new AudioFrame();
int start = speech_start_i*seg_sample;
int end = speech_end_i*seg_sample;
+ frame = new AudioFrame(end-start);
frame->SetStart(start);
frame->SetEnd(end);
- frame_queue.push(frame);
+ vad_frames.push_back(frame);
frame = nullptr;
speech_start_i=-1;
speech_end_i=-1;
}
+
+ }
+ // sort
+ {
+ index_vector.clear();
+ index_vector.resize(vad_frames.size());
+ for (int i = 0; i < index_vector.size(); ++i) {
+ index_vector[i] = i;
+ }
+ std::sort(index_vector.begin(), index_vector.end(), [&vad_frames](const int a, const int b) {
+ return vad_frames[a]->len < vad_frames[b]->len;
+ });
+ for (int idx : index_vector) {
+ frame_queue.push(vad_frames[idx]);
+ }
}
}
--
Gitblit v1.9.1