Skip to content

Instantly share code, notes, and snippets.

@chisler
Last active November 6, 2018 22:26
Show Gist options
  • Save chisler/c94dbd5f2fcc1ea381198c3eadcbed32 to your computer and use it in GitHub Desktop.
Save chisler/c94dbd5f2fcc1ea381198c3eadcbed32 to your computer and use it in GitHub Desktop.
from pydub import AudioSegment
import datetime
path = ""
sound = AudioSegment.from_mp3(path)
length = len(sound)
print(f'Length of the file is {datetime.timedelta(milliseconds=length)} How many minutes should be one file?')
step_minutes = input()
step_miliseconds = int(step_minutes) * 60000
l = 0
c = 0
while l + step_miliseconds < length:
sound[l:l+step_miliseconds].export(f"path/file_{c}.mp3", format="mp3")
print(f'File_{c}.mp3 created')
l += step_miliseconds
c += 1
print(f'Count: {c} sounds created')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment