Use parse options to parse arguments from sherpa-onnx-microphone (#237)
This commit is contained in:
@@ -36,54 +36,36 @@ static void Handler(int32_t sig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t main(int32_t argc, char *argv[]) {
|
int32_t main(int32_t argc, char *argv[]) {
|
||||||
if (argc < 5 || argc > 7) {
|
signal(SIGINT, Handler);
|
||||||
const char *usage = R"usage(
|
|
||||||
Usage:
|
|
||||||
./bin/sherpa-onnx-microphone \
|
|
||||||
/path/to/tokens.txt \
|
|
||||||
/path/to/encoder.onnx\
|
|
||||||
/path/to/decoder.onnx\
|
|
||||||
/path/to/joiner.onnx\
|
|
||||||
[num_threads [decoding_method]]
|
|
||||||
|
|
||||||
Default value for num_threads is 2.
|
const char *kUsageMessage = R"usage(
|
||||||
Valid values for decoding_method: greedy_search (default), modified_beam_search.
|
This program uses streaming models with microphone for speech recognition.
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
./bin/sherpa-onnx-microphone \
|
||||||
|
--tokens=/path/to/tokens.txt \
|
||||||
|
--encoder=/path/to/encoder.onnx \
|
||||||
|
--decoder=/path/to/decoder.onnx \
|
||||||
|
--joiner=/path/to/joiner.onnx \
|
||||||
|
--provider=cpu \
|
||||||
|
--num-threads=1 \
|
||||||
|
--decoding-method=greedy_search
|
||||||
|
|
||||||
Please refer to
|
Please refer to
|
||||||
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
||||||
for a list of pre-trained models to download.
|
for a list of pre-trained models to download.
|
||||||
)usage";
|
)usage";
|
||||||
fprintf(stderr, "%s\n", usage);
|
|
||||||
fprintf(stderr, "argc, %d\n", argc);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
signal(SIGINT, Handler);
|
|
||||||
|
|
||||||
|
sherpa_onnx::ParseOptions po(kUsageMessage);
|
||||||
sherpa_onnx::OnlineRecognizerConfig config;
|
sherpa_onnx::OnlineRecognizerConfig config;
|
||||||
config.model_config.tokens = argv[1];
|
|
||||||
|
|
||||||
config.model_config.debug = false;
|
config.Register(&po);
|
||||||
config.model_config.encoder_filename = argv[2];
|
po.Read(argc, argv);
|
||||||
config.model_config.decoder_filename = argv[3];
|
if (po.NumArgs() != 0) {
|
||||||
config.model_config.joiner_filename = argv[4];
|
po.PrintUsage();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
config.model_config.num_threads = 2;
|
|
||||||
if (argc == 6 && atoi(argv[5]) > 0) {
|
|
||||||
config.model_config.num_threads = atoi(argv[5]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 7) {
|
|
||||||
config.decoding_method = argv[6];
|
|
||||||
}
|
|
||||||
config.max_active_paths = 4;
|
|
||||||
|
|
||||||
config.enable_endpoint = true;
|
|
||||||
|
|
||||||
config.endpoint_config.rule1.min_trailing_silence = 2.4;
|
|
||||||
config.endpoint_config.rule2.min_trailing_silence = 1.2;
|
|
||||||
config.endpoint_config.rule3.min_utterance_length = 300;
|
|
||||||
|
|
||||||
fprintf(stderr, "%s\n", config.ToString().c_str());
|
fprintf(stderr, "%s\n", config.ToString().c_str());
|
||||||
|
|
||||||
if (!config.Validate()) {
|
if (!config.Validate()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user