Skip to content

Commit 12dc78b

Browse files
committed
Make metrics dependencies optional via extras_require
BREAKING CHANGE: Metrics functionality now requires explicit installation Previously, all metrics dependencies (pyannote, pandas, jiwer, etc.) were installed by default. This change moves them to an optional '[metrics]' extra to reduce the default installation footprint. Changes: - Move metrics dependencies to requirements-metrics.txt - Configure extras_require in setup.py for optional installation - Add graceful error handling in CLI when dependencies are missing - Update README with installation instructions for metrics features To use metrics functionality after this change: pip install speechmatics-python[metrics] This significantly reduces installation size and time for users who only need the core transcription features, while maintaining full functionality for those who need metrics capabilities.
1 parent 1e7a168 commit 12dc78b

File tree

5 files changed

+63
-20
lines changed

5 files changed

+63
-20
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ To install from PyPI:
99
```bash
1010
pip install speechmatics-python
1111
```
12+
13+
To use the sm-metrics tool for diarization features and speaker identification metrics, install with the optional dependencies:
14+
```bash
15+
pip install speechmatics-python[metrics]
16+
```
1217
To install from source:
1318
```bash
1419
git clone https://github.com/speechmatics/speechmatics-python

asr_metrics/cli.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
11
"""Entrypoint for SM metrics"""
22
import argparse
3+
import sys
34

4-
import asr_metrics.diarization.sm_diarization_metrics.cookbook as diarization_metrics
5-
import asr_metrics.wer.__main__ as wer_metrics
5+
try:
6+
import asr_metrics.wer.__main__ as wer_metrics
7+
WER_AVAILABLE = True
8+
except ImportError:
9+
WER_AVAILABLE = False
10+
11+
try:
12+
import asr_metrics.diarization.sm_diarization_metrics.cookbook as diarization_metrics
13+
DIARIZATION_AVAILABLE = True
14+
except ImportError:
15+
DIARIZATION_AVAILABLE = False
616

717

818
def main():
9-
parser = argparse.ArgumentParser(description="Your CLI description")
19+
parser = argparse.ArgumentParser(description="Speechmatics metrics tool for WER and diarization")
1020

1121
# Create subparsers
1222
subparsers = parser.add_subparsers(
1323
dest="mode", help="Metrics mode. Choose from 'wer' or 'diarization'"
1424
)
15-
subparsers.required = True # Make sure a subparser id always provided
25+
subparsers.required = True # Make sure a subparser is always provided
1626

17-
wer_parser = subparsers.add_parser("wer", help="Entrypoint for WER metrics")
18-
wer_metrics.get_wer_args(wer_parser)
27+
if WER_AVAILABLE:
28+
wer_parser = subparsers.add_parser("wer", help="Entrypoint for WER metrics")
29+
wer_metrics.get_wer_args(wer_parser)
30+
else:
31+
wer_parser = subparsers.add_parser(
32+
"wer", help="Entrypoint for WER metrics (requires additional dependencies)"
33+
)
1934

20-
diarization_parser = subparsers.add_parser(
21-
"diarization", help="Entrypoint for diarization metrics"
22-
)
23-
diarization_metrics.get_diarization_args(diarization_parser)
35+
if DIARIZATION_AVAILABLE:
36+
diarization_parser = subparsers.add_parser(
37+
"diarization", help="Entrypoint for diarization metrics"
38+
)
39+
diarization_metrics.get_diarization_args(diarization_parser)
40+
else:
41+
diarization_parser = subparsers.add_parser(
42+
"diarization", help="Entrypoint for diarization metrics (requires pyannote dependencies)"
43+
)
44+
diarization_parser.add_argument(
45+
"--help-install", action="store_true",
46+
help="Show instructions for installing diarization dependencies"
47+
)
2448

2549
args = parser.parse_args()
2650

2751
if args.mode == "wer":
28-
wer_metrics.main(args)
52+
if WER_AVAILABLE:
53+
wer_metrics.main(args)
54+
else:
55+
print("Error: WER metrics require additional dependencies.")
56+
print("Please install them with: pip install speechmatics-python[metrics]")
57+
sys.exit(1)
2958
elif args.mode == "diarization":
30-
diarization_metrics.main(args)
59+
if DIARIZATION_AVAILABLE:
60+
diarization_metrics.main(args)
61+
else:
62+
print("Error: Diarization metrics require additional dependencies.")
63+
print("Please install them with: pip install speechmatics-python[metrics]")
64+
sys.exit(1)
3165
else:
3266
print("Unsupported mode. Please use 'wer' or 'diarization'")
3367

requirements-metrics.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
docopt
2+
jiwer
3+
more-itertools
4+
pandas
5+
pyannote.core
6+
pyannote.database
7+
regex
8+
tabulate>=0.8.9

requirements.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,3 @@ httpx[http2]~=0.23
33
polling2~=0.5
44
toml~=0.10.2
55
tenacity~=8.2.3
6-
jiwer
7-
regex
8-
more-itertools
9-
pyannote.core
10-
pyannote.database
11-
docopt
12-
tabulate>=0.8.9

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ def get_version(fname):
6767
description="Python library and CLI for Speechmatics",
6868
long_description=read("README.md"),
6969
long_description_content_type="text/markdown",
70-
install_requires=read_list("requirements.txt"),
70+
install_requires=[req for req in read_list("requirements.txt") if not req.startswith("pyannote")],
7171
tests_require=read_list("requirements-dev.txt"),
72+
extras_require={
73+
"metrics": read_list("requirements-metrics.txt"),
74+
},
7275
entry_points={
7376
"console_scripts": [
7477
"speechmatics = speechmatics.cli:main",

0 commit comments

Comments
 (0)