Repository: lhotse-speech/lhotse

Issue:
TypeError: slice indices must be integers or None or have an __index__ method
```python
>>> cut
MonoCut(id='yes_e0a7c5a0_nohash_0-0', start=0, duration=1.0, channel=0, supervisions=[SupervisionSegment(id='yes_e0a7c5a0_nohash_0', recording_id='yes_e0a7c5a0_nohash_0', start=0.0, duration=1.0, channel=0, text='yes', language='English', speaker='e0a7c5a0', gender=None, custom=None, alignment=None)], features=None, recording=Recording(id='yes_e0a7c5a0_nohash_0', sources=[AudioSource(type='file', channels=[0], source='/k2-dev/yangyifan/icefall-wuw/egs/speechcommands/v1/wuw/download/SpeechCommands1/speech_commands_v0.01/yes/e0a7c5a0_nohash_0.wav')], sampling_rate=16000, num_samples=16000, duration=1.0, channel_ids=[0], transforms=None), custom=None)
>>> cut.supervisions_audio_mask()
0 16000.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/k2-dev/yangyifan/anaconda3/envs/icefall/lib/python3.10/site-packages/lhotse-1.13.0.dev0+git.7e8d6b0.dirty-py3.10.egg/lhotse/cut/base.py", line 1019, in supervisions_audio_mask
TypeError: slice indices must be integers or None or have an __index__ method
```


Discussion:
https://github.com/lhotse-speech/lhotse/blob/master/lhotse/cut/base.py line 993-1019
```python
        for supervision in self.supervisions:
            if (
                use_alignment_if_exists
                and supervision.alignment
                and use_alignment_if_exists in supervision.alignment
            ):
                for ali in supervision.alignment[use_alignment_if_exists]:
                    st = round(ali.start * self.sampling_rate) if ali.start > 0 else 0
                    et = (
                        round(ali.end * self.sampling_rate)
                        if ali.end < self.duration
                        else self.duration * self.sampling_rate
                    )
                    mask[st:et] = 1.0
            else:
                st = (
                    round(supervision.start * self.sampling_rate)
                    if supervision.start > 0
                    else 0
                )
                et = (
                    round(supervision.end * self.sampling_rate)
                    if supervision.end < self.duration
                    else self.duration * self.sampling_rate
                )
                mask[st:et] = 1.0
        return mask
```
Note that `et = self.duration * self.sampling_rate` when `supervision.end >= self.duration`, which may result in `TypeError: slice indices must be integers or None or have an __index__ method`.

Resolving patch:
diff --git a/lhotse/cut/base.py b/lhotse/cut/base.py
--- a/lhotse/cut/base.py
+++ b/lhotse/cut/base.py
@@ -1001,7 +1001,7 @@ def supervisions_audio_mask(
                     et = (
                         round(ali.end * self.sampling_rate)
                         if ali.end < self.duration
-                        else self.duration * self.sampling_rate
+                        else round(self.duration * self.sampling_rate)
                     )
                     mask[st:et] = 1.0
             else:
@@ -1013,7 +1013,7 @@ def supervisions_audio_mask(
                 et = (
                     round(supervision.end * self.sampling_rate)
                     if supervision.end < self.duration
-                    else self.duration * self.sampling_rate
+                    else round(self.duration * self.sampling_rate)
                 )
                 mask[st:et] = 1.0
         return mask


Test patch: