Exemplo n.º 1
0
def analyze(filename):
	'''Analyze a voice file.

	Example:
		python analyze 'myfile'
	Return:
		The detailed infomation and the mood prediction result if success.
	The file should use its full path, and will be mood_predict by our program.
	The prediction is processed by svm-machine , model file and scale file should
	be generated by the script train.py, and no need to indicate. All you need is 
	to tell us which file or directory you want to predict.'''
	#print 'Analyzing %s'%filename
	m = Voice()
	try:
		m.analyze(filename)
		m.calFeatures()
		m.mood_predict()
		m.callInfo()
		m.report()
		print 'Analyze success'
	except Exception as e:
		print 'Analyze failed:'+ repr(e)
Exemplo n.º 2
0
def train(diretory=config.root_dir):
    '''Train all the files in diretory 'luyin'

	The diretory is made up of two subdiretories named 'normal' and 'abnormal'.
	
	As a result , the script will generate 3 files:
	(1)scale : used for scale data by the svm command 'svm-scale -s filename > scale'
	(2)dataset_scaled : the scaled dataset for training
	(3)model : the svm model file 
	'''
    files = os.listdir(config.normal)
    dataset = config.dataset
    dataset_scaled = config.dataset_scaled
    scale = config.scale

    #fs = open(dataset,'a')

    for f in files:
        f = config.normal + f
        voice = Voice()
        voice.analyze(f)
        voice.calFeatures()
        voice.learn(dataset, '+1')
    files = os.listdir(config.abnormal)

    for f in files:
        f = config.abnormal + f
        voice = Voice()
        voice.analyze(f)
        voice.calFeatures()
        voice.learn(dataset, '-1')

    os.system('svm-scale -s %s %s > %s' % (scale, dataset, dataset_scaled))
    y, x = svm_read_problem(dataset_scaled)
    m = svm_train(y, x)
    svm_save_model(config.model, m)
Exemplo n.º 3
0
def train(diretory = config.root_dir):
	'''Train all the files in diretory 'luyin'

	The diretory is made up of two subdiretories named 'normal' and 'abnormal'.
	
	As a result , the script will generate 3 files:
	(1)scale : used for scale data by the svm command 'svm-scale -s filename > scale'
	(2)dataset_scaled : the scaled dataset for training
	(3)model : the svm model file 
	'''
	files = os.listdir(config.normal)
	dataset = config.dataset
	dataset_scaled = config.dataset_scaled
	scale = config.scale

	#fs = open(dataset,'a')

	for f in files:
		f = config.normal + f
		voice = Voice()
		voice.analyze(f)
		voice.calFeatures()
		voice.learn(dataset,'+1')
	files = os.listdir(config.abnormal)
	
	for f in files:
		f = config.abnormal + f
		voice = Voice()
		voice.analyze(f)
		voice.calFeatures()
		voice.learn(dataset,'-1')

	os.system('svm-scale -s %s %s > %s'%(scale,dataset,dataset_scaled))
	y,x = svm_read_problem(dataset_scaled)
	m = svm_train(y,x)
	svm_save_model(config.model,m)
Exemplo n.º 4
0
from voice import Voice 
import pylab as pl
m = Voice()
m.analyze('../luyin/moni-2.wav')

print m.speech_segment
pl.subplot(311)
pl.plot(m.volume)
pl.subplot(312)
pl.plot(m.zcr)
pl.subplot(313)
pl.plot(m.acf)
pl.show()
'''
m.calFeatures()
m.mood_predict()
m.callInfo()
m.report()
'''
Exemplo n.º 5
0
from voice import Voice
import pylab as pl

m = Voice()
m.analyze('../luyin/moni-2.wav')

print m.speech_segment
pl.subplot(311)
pl.plot(m.volume)
pl.subplot(312)
pl.plot(m.zcr)
pl.subplot(313)
pl.plot(m.acf)
pl.show()
'''
m.calFeatures()
m.mood_predict()
m.callInfo()
m.report()
'''