in src/diarizers/data/preprocess.py [0:0]
def get_start_positions(self, file, overlap, random=False):
"""Get start positions from the audio_chunks in the input audio file.
Args:
file (dict): dataset row containing the "audio" feature.
overlap (float, optional): Overlap between successive start positions.
random (bool, optional): Whether or not to randomly select chunks in the audio file. Defaults to False.
Returns:
start_positions: Numpy array containing the start positions of the audio chunks in file.
"""
sample_rate = file["audio"][0]["sampling_rate"]
assert sample_rate == self.sample_rate
file_duration = len(file["audio"][0]["array"]) / sample_rate
start_positions = np.arange(0, file_duration - self.chunk_duration, self.chunk_duration * (1 - overlap))
if random:
nb_samples = int(file_duration / self.chunk_duration)
start_positions = np.random.uniform(0, file_duration, nb_samples)
return start_positions