Repository: lhotse-speech/lhotse

Issue:
A few questions...
I came across a few confusions while I was reading the code in order to write an example. It would be helpful for me if they are clarified ( I may have missed something).

https://github.com/lhotse-speech/lhotse/blob/master/lhotse/kaldi.py#L68
why `duration - start` rather than just `duration`?

https://github.com/lhotse-speech/lhotse/blob/master/lhotse/audio.py#L178
why not `[n_sources, n_channels, n_samples]`?

Thanks!


Discussion:
> https://github.com/lhotse-speech/lhotse/blob/master/lhotse/kaldi.py#L68
> why `duration - start` rather than just `duration`?

My bad - the variable should be called `end`, the code should work fine otherwise.

> https://github.com/lhotse-speech/lhotse/blob/master/lhotse/audio.py#L178
> why not `[n_sources, n_channels, n_samples]`?

I think that might be a naming collision - "source" in this context is supposed to mean "some storage containing audio samples for one or more channels" (e.g. a file), rather than an acoustic sound source in some physical space... So if some corpus has recordings from an array of 4 mics stored in separate wav files, there would be 4 `AudioSource` objects inside a `Recording` to represent that. Does that make it clearer?

I'll make a PR soon with updates to fix/clarify based on your feedback - thanks!

> > https://github.com/lhotse-speech/lhotse/blob/master/lhotse/kaldi.py#L68
> > why `duration - start` rather than just `duration`?
> 
> My bad - the variable should be called `end`, the code should work fine otherwise.
> 
> > https://github.com/lhotse-speech/lhotse/blob/master/lhotse/audio.py#L178
> > why not `[n_sources, n_channels, n_samples]`?
> 
> I think that might be a naming collision - "source" in this context is supposed to mean "some storage containing audio samples for one or more channels" (e.g. a file), rather than an acoustic sound source in some physical space... So if some corpus has recordings from an array of 4 mics stored in separate wav files, there would be 4 `AudioSource` objects inside a `Recording` to represent that. Does that make it clearer?

> 
> I'll make a PR soon with updates to fix/clarify based on your feedback - thanks!

Thanks! what is the size of each element in the list `samples_per_source`? I assume it is already 2D?


> Thanks! what is the size of each element in the list `samples_per_source`? I assume it is already 2D?

Yes - for mono files it'd be (1, num_samples), for stereo files (2, num_samples), and the `stack` operation concats across the channel dim.
I think `np.vstack()` will add one more dimension on top on the existing tensor, so the resulting tensor will be in 3D?
I don't think so:

```
import numpy
x = numpy.ones((1, 1000))
y = numpy.zeros((2, 1000))
numpy.vstack([x, y]).shape
Out[5]: (3, 1000)
```
Oh OK, maybe only for 1D vectors it adds one more dimension.

Resolving patch:
diff --git a/lhotse/kaldi.py b/lhotse/kaldi.py
--- a/lhotse/kaldi.py
+++ b/lhotse/kaldi.py
@@ -65,14 +65,14 @@ def load_kaldi_data_dir(path: Pathlike, sampling_rate: int) -> Tuple[RecordingSe
             id=segment_id,
             recording_id=recording_id,
             start=float(start),
-            duration=float(duration) - float(start),
+            duration=float(end) - float(start),
             channel=0,
             text=texts[segment_id],
             language=languages[segment_id],
             speaker=speakers[segment_id],
             gender=genders[speakers[segment_id]]
         )
-        for segment_id, recording_id, start, duration in supervision_segments
+        for segment_id, recording_id, start, end in supervision_segments
     )
 
     return audio_set, supervision_set


Test patch: