Added big chop
This commit is contained in:
commit
2069898190
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
*.swp
|
||||
venv
|
||||
*.pyc
|
||||
__pycache__/*
|
||||
__pycache__
|
||||
*.wpr
|
||||
*.log
|
||||
.idea
|
||||
*.wav
|
||||
big_chop_output/
|
33
big_chop.py
Normal file
33
big_chop.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user