34 lines
812 B
Python
34 lines
812 B
Python
#!/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()
|