Skip to content

Commit 6c8e239

Browse files
authored
feat(asr): Add profanity_filter in python-clients (#12)
* feat(asr): Add profanity_filter in python-clients * update patch version for testing * update pre_release version since 0.0.5 already exists in test.pypi.org * set profanity_filter=True to make it discoverable * update package version for testing * Enable profanity_filter in other transcribe example files * Update release version * Older release doesn't work * Pass profanity_filter value to RecognitionConfig * remove PRE_RELEASE from VERSION * revert patch no
1 parent b64aa72 commit 6c8e239

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

riva/client/argparse_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def add_asr_config_argparse_parameters(
8-
parser: argparse.ArgumentParser, max_alternatives: bool = False, word_time_offsets: bool = False
8+
parser: argparse.ArgumentParser, max_alternatives: bool = False, profanity_filter: bool = False, word_time_offsets: bool = False
99
) -> argparse.ArgumentParser:
1010
if word_time_offsets:
1111
parser.add_argument(
@@ -18,6 +18,13 @@ def add_asr_config_argparse_parameters(
1818
type=int,
1919
help="Maximum number of alternative transcripts to return (up to limit configured on server).",
2020
)
21+
if profanity_filter:
22+
parser.add_argument(
23+
"--profanity-filter",
24+
default=False,
25+
action='store_true',
26+
help="Flag that controls the profanity filtering in the generated transcripts",
27+
)
2128
parser.add_argument(
2229
"--automatic-punctuation",
2330
default=False,

scripts/asr/riva_streaming_asr_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def parse_args() -> argparse.Namespace:
3838
"--file-streaming-chunk", type=int, default=1600, help="Number of frames in one chunk sent to server."
3939
)
4040
parser = add_connection_argparse_parameters(parser)
41-
parser = add_asr_config_argparse_parameters(parser, max_alternatives=True, word_time_offsets=True)
41+
parser = add_asr_config_argparse_parameters(parser, max_alternatives=True, profanity_filter=True, word_time_offsets=True)
4242
args = parser.parse_args()
4343
if args.max_alternatives < 1:
4444
parser.error("`--max-alternatives` must be greater than or equal to 1")
@@ -57,6 +57,7 @@ def streaming_transcription_worker(
5757
encoding=riva.client.AudioEncoding.LINEAR_PCM,
5858
language_code=args.language_code,
5959
max_alternatives=args.max_alternatives,
60+
profanity_filter=args.profanity_filter,
6061
enable_automatic_punctuation=args.automatic_punctuation,
6162
verbatim_transcripts=not args.no_verbatim_transcripts,
6263
enable_word_time_offsets=args.word_time_offsets,

scripts/asr/transcribe_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def parse_args() -> argparse.Namespace:
4949
"--print-confidence", action="store_true", help="Whether to print stability and confidence of transcript."
5050
)
5151
parser = add_connection_argparse_parameters(parser)
52-
parser = add_asr_config_argparse_parameters(parser)
52+
parser = add_asr_config_argparse_parameters(parser, profanity_filter=True)
5353
args = parser.parse_args()
5454
if not args.list_devices and args.input_file is None:
5555
parser.error(
@@ -73,6 +73,7 @@ def main() -> None:
7373
encoding=riva.client.AudioEncoding.LINEAR_PCM,
7474
language_code=args.language_code,
7575
max_alternatives=1,
76+
profanity_filter=args.profanity_filter,
7677
enable_automatic_punctuation=args.automatic_punctuation,
7778
verbatim_transcripts=not args.no_verbatim_transcripts,
7879
),

scripts/asr/transcribe_file_offline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_args() -> argparse.Namespace:
1818
)
1919
parser.add_argument("--input-file", required=True, type=Path, help="A path to a local file to transcribe.")
2020
parser = add_connection_argparse_parameters(parser)
21-
parser = add_asr_config_argparse_parameters(parser)
21+
parser = add_asr_config_argparse_parameters(parser, profanity_filter=True)
2222
args = parser.parse_args()
2323
args.input_file = args.input_file.expanduser()
2424
return args
@@ -32,6 +32,7 @@ def main() -> None:
3232
encoding=riva.client.AudioEncoding.LINEAR_PCM,
3333
language_code=args.language_code,
3434
max_alternatives=1,
35+
profanity_filter=args.profanity_filter,
3536
enable_automatic_punctuation=args.automatic_punctuation,
3637
verbatim_transcripts=not args.no_verbatim_transcripts,
3738
)

scripts/asr/transcribe_mic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_args() -> argparse.Namespace:
1818
)
1919
parser.add_argument("--input-device", type=int, default=default_device_index, help="An input audio device to use.")
2020
parser.add_argument("--list-devices", action="store_true", help="List input audio device indices.")
21-
parser = add_asr_config_argparse_parameters(parser)
21+
parser = add_asr_config_argparse_parameters(parser, profanity_filter=True)
2222
parser = add_connection_argparse_parameters(parser)
2323
parser.add_argument(
2424
"--sample-rate-hz",
@@ -48,6 +48,7 @@ def main() -> None:
4848
encoding=riva.client.AudioEncoding.LINEAR_PCM,
4949
language_code=args.language_code,
5050
max_alternatives=1,
51+
profanity_filter=args.profanity_filter,
5152
enable_automatic_punctuation=args.automatic_punctuation,
5253
verbatim_transcripts=not args.no_verbatim_transcripts,
5354
sample_rate_hertz=args.sample_rate_hz,

0 commit comments

Comments
 (0)