diff --git a/pydub/audio_segment.py b/pydub/audio_segment.py index 3b9e2881..b666d100 100644 --- a/pydub/audio_segment.py +++ b/pydub/audio_segment.py @@ -180,6 +180,7 @@ def __init__(self, data=None, *args, **kwargs): self.sample_width = kwargs.pop("sample_width", None) self.frame_rate = kwargs.pop("frame_rate", None) self.channels = kwargs.pop("channels", None) + self.start_time = kwargs.pop("start_time", None) audio_params = (self.sample_width, self.frame_rate, self.channels) diff --git a/pydub/silence.py b/pydub/silence.py index 0ad14999..4cb9e7b7 100644 --- a/pydub/silence.py +++ b/pydub/silence.py @@ -157,11 +157,16 @@ def pairwise(iterable): range_i[1] = (last_end+next_start)//2 range_ii[0] = range_i[1] - return [ - audio_segment[ max(start,0) : min(end,len(audio_segment)) ] - for start,end in output_ranges - ] + audio_segment_chunks = [] + for start, end in output_ranges: + start = max(start, 0) + end = min(end, len(audio_segment)) + + new_audio_segment = audio_segment[start:end] + new_audio_segment.start_time = start + audio_segment_chunks.append(new_audio_segment) + return audio_segment_chunks def detect_leading_silence(sound, silence_threshold=-50.0, chunk_size=10): """