Skip to content

Commit bdb653a

Browse files
authored
Turn 'pyannote' into an optional dependency (#122)
* 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. * Add 'requirements-metrics.txt' to unit test requirements.
1 parent 6be8ea9 commit bdb653a

6 files changed

Lines changed: 69 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
python-version: ${{ matrix.python-version }}
2323

2424
- name: Install dependencies
25-
run: pip3 install -r requirements.txt -r requirements-dev.txt
25+
run: pip3 install -r requirements.txt -r requirements-dev.txt -r requirements-metrics.txt
2626

2727
- name: Lint
2828
run: make lint

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: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,74 @@
11
"""Entrypoint for SM metrics"""
22

33
import argparse
4+
import sys
45

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

820

921
def main():
10-
parser = argparse.ArgumentParser(description="Your CLI description")
22+
parser = argparse.ArgumentParser(
23+
description="Speechmatics metrics tool for WER and diarization"
24+
)
1125

1226
# Create subparsers
1327
subparsers = parser.add_subparsers(
1428
dest="mode", help="Metrics mode. Choose from 'wer' or 'diarization'"
1529
)
16-
subparsers.required = True # Make sure a subparser id always provided
30+
subparsers.required = True # Make sure a subparser is always provided
1731

18-
wer_parser = subparsers.add_parser("wer", help="Entrypoint for WER metrics")
19-
wer_metrics.get_wer_args(wer_parser)
32+
if WER_AVAILABLE:
33+
wer_parser = subparsers.add_parser("wer", help="Entrypoint for WER metrics")
34+
wer_metrics.get_wer_args(wer_parser)
35+
else:
36+
wer_parser = subparsers.add_parser(
37+
"wer", help="Entrypoint for WER metrics (requires additional dependencies)"
38+
)
2039

21-
diarization_parser = subparsers.add_parser(
22-
"diarization", help="Entrypoint for diarization metrics"
23-
)
24-
diarization_metrics.get_diarization_args(diarization_parser)
40+
if DIARIZATION_AVAILABLE:
41+
diarization_parser = subparsers.add_parser(
42+
"diarization", help="Entrypoint for diarization metrics"
43+
)
44+
diarization_metrics.get_diarization_args(diarization_parser)
45+
else:
46+
diarization_parser = subparsers.add_parser(
47+
"diarization",
48+
help="Entrypoint for diarization metrics (requires pyannote dependencies)",
49+
)
50+
diarization_parser.add_argument(
51+
"--help-install",
52+
action="store_true",
53+
help="Show instructions for installing diarization dependencies",
54+
)
2555

2656
args = parser.parse_args()
2757

2858
if args.mode == "wer":
29-
wer_metrics.main(args)
59+
if WER_AVAILABLE:
60+
wer_metrics.main(args)
61+
else:
62+
print("Error: WER metrics require additional dependencies.")
63+
print("Please install them with: pip install speechmatics-python[metrics]")
64+
sys.exit(1)
3065
elif args.mode == "diarization":
31-
diarization_metrics.main(args)
66+
if DIARIZATION_AVAILABLE:
67+
diarization_metrics.main(args)
68+
else:
69+
print("Error: Diarization metrics require additional dependencies.")
70+
print("Please install them with: pip install speechmatics-python[metrics]")
71+
sys.exit(1)
3272
else:
3373
print("Unsupported mode. Please use 'wer' or 'diarization'")
3474

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def get_version(fname):
6969
long_description_content_type="text/markdown",
7070
install_requires=read_list("requirements.txt"),
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)