正在显示
5 个修改的文件
包含
61 行增加
和
7 行删除
| 1 | 1 | ||
| 2 | CUR_DIR :=$(shell pwd) | 2 | CUR_DIR :=$(shell pwd) |
| 3 | 3 | ||
| 4 | -CFLAGS := -I ../ | 4 | +CFLAGS := -I ../ -I ../build/_deps/cargs-src/include/ |
| 5 | LDFLAGS := -L ../build/lib | 5 | LDFLAGS := -L ../build/lib |
| 6 | LDFLAGS += -L ../build/_deps/onnxruntime-src/lib | 6 | LDFLAGS += -L ../build/_deps/onnxruntime-src/lib |
| 7 | -LDFLAGS += -lsherpa-onnx-c-api -lsherpa-onnx-core -lonnxruntime -lkaldi-native-fbank-core | 7 | +LDFLAGS += -lsherpa-onnx-c-api -lsherpa-onnx-core -lonnxruntime -lkaldi-native-fbank-core -lcargs |
| 8 | LDFLAGS += -Wl,-rpath,${CUR_DIR}/../build/lib | 8 | LDFLAGS += -Wl,-rpath,${CUR_DIR}/../build/lib |
| 9 | LDFLAGS += -Wl,-rpath,${CUR_DIR}/../build/_deps/onnxruntime-src/lib | 9 | LDFLAGS += -Wl,-rpath,${CUR_DIR}/../build/_deps/onnxruntime-src/lib |
| 10 | 10 |
| @@ -52,7 +52,21 @@ static struct cag_option options[] = { | @@ -52,7 +52,21 @@ static struct cag_option options[] = { | ||
| 52 | .access_name = "decoding-method", | 52 | .access_name = "decoding-method", |
| 53 | .value_name = "decoding-method", | 53 | .value_name = "decoding-method", |
| 54 | .description = | 54 | .description = |
| 55 | - "Decoding method: greedy_search (default), modified_beam_search"}}; | 55 | + "Decoding method: greedy_search (default), modified_beam_search"}, |
| 56 | + {.identifier = 'f', | ||
| 57 | + .access_letters = NULL, | ||
| 58 | + .access_name = "hotwords-file", | ||
| 59 | + .value_name = "hotwords-file", | ||
| 60 | + .description = "The file containing hotwords, one words/phrases per line, " | ||
| 61 | + "and for each phrase the bpe/cjkchar are separated by a " | ||
| 62 | + "space. For example: ▁HE LL O ▁WORLD, 你 好 世 界"}, | ||
| 63 | + {.identifier = 's', | ||
| 64 | + .access_letters = NULL, | ||
| 65 | + .access_name = "hotwords-score", | ||
| 66 | + .value_name = "hotwords-score", | ||
| 67 | + .description = "The bonus score for each token in hotwords. Used only " | ||
| 68 | + "when decoding_method is modified_beam_search"}, | ||
| 69 | +}; | ||
| 56 | 70 | ||
| 57 | const char *kUsage = | 71 | const char *kUsage = |
| 58 | "\n" | 72 | "\n" |
| @@ -130,6 +144,12 @@ int32_t main(int32_t argc, char *argv[]) { | @@ -130,6 +144,12 @@ int32_t main(int32_t argc, char *argv[]) { | ||
| 130 | case 'm': | 144 | case 'm': |
| 131 | config.decoding_method = value; | 145 | config.decoding_method = value; |
| 132 | break; | 146 | break; |
| 147 | + case 'f': | ||
| 148 | + config.hotwords_file = value; | ||
| 149 | + break; | ||
| 150 | + case 's': | ||
| 151 | + config.hotwords_score = atof(value); | ||
| 152 | + break; | ||
| 133 | case 'h': { | 153 | case 'h': { |
| 134 | fprintf(stderr, "%s\n", kUsage); | 154 | fprintf(stderr, "%s\n", kUsage); |
| 135 | exit(0); | 155 | exit(0); |
| @@ -27,8 +27,22 @@ if [ ! -f ./decode-file-c-api ]; then | @@ -27,8 +27,22 @@ if [ ! -f ./decode-file-c-api ]; then | ||
| 27 | fi | 27 | fi |
| 28 | 28 | ||
| 29 | ./decode-file-c-api \ | 29 | ./decode-file-c-api \ |
| 30 | - ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt \ | ||
| 31 | - ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.onnx \ | ||
| 32 | - ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx \ | ||
| 33 | - ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.onnx \ | 30 | + --tokens=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt \ |
| 31 | + --encoder=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.onnx \ | ||
| 32 | + --decoder=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx \ | ||
| 33 | + --joiner=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.onnx \ | ||
| 34 | + ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/test_wavs/0.wav | ||
| 35 | + | ||
| 36 | +# Run with hotwords | ||
| 37 | + | ||
| 38 | +echo "礼 拜 二" > hotwords.txt | ||
| 39 | + | ||
| 40 | +./decode-file-c-api \ | ||
| 41 | + --tokens=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt \ | ||
| 42 | + --encoder=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.onnx \ | ||
| 43 | + --decoder=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx \ | ||
| 44 | + --joiner=./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.onnx \ | ||
| 45 | + --hotwords-file=hotwords.txt \ | ||
| 46 | + --hotwords-score=1.5 \ | ||
| 47 | + --decoding-method=modified_beam_search \ | ||
| 34 | ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/test_wavs/0.wav | 48 | ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/test_wavs/0.wav |
| @@ -80,6 +80,10 @@ SherpaOnnxOnlineRecognizer *CreateOnlineRecognizer( | @@ -80,6 +80,10 @@ SherpaOnnxOnlineRecognizer *CreateOnlineRecognizer( | ||
| 80 | recognizer_config.endpoint_config.rule3.min_utterance_length = | 80 | recognizer_config.endpoint_config.rule3.min_utterance_length = |
| 81 | SHERPA_ONNX_OR(config->rule3_min_utterance_length, 20); | 81 | SHERPA_ONNX_OR(config->rule3_min_utterance_length, 20); |
| 82 | 82 | ||
| 83 | + recognizer_config.hotwords_file = SHERPA_ONNX_OR(config->hotwords_file, ""); | ||
| 84 | + recognizer_config.hotwords_score = | ||
| 85 | + SHERPA_ONNX_OR(config->hotwords_score, 1.5); | ||
| 86 | + | ||
| 83 | if (config->model_config.debug) { | 87 | if (config->model_config.debug) { |
| 84 | fprintf(stderr, "%s\n", recognizer_config.ToString().c_str()); | 88 | fprintf(stderr, "%s\n", recognizer_config.ToString().c_str()); |
| 85 | } | 89 | } |
| @@ -297,6 +301,10 @@ SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer( | @@ -297,6 +301,10 @@ SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer( | ||
| 297 | recognizer_config.max_active_paths = | 301 | recognizer_config.max_active_paths = |
| 298 | SHERPA_ONNX_OR(config->max_active_paths, 4); | 302 | SHERPA_ONNX_OR(config->max_active_paths, 4); |
| 299 | 303 | ||
| 304 | + recognizer_config.hotwords_file = SHERPA_ONNX_OR(config->hotwords_file, ""); | ||
| 305 | + recognizer_config.hotwords_score = | ||
| 306 | + SHERPA_ONNX_OR(config->hotwords_score, 1.5); | ||
| 307 | + | ||
| 300 | if (config->model_config.debug) { | 308 | if (config->model_config.debug) { |
| 301 | fprintf(stderr, "%s\n", recognizer_config.ToString().c_str()); | 309 | fprintf(stderr, "%s\n", recognizer_config.ToString().c_str()); |
| 302 | } | 310 | } |
| @@ -111,6 +111,12 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig { | @@ -111,6 +111,12 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig { | ||
| 111 | /// this value. | 111 | /// this value. |
| 112 | /// Used only when enable_endpoint is not 0. | 112 | /// Used only when enable_endpoint is not 0. |
| 113 | float rule3_min_utterance_length; | 113 | float rule3_min_utterance_length; |
| 114 | + | ||
| 115 | + /// Path to the hotwords. | ||
| 116 | + const char *hotwords_file; | ||
| 117 | + | ||
| 118 | + /// Bonus score for each token in hotwords. | ||
| 119 | + float hotwords_score; | ||
| 114 | } SherpaOnnxOnlineRecognizerConfig; | 120 | } SherpaOnnxOnlineRecognizerConfig; |
| 115 | 121 | ||
| 116 | SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerResult { | 122 | SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerResult { |
| @@ -335,6 +341,12 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerConfig { | @@ -335,6 +341,12 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerConfig { | ||
| 335 | 341 | ||
| 336 | const char *decoding_method; | 342 | const char *decoding_method; |
| 337 | int32_t max_active_paths; | 343 | int32_t max_active_paths; |
| 344 | + | ||
| 345 | + /// Path to the hotwords. | ||
| 346 | + const char *hotwords_file; | ||
| 347 | + | ||
| 348 | + /// Bonus score for each token in hotwords. | ||
| 349 | + float hotwords_score; | ||
| 338 | } SherpaOnnxOfflineRecognizerConfig; | 350 | } SherpaOnnxOfflineRecognizerConfig; |
| 339 | 351 | ||
| 340 | SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizer | 352 | SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizer |
-
请 注册 或 登录 后发表评论