Created
February 13, 2013 13:05
-
-
Save KenjiTakahashi/4944463 to your computer and use it in GitHub Desktop.
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
import wave | |
import random | |
import struct | |
import datetime | |
SAMPLE_LEN = 44100 * 3 # 300 seconds of noise, 5 minutes | |
print "Create file using wave, storing frames in an array and using writeframes only once" | |
noise_output = wave.open('noise2.wav', 'w') | |
noise_output.setparams((2, 2, 44100, 0, 'NONE', 'not compressed')) | |
d1 = datetime.datetime.now() | |
values = [] | |
for i in range(0, SAMPLE_LEN): | |
value = random.randint(-32767, 32767) | |
packed_value = struct.pack('h', value) | |
values.append(packed_value) | |
values.append(packed_value) | |
value_str = ''.join(values) | |
print value_str | |
noise_output.writeframes(value_str) | |
d2 = datetime.datetime.now() | |
print (d2 - d1), "(time for writing frames)" | |
noise_output.close() | |
d3 = datetime.datetime.now() | |
print (d3 - d2), "(time for closing the file)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment