Added big chop

This commit is contained in:
Pünkösd Marcell 2021-11-24 20:01:56 +01:00
commit 2069898190
2 changed files with 43 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
*.swp
venv
*.pyc
__pycache__/*
__pycache__
*.wpr
*.log
.idea
*.wav
big_chop_output/

33
big_chop.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# This script chops up any file to one sec segments
import wave
import os
import os.path
import sys
def main():
infile = sys.argv[1]
wavefile = wave.open(infile, "rb")
os.makedirs("big_chop_output", exist_ok=True)
samples_per_slice = wavefile.getframerate()
i = 0
while True:
filename = os.path.join("big_chop_output", f"{i}.wav")
sound_data = wavefile.readframes(samples_per_slice)
if len(sound_data) < samples_per_slice:
break
with wave.open(filename, "wb") as f:
f.setnchannels(wavefile.getnchannels())
f.setframerate(wavefile.getframerate())
f.setsampwidth(wavefile.getsampwidth())
f.writeframes(sound_data)
i += 1
if __name__ == '__main__':
main()