Python对批量wav文件改名

	sample = r"C:\Users\Administrator\Desktop\aws-3 "
	files = os.listdir(sample)
	files = [sample + "\\" + f for f in files if f.endswith('.wav')]
	num = len(files)
	threshold_value = 1
	check_repeat = []
	for i in xrange(num):
		song = djv.recognize(FileRecognizer, files[i])
		FileName = files[i]
		# print("recognition File Name is ", FileName)
		f = wave.open(FileName, "rb")
		params = f.getparams()
		# print(params)
		nchannels, sampwidth, framerate, nframes = params[:4]
		str_data = f.readframes(nframes)
		f.close()
		wave_data = np.fromstring(str_data, dtype=np.short)
		wave_data = wave_data.astype(np.short)
		print "测试数据", i + 1, ":", os.path.basename(files[i]), "From file we recognized: %s" % song
		try:
			if song['confidence'] > threshold_value:
				# print "可能重复文件", i + 1, ":", os.path.basename(files[i]), "From file we recognized: %s" % song

				status_id=song['song_name'].split('-')[-1]
				status=song['song_name'].split('-')[-3]
				re_dataname = ".\\recognition-data\\" +'TEST-' +status_id+'-'+status+'-'+str(i)+".wav"
				fw = wave.open(re_dataname, "wb")  #
				fw.setnchannels(nchannels)
				fw.setsampwidth(sampwidth)
				fw.setframerate(framerate)
				# print wave_data
				fw.writeframes(wave_data.tostring())
				fw.close()

 

你可能感兴趣的:(工具包,信号处理,音频处理)