Created
April 16, 2023 22:06
-
-
Save tikhonova/9879b8be160582efacdf74d2ee0a5b9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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