From b19404889592129c8c0151673d0a7aef0ab601cc Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期四, 14 三月 2024 09:59:45 +0800
Subject: [PATCH] add SwitchArg for funasr-onnx-offline

---
 runtime/onnxruntime/bin/funasr-onnx-offline.cpp |    5 ++++-
 runtime/onnxruntime/include/com-define.h        |    2 ++
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/runtime/onnxruntime/bin/funasr-onnx-offline.cpp b/runtime/onnxruntime/bin/funasr-onnx-offline.cpp
index 7c25515..c2a5236 100644
--- a/runtime/onnxruntime/bin/funasr-onnx-offline.cpp
+++ b/runtime/onnxruntime/bin/funasr-onnx-offline.cpp
@@ -58,6 +58,7 @@
     TCLAP::ValueArg<std::string>    wav_path("", WAV_PATH, "the input could be: wav_path, e.g.: asr_example.wav; pcm_path, e.g.: asr_example.pcm; wav.scp, kaldi style wav list (wav_id \t wav_path)", true, "", "string");
     TCLAP::ValueArg<std::int32_t>   audio_fs("", AUDIO_FS, "the sample rate of audio", false, 16000, "int32_t");
     TCLAP::ValueArg<std::string>    hotword("", HOTWORD, "the hotword file, one hotword perline, Format: Hotword Weight (could be: 闃块噷宸村反 20)", false, "", "string");
+    TCLAP::SwitchArg use_gpu("", USE_GPU, "Whether to use GPU for inference, default is false", false);
 
     cmd.add(model_dir);
     cmd.add(quantize);
@@ -74,6 +75,7 @@
     cmd.add(wav_path);
     cmd.add(audio_fs);
     cmd.add(hotword);
+    cmd.add(use_gpu);
     cmd.parse(argc, argv);
 
     std::map<std::string, std::string> model_path;
@@ -90,7 +92,8 @@
     struct timeval start, end;
     gettimeofday(&start, nullptr);
     int thread_num = 1;
-    FUNASR_HANDLE asr_hanlde=FunOfflineInit(model_path, thread_num, true);
+    bool use_gpu_ = use_gpu.getValue();
+    FUNASR_HANDLE asr_hanlde=FunOfflineInit(model_path, thread_num, use_gpu_);
 
     if (!asr_hanlde)
     {
diff --git a/runtime/onnxruntime/include/com-define.h b/runtime/onnxruntime/include/com-define.h
index a16fc50..6af2527 100644
--- a/runtime/onnxruntime/include/com-define.h
+++ b/runtime/onnxruntime/include/com-define.h
@@ -50,8 +50,10 @@
 #define MODEL_EB_NAME "model_eb.onnx"
 #define QUANT_MODEL_NAME "model_quant.onnx"
 // gpu models
+#define USE_GPU "gpu"
 #define TORCH_MODEL_NAME "model.gpu.torchscripts"
 #define TORCH_QUANT_MODEL_NAME "model.blade.fp16.pt"
+
 #define VAD_CMVN_NAME "vad.mvn"
 #define VAD_CONFIG_NAME "vad.yaml"
 #define AM_CMVN_NAME "am.mvn"

--
Gitblit v1.9.1