#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
#from matplotlib.pyplot import *
from numpy import *
from scipy.stats.mstats import mquantiles
def soundGenerator((signal,downsampl_freq, name)):
print "sound gen. start"
signal-=median(signal)
MIN = min(mquantiles(signal,0.0001), -absmax)
MAX = max(mquantiles(signal,0.9999), absmax)
signal =(signal-MIN)/(MAX-MIN)
signal *=2**16-1
signal_16bit = uint16(signal)
#plot(signal_16bit)
#show()
fi=open(name+'.raw',"wb")
fi.write(signal_16bit)
fi.close()
os.system("sox -r "+str(int(downsampl_freq))+" -e unsigned -b 16 -c1 "+name+".raw "+name+".wav")
os.system("lame -b 512 "+name+".wav "+name+".mp3")
try:
os.remove(name+'.wav')
except:
pass
try:
os.remove(name+'.raw')
except:
pass
#use the http://flash-mp3-player.net/players/maxi/generator/