In [1]:
%matplotlib notebook

from scipy.io.wavfile import write
from numpy import linspace,sin,pi,int16,concatenate
from pylab import plot,show,axis

import pandas as pd
import os
from os.path import isfile, join

In [2]:
fileList = os.listdir('gg/')

def isDataFile(filename):
    return filename.find('.dat')>0

dataFiles = filter(isDataFile,fileList)

In [5]:
len(dataFiles)


Out[5]:
266

In [4]:
pd.read_csv('gg/'+dataFiles[0],sep='\t',header=None,names=('grain-ID','area','sides'))


Out[4]:
grain-ID area sides
0 1 0.002307 4
1 2 0.041458 5
2 3 0.011237 5
3 4 0.014604 6
4 5 0.027024 8
5 6 0.017106 5
6 7 0.034995 7
7 8 0.012546 6
8 9 0.074316 5
9 10 0.028605 5
10 11 0.006609 5
11 12 0.043620 7
12 13 0.017081 4
13 14 0.002516 3
14 15 0.041003 7
15 16 0.004306 5
16 17 0.024224 6
17 18 0.029528 5
18 19 0.029660 3
19 20 0.019782 5
20 21 0.004285 4
21 22 0.002741 4
22 23 0.005267 4
23 24 0.004443 6
24 25 0.020166 7
25 26 0.010164 4
26 27 0.035461 7
27 28 0.035187 5
28 29 0.032246 8
29 30 0.014116 9
30 31 0.013792 4
31 32 0.027356 7
32 33 0.042277 9
33 34 0.003075 4
34 35 0.010560 5
35 36 0.035285 6
36 37 0.005527 5
37 38 0.012483 5
38 39 0.007960 4
39 40 0.000837 3
40 41 0.033747 7
41 42 0.032337 6
42 43 0.002720 3
43 44 0.001259 4
44 45 0.027278 8
45 46 0.029346 7
46 47 0.012089 4
47 48 0.003810 4
48 49 0.049907 5
49 50 0.001755 5

In [2]:
# tone synthesis
def note(freq, len, amp=1, rate=44100):
 t = linspace(0,len,len*rate)
 data = sin(2*pi*freq*t)*amp
 return data.astype(int16) # two byte integers

In [10]:
# A tone, 2 seconds, 44100 samples per second

tone_1 = note(440,2,amp=10000) + note(660,2,amp=10000)
tone_2 = note(440,2,amp=10000)

tone_total = concatenate((tone_1,tone_2))

write('test.wav',44100,tone_total) # writing the sound to a file

#plot(linspace(0,2,2*44100),tone_total)
#axis([0,0.4,15000,-15000])
#show()

In [ ]: