Committed by
GitHub
Use parse options to parse arguments from sherpa-onnx-microphone (#237)
正在显示
1 个修改的文件
包含
18 行增加
和
36 行删除
| @@ -36,53 +36,35 @@ static void Handler(int32_t sig) { | @@ -36,53 +36,35 @@ static void Handler(int32_t sig) { | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | int32_t main(int32_t argc, char *argv[]) { | 38 | int32_t main(int32_t argc, char *argv[]) { |
| 39 | - if (argc < 5 || argc > 7) { | ||
| 40 | - const char *usage = R"usage( | 39 | + signal(SIGINT, Handler); |
| 40 | + | ||
| 41 | + const char *kUsageMessage = R"usage( | ||
| 42 | +This program uses streaming models with microphone for speech recognition. | ||
| 41 | Usage: | 43 | Usage: |
| 42 | - ./bin/sherpa-onnx-microphone \ | ||
| 43 | - /path/to/tokens.txt \ | ||
| 44 | - /path/to/encoder.onnx\ | ||
| 45 | - /path/to/decoder.onnx\ | ||
| 46 | - /path/to/joiner.onnx\ | ||
| 47 | - [num_threads [decoding_method]] | ||
| 48 | 44 | ||
| 49 | -Default value for num_threads is 2. | ||
| 50 | -Valid values for decoding_method: greedy_search (default), modified_beam_search. | 45 | + ./bin/sherpa-onnx-microphone \ |
| 46 | + --tokens=/path/to/tokens.txt \ | ||
| 47 | + --encoder=/path/to/encoder.onnx \ | ||
| 48 | + --decoder=/path/to/decoder.onnx \ | ||
| 49 | + --joiner=/path/to/joiner.onnx \ | ||
| 50 | + --provider=cpu \ | ||
| 51 | + --num-threads=1 \ | ||
| 52 | + --decoding-method=greedy_search | ||
| 51 | 53 | ||
| 52 | Please refer to | 54 | Please refer to |
| 53 | https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html | 55 | https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html |
| 54 | for a list of pre-trained models to download. | 56 | for a list of pre-trained models to download. |
| 55 | )usage"; | 57 | )usage"; |
| 56 | - fprintf(stderr, "%s\n", usage); | ||
| 57 | - fprintf(stderr, "argc, %d\n", argc); | ||
| 58 | - | ||
| 59 | - return 0; | ||
| 60 | - } | ||
| 61 | - signal(SIGINT, Handler); | ||
| 62 | 58 | ||
| 59 | + sherpa_onnx::ParseOptions po(kUsageMessage); | ||
| 63 | sherpa_onnx::OnlineRecognizerConfig config; | 60 | sherpa_onnx::OnlineRecognizerConfig config; |
| 64 | - config.model_config.tokens = argv[1]; | ||
| 65 | 61 | ||
| 66 | - config.model_config.debug = false; | ||
| 67 | - config.model_config.encoder_filename = argv[2]; | ||
| 68 | - config.model_config.decoder_filename = argv[3]; | ||
| 69 | - config.model_config.joiner_filename = argv[4]; | ||
| 70 | - | ||
| 71 | - config.model_config.num_threads = 2; | ||
| 72 | - if (argc == 6 && atoi(argv[5]) > 0) { | ||
| 73 | - config.model_config.num_threads = atoi(argv[5]); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - if (argc == 7) { | ||
| 77 | - config.decoding_method = argv[6]; | 62 | + config.Register(&po); |
| 63 | + po.Read(argc, argv); | ||
| 64 | + if (po.NumArgs() != 0) { | ||
| 65 | + po.PrintUsage(); | ||
| 66 | + exit(EXIT_FAILURE); | ||
| 78 | } | 67 | } |
| 79 | - config.max_active_paths = 4; | ||
| 80 | - | ||
| 81 | - config.enable_endpoint = true; | ||
| 82 | - | ||
| 83 | - config.endpoint_config.rule1.min_trailing_silence = 2.4; | ||
| 84 | - config.endpoint_config.rule2.min_trailing_silence = 1.2; | ||
| 85 | - config.endpoint_config.rule3.min_utterance_length = 300; | ||
| 86 | 68 | ||
| 87 | fprintf(stderr, "%s\n", config.ToString().c_str()); | 69 | fprintf(stderr, "%s\n", config.ToString().c_str()); |
| 88 | 70 |
-
请 注册 或 登录 后发表评论