Created
March 25, 2012 06:10
-
-
Save cincodenada/2191669 to your computer and use it in GitHub Desktop.
A quick script to split a sample-interlaced wav into two files, used for testing my Honors Project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
import wave | |
sound = wave.open(argv[1],"r") | |
one = wave.open("split_one.wav","w") | |
two = wave.open("split_two.wav","w") | |
data = sound.readframes(sound.getnframes()) | |
one.setparams(sound.getparams()) | |
two.setparams(sound.getparams()) | |
one.setframerate(sound.getframerate()/2) | |
two.setframerate(sound.getframerate()/2) | |
dataone = '' | |
datatwo = '' | |
print "Splitting %d bytes..." % len(data) | |
for startpos in range(0, len(data), 4): | |
#print "First sample: %s Second sample: %s" % (hex(ord(data[startpos])) + hex(ord(data[startpos+1])), hex(ord(data[startpos+2])) + hex(ord(data[startpos+3]))) | |
try: | |
dataone += data[startpos] | |
dataone += data[startpos+1] | |
datatwo += data[startpos+2] | |
datatwo += data[startpos+3] | |
except IndexError: | |
pass | |
print len(dataone) | |
print len(datatwo) | |
one.writeframes(dataone) | |
two.writeframes(datatwo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment