From 9fcb3cc06b4e324f0913d2f61b89becc2baeef1b Mon Sep 17 00:00:00 2001
From: hnluo <haoneng.lhn@alibaba-inc.com>
Date: 星期一, 11 九月 2023 17:40:03 +0800
Subject: [PATCH] Merge pull request #932 from alibaba-damo-academy/dev_lhn
---
funasr/runtime/onnxruntime/src/audio.cpp | 42 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/funasr/runtime/onnxruntime/src/audio.cpp b/funasr/runtime/onnxruntime/src/audio.cpp
index 2ba9c30..94fcefc 100644
--- a/funasr/runtime/onnxruntime/src/audio.cpp
+++ b/funasr/runtime/onnxruntime/src/audio.cpp
@@ -9,6 +9,11 @@
#include "audio.h"
#include "precomp.h"
+
+#if defined(__APPLE__)
+#include <string.h>
+#else
+
extern "C" {
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
@@ -17,6 +22,10 @@
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
}
+
+#endif
+
+
using namespace std;
@@ -245,6 +254,9 @@
}
bool Audio::FfmpegLoad(const char *filename, bool copy2char){
+#if defined(__APPLE__)
+ return false;
+#else
// from file
AVFormatContext* formatContext = avformat_alloc_context();
if (avformat_open_input(&formatContext, filename, NULL, NULL) != 0) {
@@ -403,10 +415,13 @@
}
else
return false;
-
+#endif
}
bool Audio::FfmpegLoad(const char* buf, int n_file_len){
+#if defined(__APPLE__)
+ return false;
+#else
// from buf
char* buf_copy = (char *)malloc(n_file_len);
memcpy(buf_copy, buf, n_file_len);
@@ -577,7 +592,7 @@
}
else
return false;
-
+#endif
}
@@ -980,6 +995,23 @@
}
}
+int Audio::Fetch(float *&dout, int &len, int &flag, float &start_time)
+{
+ if (frame_queue.size() > 0) {
+ AudioFrame *frame = frame_queue.front();
+ frame_queue.pop();
+
+ start_time = (float)(frame->GetStart())/MODEL_SAMPLE_RATE;
+ dout = speech_data + frame->GetStart();
+ len = frame->GetLen();
+ delete frame;
+ flag = S_END;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
void Audio::Padding()
{
float num_samples = speech_len;
@@ -1146,8 +1178,8 @@
}else if(speech_end_i != -1){ // [-1,100]
if(speech_start == -1 or speech_offline_start == -1){
- LOG(ERROR) <<"Vad start is null while vad end is available." ;
- exit(-1);
+ LOG(ERROR) <<"Vad start is null while vad end is available. Set vad start 0" ;
+ speech_start = 0;
}
int start = speech_start*seg_sample;
@@ -1212,4 +1244,4 @@
}
-} // namespace funasr
\ No newline at end of file
+} // namespace funasr
--
Gitblit v1.9.1