Skip to content

Add homonphone replacer example for Python API. #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/test-offline-transducer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $EXE \
--model-type=nemo_transducer \
./sherpa-onnx-nemo-transducer-giga-am-v2-russian-2025-04-19/test_wavs/example.wav

rm sherpa-onnx-nemo-transducer-giga-am-v2-russian-2025-04-19
rm -rf sherpa-onnx-nemo-transducer-giga-am-v2-russian-2025-04-19


log "------------------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rknn-linux-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
workflow_dispatch:

concurrency:
group: aarch64-linux-gnu-shared-${{ github.ref }}
group: rknn-linux-aarch64-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ def get_args():
""",
)

parser.add_argument(
"--hr-dict-dir",
type=str,
default="",
help="If not empty, it is the jieba dict directory for homophone replacer",
)

parser.add_argument(
"--hr-lexicon",
type=str,
default="",
help="If not empty, it is the lexicon.txt for homophone replacer",
)

parser.add_argument(
"--hr-rule-fsts",
type=str,
default="",
help="If not empty, it is the replace.fst for homophone replacer",
)

parser.add_argument(
"--device-name",
type=str,
Expand Down Expand Up @@ -159,6 +180,9 @@ def create_recognizer(args):
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
blank_penalty=args.blank_penalty,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
return recognizer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ def get_args():
""",
)

parser.add_argument(
"--hr-dict-dir",
type=str,
default="",
help="If not empty, it is the jieba dict directory for homophone replacer",
)

parser.add_argument(
"--hr-lexicon",
type=str,
default="",
help="If not empty, it is the lexicon.txt for homophone replacer",
)

parser.add_argument(
"--hr-rule-fsts",
type=str,
default="",
help="If not empty, it is the replace.fst for homophone replacer",
)

return parser.parse_args()


Expand Down Expand Up @@ -142,6 +163,9 @@ def create_recognizer(args):
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
blank_penalty=args.blank_penalty,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
return recognizer

Expand Down
24 changes: 24 additions & 0 deletions python-api-examples/speech-recognition-from-microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ def get_args():
""",
)

parser.add_argument(
"--hr-dict-dir",
type=str,
default="",
help="If not empty, it is the jieba dict directory for homophone replacer",
)

parser.add_argument(
"--hr-lexicon",
type=str,
default="",
help="If not empty, it is the lexicon.txt for homophone replacer",
)

parser.add_argument(
"--hr-rule-fsts",
type=str,
default="",
help="If not empty, it is the replace.fst for homophone replacer",
)

return parser.parse_args()


Expand All @@ -148,6 +169,9 @@ def create_recognizer(args):
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
blank_penalty=args.blank_penalty,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
return recognizer

Expand Down
23 changes: 23 additions & 0 deletions python-api-examples/speech-recognition-from-url.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ def get_args():
""",
)

parser.add_argument(
"--hr-dict-dir",
type=str,
default="",
help="If not empty, it is the jieba dict directory for homophone replacer",
)

parser.add_argument(
"--hr-lexicon",
type=str,
default="",
help="If not empty, it is the lexicon.txt for homophone replacer",
)

parser.add_argument(
"--hr-rule-fsts",
type=str,
default="",
help="If not empty, it is the replace.fst for homophone replacer",
)

return parser.parse_args()

Expand All @@ -133,6 +153,9 @@ def create_recognizer(args):
rule3_min_utterance_length=300, # it essentially disables this rule
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
return recognizer

Expand Down
36 changes: 36 additions & 0 deletions python-api-examples/vad-with-non-streaming-asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ def get_args():
help="Feature dimension. Must match the one expected by the model",
)

parser.add_argument(
"--hr-dict-dir",
type=str,
default="",
help="If not empty, it is the jieba dict directory for homophone replacer",
)

parser.add_argument(
"--hr-lexicon",
type=str,
default="",
help="If not empty, it is the lexicon.txt for homophone replacer",
)

parser.add_argument(
"--hr-rule-fsts",
type=str,
default="",
help="If not empty, it is the replace.fst for homophone replacer",
)

return parser.parse_args()


Expand Down Expand Up @@ -312,6 +333,9 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
decoding_method=args.decoding_method,
blank_penalty=args.blank_penalty,
debug=args.debug,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
elif args.paraformer:
assert len(args.sense_voice) == 0, args.sense_voice
Expand All @@ -334,6 +358,9 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
feature_dim=args.feature_dim,
decoding_method=args.decoding_method,
debug=args.debug,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
elif args.sense_voice:
assert len(args.whisper_encoder) == 0, args.whisper_encoder
Expand All @@ -352,6 +379,9 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
num_threads=args.num_threads,
use_itn=True,
debug=args.debug,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
elif args.whisper_encoder:
assert_file_exists(args.whisper_encoder)
Expand All @@ -373,6 +403,9 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
language=args.whisper_language,
task=args.whisper_task,
tail_paddings=args.whisper_tail_paddings,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
elif args.moonshine_preprocessor:
assert_file_exists(args.moonshine_preprocessor)
Expand All @@ -389,6 +422,9 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
num_threads=args.num_threads,
decoding_method=args.decoding_method,
debug=args.debug,
hr_dict_dir=args.hr_dict_dir,
hr_rule_fsts=args.hr_rule_fsts,
hr_lexicon=args.hr_lexicon,
)
else:
raise ValueError("Please specify at least one model")
Expand Down
Loading