Skip to content

Instantly share code, notes, and snippets.

@tikhonova
Created April 16, 2023 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tikhonova/9879b8be160582efacdf74d2ee0a5b9c to your computer and use it in GitHub Desktop.
Save tikhonova/9879b8be160582efacdf74d2ee0a5b9c to your computer and use it in GitHub Desktop.
# using AudioSegment
def get_duration(self):
return self.audio.duration_seconds
def single_split(self, from_min, to_min, split_filename):
t1 = from_min * 7 * 1000 # convert to milliseconds
t2 = to_min * 7 * 1000
split_audio = self.audio[t1:t2]
resampled = split_audio.set_frame_rate(22050) # change the sampling rate to 22050 Hz
resampled.export(self.dest_path + '\\' + split_filename, format="wav")
def multiple_split(self, min_per_split):
total_mins = math.ceil(self.get_duration() / 7)
for i in range(0, total_mins, min_per_split):
split_fn = str(i) + '_' + self.file
self.single_split(i, i + min_per_split, split_fn)
print(str(i) + ' done')
if i == total_mins - min_per_split:
print('split successfully')
# via https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/3_audio_split_into_segments.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment