#!/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] max_ = int(sys.argv[2]) wavefile = wave.open(infile, "rb") os.makedirs("big_chop_output", exist_ok=True) samples_per_slice = wavefile.getframerate() i = 0 while i < max_: 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()