Skip to content

Commit e1bf28c

Browse files
committed
CTC segmentation - fix {doc,py}tests
1 parent c2ca5f5 commit e1bf28c

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Full dependencies
4444
run: |
4545
pip install -r requirements.txt
46-
pip install --editable .
46+
pip install --editable .[full]
4747
- name: Unittests with pytest
4848
run: |
4949
pytest tests/unittests

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"tqdm",
3232
"huggingface_hub",
3333
],
34+
extras_require={"full": ["ctc-segmentation<1.8,>=1.6.6"],}, # noqa: E231
3435
python_requires=">=3.7",
3536
url="https://speechbrain.github.io/",
3637
)

speechbrain/alignment/ctc_segmentation.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@
99

1010
import numpy as np
1111
import torch
12-
from typeguard import check_argument_types
13-
from typeguard import check_return_type
1412
from typing import List
1513

1614
# speechbrain interface
1715
from speechbrain.pretrained.interfaces import EncoderDecoderASR
1816

1917
# imports for CTC segmentation
20-
from ctc_segmentation import ctc_segmentation
21-
from ctc_segmentation import CtcSegmentationParameters
22-
from ctc_segmentation import determine_utterance_segments
23-
from ctc_segmentation import prepare_text
24-
from ctc_segmentation import prepare_token_list
18+
try:
19+
from ctc_segmentation import ctc_segmentation
20+
from ctc_segmentation import CtcSegmentationParameters
21+
from ctc_segmentation import determine_utterance_segments
22+
from ctc_segmentation import prepare_text
23+
from ctc_segmentation import prepare_token_list
24+
except ImportError:
25+
print(
26+
"ImportError: "
27+
"Is the ctc_segmentation module installed "
28+
"and in your PYTHONPATH?"
29+
)
2530

2631
logger = logging.getLogger(__name__)
2732

@@ -94,7 +99,8 @@ def __init__(self, **kwargs):
9499
def set(self, **kwargs):
95100
"""Update properties.
96101
97-
Args:
102+
Args
103+
----
98104
**kwargs
99105
Key-value dict that contains all properties
100106
with their new values. Unknown properties are ignored.
@@ -230,8 +236,6 @@ def __init__(
230236
**ctc_segmentation_args
231237
Parameters for CTC segmentation.
232238
"""
233-
assert check_argument_types()
234-
235239
# Prepare ASR model
236240
if not (
237241
hasattr(asr_model, "modules")
@@ -350,15 +354,13 @@ def set_config(self, **kwargs):
350354
)
351355
# Parameters for text preparation
352356
if "set_blank" in kwargs:
353-
assert isinstance(kwargs["set_blank"], int)
354-
self.config.blank = kwargs["set_blank"]
357+
self.config.blank = int(kwargs["set_blank"])
355358
if "replace_spaces_with_blanks" in kwargs:
356359
self.config.replace_spaces_with_blanks = bool(
357360
kwargs["replace_spaces_with_blanks"]
358361
)
359362
if "kaldi_style_text" in kwargs:
360-
assert isinstance(kwargs["kaldi_style_text"], bool)
361-
self.kaldi_style_text = kwargs["kaldi_style_text"]
363+
self.kaldi_style_text = bool(kwargs["kaldi_style_text"])
362364
if "text_converter" in kwargs:
363365
if kwargs["text_converter"] not in self.choices_text_converter:
364366
raise NotImplementedError(
@@ -368,11 +370,9 @@ def set_config(self, **kwargs):
368370
self.text_converter = kwargs["text_converter"]
369371
# Parameters for alignment
370372
if "min_window_size" in kwargs:
371-
assert isinstance(kwargs["min_window_size"], int)
372-
self.config.min_window_size = kwargs["min_window_size"]
373+
self.config.min_window_size = int(kwargs["min_window_size"])
373374
if "max_window_size" in kwargs:
374-
assert isinstance(kwargs["max_window_size"], int)
375-
self.config.max_window_size = kwargs["max_window_size"]
375+
self.config.max_window_size = int(kwargs["max_window_size"])
376376
if "gratis_blank" in kwargs:
377377
self.config.blank_transition_cost_zero = bool(
378378
kwargs["gratis_blank"]
@@ -389,8 +389,7 @@ def set_config(self, **kwargs):
389389
self.warned_about_misconfiguration = True
390390
# Parameter for calculation of confidence score
391391
if "scoring_length" in kwargs:
392-
assert isinstance(kwargs["scoring_length"], int)
393-
self.config.score_min_mean_over_L = kwargs["scoring_length"]
392+
self.config.score_min_mean_over_L = int(kwargs["scoring_length"])
394393

395394
def get_timing_config(self, speech_len=None, lpz_len=None):
396395
"""Obtain parameters to determine time stamps."""
@@ -591,7 +590,7 @@ def get_segments(task: CTCSegmentationTask):
591590
Dictionary with alignments. Combine this with the task
592591
object to obtain a human-readable segments representation.
593592
"""
594-
assert check_argument_types()
593+
assert type(task) == CTCSegmentationTask
595594
assert task.config is not None
596595
config = task.config
597596
lpz = task.lpz
@@ -641,7 +640,6 @@ def __call__(
641640
Task object with segments. Apply str(·) or print(·) on it
642641
to obtain the segments list.
643642
"""
644-
assert check_argument_types()
645643
if isinstance(speech, str) or isinstance(speech, Path):
646644
speech = self.asr_model.load_audio(speech)
647645
# Get log CTC posterior probabilities
@@ -651,5 +649,4 @@ def __call__(
651649
# Apply CTC segmentation
652650
segments = self.get_segments(task)
653651
task.set(**segments)
654-
assert check_return_type(task)
655652
return task

0 commit comments

Comments
 (0)