Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: slice indices must be integers or None or have an __index__ method #1001

Closed
yfyeung opened this issue Mar 20, 2023 · 2 comments · Fixed by #1002
Closed

TypeError: slice indices must be integers or None or have an __index__ method #1001

yfyeung opened this issue Mar 20, 2023 · 2 comments · Fixed by #1002

Comments

@yfyeung
Copy link
Contributor

yfyeung commented Mar 20, 2023

>>> 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
@yfyeung
Copy link
Contributor Author

yfyeung commented Mar 20, 2023

https://github.com/lhotse-speech/lhotse/blob/master/lhotse/cut/base.py line 993-1019

        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

@yfyeung
Copy link
Contributor Author

yfyeung commented Mar 20, 2023

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.

yfyeung pushed a commit to yfyeung/lhotse that referenced this issue Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant