segmented_index()

audformat.segmented_index(files=None, starts=None, ends=None)[source]

Create segmented index.

Index is conform to table specifications.

If a non-empty index is created and starts is set to None, the level will be filled up with 0. If a non-empty index is created and ends is set to None, the level will be filled up with NaT.

Parameters
Return type

Index

Returns

segmented index

Raises
  • ValueError – if created index contains duplicates

  • ValueError – if files, start and ends differ in size

Examples

>>> segmented_index("a.wav", 0, 1.1)
MultiIndex([('a.wav', '0 days', '0 days 00:00:01.100000')],
           names=['file', 'start', 'end'])
>>> segmented_index("a.wav", "0ms", "1ms")
MultiIndex([('a.wav', '0 days', '0 days 00:00:00.001000')],
           names=['file', 'start', 'end'])
>>> segmented_index(["a.wav", "b.wav"])
MultiIndex([('a.wav', '0 days', NaT),
            ('b.wav', '0 days', NaT)],
           names=['file', 'start', 'end'])
>>> segmented_index(["a.wav", "b.wav"], [None, 1], [1, None])
MultiIndex([('a.wav',               NaT, '0 days 00:00:01'),
            ('b.wav', '0 days 00:00:01',               NaT)],
           names=['file', 'start', 'end'])
>>> segmented_index(
...     files=["a.wav", "a.wav"],
...     starts=[0, 1],
...     ends=pd.to_timedelta([1000, 2000], unit="ms"),
... )
MultiIndex([('a.wav', '0 days 00:00:00', '0 days 00:00:01'),
            ('a.wav', '0 days 00:00:01', '0 days 00:00:02')],
           names=['file', 'start', 'end'])