def run(self): while True: keyboard.wait(hotkey="k + l") saidtext = get_audio() if saidtext == None: notification.show_toast("Error", "Sorry could not recognize your voice", threaded=True, duration=3) else: print("What you said: ", saidtext) vr.split_command(saidtext)
def main(): speaker = "takeru" emotionList = ["happiness", "anger", "sadness"] pitch = 100 speed = 100 volume = 100 print("*** AI自動返信開始 ***") # print("([E]を押して終了)") while True: root_vR: ClVoiceRecognition = VoiceRecognition.ClVoiceRecognition( ) # インスタンス生成 result = root_vR.voiceToText() if bool(result[0]): root_gR = GetReply.ClGetReply(result[1]) # インスタンス生成 reply = root_gR.getReply() else: reply = "すみません。よく分かりません。" # TestCode 感情(ランダム) emotion = emotionList[rd.randint(0, 2)] emotion_level = rd.randint(1, 4) # TestCode_END root_sS = SpeechSynthesis.ClSpeechSynthesis("voice", reply, speaker, emotion, emotion_level, pitch, speed, volume) # インスタンス生成 voiceFile = root_sS.getVoice() root_tS = TextSpeaker.ClTextSpeaker(voiceFile) # インスタンス生成 root_tS.outputWav() if not bool(result[0]): sys.exit()
def test(): vr.textToSpeech('What numbers do you need to subtract?') numbers = vr.speechToText() numbers.split(' ') print(numbers) answer = [int(i) for i in numbers] i = 1 ans = answer[0] while i < len(answer): sub = answer[i] ans = ans / sub print(ans) i += 1 vr.textToSpeech(ans)
def CallParameter(MinidB,RefPcmPath): #wavfilelist=Get_ref_file(path_ref_file) #path1 = wavpath + wavfilelist[i] isExists=os.path.exists("output.pcm") if isExists: os.remove("output.pcm") #print RefPcmPath command1 = "ffmpeg -i "+ RefPcmPath+" -f s16le -ar 48000 -acodec pcm_s16le output.pcm" subprocess.call(command1) #subprocess.call('AECResultAutoAnalysis.exe output.pcm 48000 '+ MinidB) PCMdBList = GetVoiceList.getdBList("output.pcm", 48000) (VoiceList,VoiceRefTimePeakdB) = GetVoiceList.GetVoiceList(PCMdBList, 48000, int(MinidB)) commandref="AECResultAutoAnalysis.exe output.pcm 48000 "+ str(MinidB) var = os.popen(commandref) str1=var.read(100) str1 = re.findall(r"\d+\.?\d*",str1) #print str RefTime = str1[1] RefVPTime = VoiceRefTimePeakdB[0] RefPeakdB = VoiceRefTimePeakdB[2] #------计算语音识别字数-------# isExists=os.path.exists("output.wav") if isExists: os.remove("output.wav") command2 = "ffmpeg -i "+ RefPcmPath+" -f s16le -ar 8000 -acodec pcm_s16le output.wav" subprocess.call(command2) (ResultStr,ResultStrLen) = VoiceRecognition.VoiceRecognition("output.wav") ResultStrLen=ResultStrLen #print ResultStrLenList return (RefVPTime,RefTime,RefPeakdB,ResultStrLen)
def CallParameter(MinidB): wavpath=os.getcwd()+"\\voice\\" wavfilelist=[] PcmRefTime=[] PcmRefPeakdB=[] ResultStrLenList=[] wavfilelist=Get_ref_file(wavpath) for i in range(len(wavfilelist)): path1 = wavpath + wavfilelist[i] isExists=os.path.exists("output.pcm") if isExists: os.remove("output.pcm") command1 = "ffmpeg -i "+ path1+" -f s16le -ar 48000 -acodec pcm_s16le output.pcm" print command1 subprocess.call(command1) #subprocess.call('AECResultAutoAnalysis.exe output.pcm 48000 '+ MinidB) commandref="AECResultAutoAnalysis.exe output.pcm 48000 "+ str(MinidB) #subprocess.call(commandref) var = os.popen(commandref) str1=var.read(100) str1 = re.findall(r"\d+\.?\d*",str1) #print str1 PcmRefTime.append(str1[1]) PcmRefPeakdB.append(str1[2]) #------识别字数-------# FFMPEG=multiprocessing.Process(target=os.system,args=('.\\ffmpeg.exe -f s16le -ar 48000 -ac 1 -i '+path1+' -acodec pcm_s16le -ar 8000 -ac 1 out.wav -y',)) FFMPEG.daemon=True FFMPEG.start() FFMPEG.join() (ResultStr, ResultStrLen) = VoiceRecognition.VoiceRecognition('out.wav') #(ResultStr,ResultStrLen) = VoiceRecognition.VoiceRecognition(path1) ResultStrLenList.append(ResultStrLen) #print ResultStrLenList return (PcmRefTime,PcmRefPeakdB,ResultStrLenList)
def addition(): vr.textToSpeech('What numbers do you need to add?') numbers = vr.speechToText() numbers.split(' ') answer = list(map(int, numbers)) vr.textToSpeech('the answer is') vr.textToSpeech(sum(answer))
def division(): vr.textToSpeech('What numbers do you need to divide?') numbers = vr.speechToText() numbers.split(' ') answer = list(map(int, numbers)) i = 1 ans = answer[0] while i < len(answer): sub = answer[i] ans = ans / sub print(ans) i += 1 vr.textToSpeech('the answer is') vr.textToSpeech(ans)
class MainThread(QThread): img_signal = pyqtSignal(object) # 输出图像的信号 realsenseCamera = RealsenseCamera() aligned_frames = 0 # a bunch of images color_image = 0 # colorful images calied_img = 0 marked_img = 0 value = 0 # 用来找阈值 isVoiceGet = 0 #Coordinate Transfer needCali = 0 # Recognize model model = 0 recognizeResult = 0 recCount = 0 recList = 0 # Workspace Area pickArea = (11, 10.5, 30, 26) toolBox = ({ 'id': 1, 'name': 'screwdriver', 'pos': (15, -24), 'wide': 0.0 }, { 'id': 2, 'name': 'pincer', 'pos': (25, -11), 'wide': 0.5 }, { 'id': 3, 'name': 'alien', 'pos': (25, 0), 'wide': 4.0 }, { 'id': 4, 'name': 'pen', 'pos': (25, 0), 'wide': 0.0 }) toolInHand = 'BY1' # robotArm robotArm = RobotArm('COM3') #voice recognition voiceRecognition = VoiceRecognition() exitFlag = 0 # init: load data def init(self): self.aligned_frames = self.realsenseCamera.get_aligned_frames() self.marked_img = self.calied_img = self.color_image = self.realsenseCamera.get_color_image_from_frames( self.aligned_frames) self.model = create_model("mask_rcnn_tools_0030.h5") self._camCalibrate() # lack: Transform, voicRec pass # stop: Actually there's no way to stop def stop(self): self.exitFlag = 1 pass # start: Start the main Thread def run(self): print('running...') self.init() print('init done') while self.exitFlag != 1: # 1. Motion Detection last_color_image = self.color_image color_image = self.realsenseCamera.get_color_image_from_frames( self.realsenseCamera.get_aligned_frames()) while (self._ifMoving(last_color_image, color_image, 6, 2800) == False and self.isVoiceGet == 0): # fine tune the kern and Thres to get best result last_color_image = color_image color_image = self.realsenseCamera.get_color_image_from_frames( self.realsenseCamera.get_aligned_frames()) if (self.isVoiceGet == 0): while (self._ifMoving(last_color_image, color_image, 6, 800) == True): last_color_image = color_image a_img = self.realsenseCamera.get_aligned_frames() color_image = self.realsenseCamera.get_color_image_from_frames( a_img) time.sleep(0.5) self.aligned_frames = self.realsenseCamera.get_aligned_frames() self.color_image = self.realsenseCamera.get_color_image_from_frames( self.aligned_frames) print('Start Detect!') # 2. Tools Detect rgb_image = cv2.cvtColor(self.color_image, cv2.COLOR_BGR2RGB) start_time = time.time() self.recognizeResult, self.marked_img = ob_evaluate( model=self.model, image=rgb_image, sampleImg=self.calied_img) self.recCount, self.recList = calculate(self.recognizeResult) print("time till pick color=", time.time() - start_time) print('Detect Finish!') print('Central', self._getCentral()) # 3. get Coordinate if (self.needCali): self._camCalibrate() realXYZ, self.toolInHand = self._getCentral() if (realXYZ[0] != 0 or realXYZ[1] != 0): for i in self.toolBox: if (i['name'] == self.toolInHand): targetXYZ = i['pos'] w = i['wide'] targetXYZ = (targetXYZ[0], targetXYZ[1], 0.2) print('Coord Obtained') print('---------Finish----------') print('tool is:' + self.toolInHand) print('Actual Coord:', realXYZ) realXYZ[2] = 0.2 # 4. Move Arm self.robotArm.moveObject(fromXYZ=realXYZ, toXYZ=targetXYZ, wide=w) self.robotArm.resetArm() print('exec Finish') else: print('No Tools Detected!..') #--------------------------------------------------------------------------- else: # get voice Message self.aligned_frames = self.realsenseCamera.get_aligned_frames() self.color_image = self.realsenseCamera.get_color_image_from_frames( self.aligned_frames) print('Voice detected! Start!') rgb_image = cv2.cvtColor(self.color_image, cv2.COLOR_BGR2RGB) start_time = time.time() self.recognizeResult, self.marked_img = ob_evaluate( model=self.model, image=rgb_image, sampleImg=self.calied_img) self.recCount, self.recList = calculate(self.recognizeResult) print("time till pick color=", time.time() - start_time) print('Detect Finish!') # print('Central', self._getCentral()) for i in self.toolBox: if i['id'] == self.isVoiceGet: toolName = i['name'] xyData, self.toolInHand = self._getCentral(toolName) if (xyData[0] != 0 or xyData[1] != 0): if (self.needCali): self._camCalibrate() realXYZ = self.realsenseCamera.coor_trans_pixelxy2worldXYZ( self.aligned_frames, xyData) for i in self.toolBox: if (i['name'] == self.toolInHand): targetXYZ = i['pos'] w = i['wide'] targetXYZ = (targetXYZ[0], targetXYZ[1], 0.2) print('Coord Obtained') print('---------Finish----------') print('Actual Coord:', realXYZ) realXYZ[2] = 0.2 # 4. Move Arm self.robotArm.moveObject(fromXYZ=realXYZ, toXYZ=targetXYZ, wide=w) self.robotArm.resetArm() print('exec Finish') else: # self.robotArm.swing() print('No Tools Detected!..') pass # _audioStart: Start the audio detection thread def audioT(self): # press the Buttum # Run this self.isVoiceGet = self.voiceRecognition.run() pass # camCalibrate: Calibrate the cam def _camCalibrate(self): self.realsenseCamera.get_transform_matrix(self.aligned_frames) while (self.realsenseCamera.if_get_position_flag is not True): aligned_frames = self.realsenseCamera.get_aligned_frames() tmpimg = self.realsenseCamera.get_transform_matrix(aligned_frames) self.marked_img = tmpimg # cv2.imshow("Positioning", tmpimg) # cv2.waitKey(1) # cv2.destroyWindow("Positioning") self.needCali = 0 print("TF_Matrix Obtained!") pass def _ifMoving(self, frame1, frame2, kern, thres): gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY) gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY) if kern % 2 == 0: kern = kern + 1 # 解决滑动条赋值到高斯滤波器是偶数异常抛出 gray1 = cv2.GaussianBlur(gray1, (kern, kern), 0) gray2 = cv2.GaussianBlur(gray2, (kern, kern), 0) frameDelta = cv2.absdiff(gray1, gray2) thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1] thresh = cv2.dilate(thresh, None, iterations=2) cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] flat = False for c in cnts: if cv2.contourArea(c) > thres: # 对于较小矩形区域,选择忽略 flat = True return flat def _getCentral(self, name=None): cent = (0, 0) if name == None: for i in self.recList: c = i['center'] c = self.realsenseCamera.coor_trans_pixelxy2worldXYZ( self.aligned_frames, c) if c is None: c = (0, 0) continue if (c[0] > self.pickArea[0] and c[0] < self.pickArea[2] and c[1] > self.pickArea[1] and c[1] < self.pickArea[3]): cent = c name = i['name'] else: for i in self.recList: if (i['name'] == name): cent = self.realsenseCamera.coor_trans_pixelxy2worldXYZ( self.aligned_frames, i['center']) if cent is None: cent = (0, 0) return cent, name def _exec(self): pass
import VoiceRecognition as vr import MathFunc as mf recognized_text = vr.speechToText() x = recognized_text.split(' ') if 'math' and 'problem' in x: vr.textToSpeech('sure, what kind of problem?') recognized_text = vr.speechToText() if recognized_text == 'addition': mf.addition() elif recognized_text == 'subtraction': mf.subtraction() elif recognized_text == 'multiplication': mf.multiplication() elif recognized_text == 'division': mf.division() else: vr.textToSpeech('addition is all I can do') else: vr.textToSpeech('I can only do math problems')
ret, frame = cap.read() # show a frame #cv2.imshow("capture", frame) cv2.imwrite("cap.jpg", frame) #cap.release() #cv2.destroyAllWindows() #拍下当前摄像头前面一张图像 live = livecheck.checklive() print(live) if live == None: print("live check return None") elif float(live) > 0.8: gethello.opendoor('VoiceTip') RecordWav2.my_record() print('Over!') VoiceReturn = VoiceRecognition.RecoLocalWav() if VoiceReturn != None: VoiceText = VoiceReturn[0] if "开门" in VoiceText: print('opendoor') #这里应该在写读取’您具有开门资格的语音 gethello.opendoor('Success') serialComu.arduino_opendoor() else: print("Sorry, Voice can't be recognizied!") gethello.opendoor('VoiceNot') #serialComu.arduino_opendoor()# 向arduino传递数据进行开门操作 elif float(live) < 0.9: gethello.opendoor('notreal') print( "It seems that the people infront of the door is not a real man" )
def AECResultAutoAnalysis(PCMPath,SampleRate,MinidB,RefTime,RefPeakdB,RefVLen,AECMod): start = time.time() PCMdBList = getdBList(PCMPath, SampleRate) TestTime = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())) FFMPEG=multiprocessing.Process(target=os.system,args=('.\\ffmpeg.exe -f s16le -ar '+str(SampleRate)+' -ac 1 -i '+PCMPath+' -acodec pcm_s16le -ar 8000 out.wav -y',)) FFMPEG.daemon=True FFMPEG.start() FFMPEG.join() (VRRestult, VPAllStrLen) = VoiceRecognition.VoiceRecognition('out.wav') #单讲 if AECMod == 's' or AECMod =='S': (AllGreaterThanMinidBTime,PeakdB,AVGdB) = PCMGreaterThanMinidBTime(PCMdBList,SampleRate,MinidB) AECFailPercent = (AllGreaterThanMinidBTime / RefTime) * 100 TestResultFileName = 'SingleTalk.csv' ResultHead = 'TestTime,Result,Cooked,PeakdB,CookedTime,RefTime,Cooked/RefTime*100%,MaxVPTime,MaxVPTimedB,MiniVPTime,MiniVPTimedB,MaxVPdB,MaxVPdBTime,MiniVPdB,MiniVPdBTime,AVGVPTime,AVGVPdB,VPCount,VRRestult,CookVLen,RefVLen' if AllGreaterThanMinidBTime > 50 or PeakdB > -20: AECResult = 'F' VoicePieceList = GetVoiceList(PCMdBList,SampleRate,MinidB) VoicePieceCount = len(VoicePieceList) VoicePieceList.sort() MaxVPTime = VoicePieceList[VoicePieceCount-1][0] #VP: VoicePiece 获取最长时间片长度 MaxVPTimedB = VoicePieceList[VoicePieceCount-1][1] #最长时间片的最大dB VoicePieceList.sort(key = lambda x:(x[0],-x[1])) #按照元组的第一个(片时间)从小到大排序,如果第一个相同,则按照元组第2个(片最大dB)从大到小排序,从而可以得到时间最小但声音最大的片 MiniVPTime = VoicePieceList[0][0] #最短时间片长度 MiniVPTimedB = VoicePieceList[0][1] #最短时间片的最大dB VoicePieceList.sort(key = lambda x:x[1]) #按dB从小到大排序,若dB相同,片时间按从小到大排序 MaxVPdB = VoicePieceList[VoicePieceCount-1][1] #最大dB MaxVPdBTime = VoicePieceList[VoicePieceCount-1][0] #最大dB所在时间片的长度 VoicePieceList.sort(key = lambda x:(x[1],-x[0])) #按照元组的第2个(片最大dB)从小到大排序,如果第2个相同,则按照元组第1个(片时间)从大到小排序,从而可以得到声音最小但时间最长的片 MiniVPdB = VoicePieceList[0][1] #最小dB MiniVPdBTime = VoicePieceList[0][0] #最小dB所在时间片的长度 SumVPTime = 0 SumVPdB = 0 for i in range(VoicePieceCount): SumVPTime = SumVPTime + VoicePieceList[i][0] SumVPdB = SumVPdB + VoicePieceList[i][1] AVGVPTime = SumVPTime // VoicePieceCount AVGVPdB = SumVPdB // VoicePieceCount Result = ''.join(TestTime+','+AECResult+','+PCMPath+','+str(PeakdB)+','+str(AllGreaterThanMinidBTime)+','+str(RefTime)+','+str(AECFailPercent)+',' +str(MaxVPTime)+','+str(MaxVPTimedB)+','+str(MiniVPTime)+','+str(MiniVPTimedB)+','+str(MaxVPdB)+','+str(MaxVPdBTime)+','+str(MiniVPdB)+ ','+str(MiniVPdBTime)+','+str(AVGVPTime)+','+str(AVGVPdB)+','+str(VoicePieceCount)+','+VRRestult.replace(',','|')+','+str(VPAllStrLen)+','+str(RefVLen)) WriteTestResult(TestResultFileName, ResultHead, Result) else: AECResult = 'P' Result = ''.join(TestTime+','+AECResult+','+PCMPath+','+str(PeakdB)+','+str(AllGreaterThanMinidBTime)+','+str(RefTime)+','+str(AECFailPercent)+','*12+ VRRestult.replace(',','|')+','+str(VPAllStrLen)+','+str(RefVLen)) WriteTestResult(TestResultFileName, ResultHead, Result) #双讲 elif AECMod == 'd' or AECMod =='D': (AllGreaterThanMinidBTime,PeakdB,AVGdB) = DoubleTalkPCMGreaterThanMinidBTime(PCMdBList,SampleRate,MinidB,RefPeakdB) AECFailPercent = (AllGreaterThanMinidBTime / RefTime) * 100 TestResultFileName = 'DoubleTalk.csv' ResultHead = 'TestTime,Result,Cooked,PeakdB,CookedTime,RefTime,Cooked/RefTime*100%,VRRestult,CookVLen,RefVLen' DValue = VPAllStrLen - RefVLen if DValue > 0: AECResult = 'F' elif DValue < 0: AECResult = '有压制' else: AECResult = '效果良好' Result = ''.join(TestTime+','+AECResult+','+PCMPath+','+str(PeakdB)+','+str(AllGreaterThanMinidBTime)+','+str(RefTime)+','+str(AECFailPercent)+','+ VRRestult.replace(',','|')+','+str(VPAllStrLen)+','+str(RefVLen)) WriteTestResult(TestResultFileName, ResultHead, Result) end = time.time() print end-start,'s'
def run(self): vr.split_command(self.text) self.exit()
import sys sys.path.append("./") from SpectrumGraph import * from VoiceRecognition import * if __name__ == "__main__": whichEngine = int( input( "Select voice processing engine : \n 1 : google (online : more precise : requires internet connection) \n 2 : Built-in (offline) \n" )) if whichEngine == 1: whichEngine = "google" elif whichEngine == 2: whichEngine = "sphinx" else: whichEngine = "sphinx" VoiceRecognition(whichEngine).recognizeVoice() time.sleep(5) #noise cancelation waiting time SpectrumGraph(9, 4, False).start_plot()
def AECResultAutoAnalysis(PCMPath, SampleRate, MinidB, RefVPTime, RefTime, RefPeakdB, RefVLen, AECMod): start = time.time() TestTime = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) FFMPEG = multiprocessing.Process( target=os.system, args=(r'ffmpeg.exe -f s16le -ar ' + str(SampleRate) + ' -ac 1 -i ' + PCMPath + ' -acodec pcm_s16le -ar 8000 -ac 1 out.wav -y', )) FFMPEG.daemon = True FFMPEG.start() FFMPEG.join() (VRRestult, VPAllStrLen) = VoiceRecognition.VoiceRecognition('out.wav') #VRRestult=VRRestult.encode('gbk') #print type(VRRestult) PCMdBList = getdBList(PCMPath, SampleRate) #单讲 if AECMod == 's' or AECMod == 'S': (AllGreaterThanMinidBTime, PeakdB, AVGdB) = PCMGreaterThanMinidBTime(PCMdBList, SampleRate, MinidB) AECFailPercent = (AllGreaterThanMinidBTime / RefTime) * 100 (VoicePieceList, VoiceRefVPTimePeakdB) = GetVoiceList.GetVoiceList( PCMdBList, SampleRate, MinidB) VoicePieceCount = len(VoicePieceList) CookedVPtime = VoiceRefVPTimePeakdB[0] AECVPTimePercent = (CookedVPtime / RefVPTime) * 100 TestResultFileName = 'SingleTalk.csv' ResultHead = 'TestTime,Result,Cooked,PeakdB,CookedVPtime,RefVPTime,CookedTime/RefTime*100%,VPList,CookedTime,RefTime,CookedTime/RefTime*100%,MaxVPTime,MaxVPTimedB,MiniVPTime,MiniVPTimedB,MaxVPdB,MaxVPdBTime,MiniVPdB,MiniVPdBTime,AVGVPTime,AVGVPdB,VPCount,VRRestult,CookVLen,RefVLen,Scorce,average' VoicePieceList.sort(key=lambda x: x[1]) # #print VoicePieceList MaxVPTime = VoicePieceList[VoicePieceCount - 1][1] #VP: VoicePiece 获取最长时间片长度 #print MaxVPTime MaxVPTimedB = VoicePieceList[VoicePieceCount - 1][2] #最长时间片的最大dB VoicePieceList.sort( key=lambda x: (x[1], -x[2]) ) #按照元组的第一个(片时间)从小到大排序,如果第一个相同,则按照元组第2个(片最大dB)从大到小排序,从而可以得到时间最小但声音最大的片 MiniVPTime = VoicePieceList[0][1] #最短时间片长度 MiniVPTimedB = VoicePieceList[0][2] #最短时间片的最大dB VoicePieceList.sort(key=lambda x: x[2]) #按dB从小到大排序,若dB相同,片时间按从小到大排序 MaxVPdB = VoicePieceList[VoicePieceCount - 1][2] #最大dB MaxVPdBTime = VoicePieceList[VoicePieceCount - 1][1] #最大dB所在时间片的长度 VoicePieceList.sort( key=lambda x: (x[2], -x[0]) ) #按照元组的第2个(片最大dB)从小到大排序,如果第2个相同,则按照元组第1个(片时间)从大到小排序,从而可以得到声音最小但时间最长的片 MiniVPdB = VoicePieceList[0][2] #最小dB MiniVPdBTime = VoicePieceList[0][1] #最小dB所在时间片的长度 AVGVPTime = (VoiceRefVPTimePeakdB[0]) // VoicePieceCount AVGVPdB = (VoiceRefVPTimePeakdB[1]) // VoicePieceCount MaxVPTimedB = VoiceRefVPTimePeakdB[2] VoicePieceList = str(VoicePieceList).replace(',', '') if CookedVPtime > 50 or MaxVPdB > -35: #计算单讲平均值 #Scorce1:语音片段残留时间 Scorce1 = ('%.2f' % (1 - CookedVPtime / RefVPTime)) #Scorce2:平均语音片段长度 Scorce2 = ('%.2f' % (1 - AVGVPTime / RefVPTime)) #Scorce2 = ('%.2f' %(1-VoicePieceCount/12)) #Scorce3:峰值分贝比值 划分区段 Scorce3 = dBCompare(MaxVPdB) #Scorce41:最大片段残留时间/语音片段残留时间;Scorce42:最大片段所在的声音音量 划分区段 Scorce41 = float(('%.2f' % (1 - MaxVPTime / RefVPTime))) Scorce42 = float(dBCompare(MaxVPTimedB)) Scorce4 = ('%.2f' % (math.sqrt(Scorce41 * Scorce42))) print Scorce41, Scorce42, Scorce4 #Scorce5 = ('%.2f' %(abs(MaxVPTimedB)/abs(MinidB))) #Scorce51:最大音量 划分区段;Scorce52:最大音量所在的语音残留时间 Scorce51 = Scorce3 Scorce52 = float(('%.2f' % (1 - MaxVPdBTime / RefVPTime))) Scorce5 = float(('%.2f' % (math.sqrt(Scorce51 * Scorce52)))) #语音识别字数 Scorce6 = ('%.2f' % (1 - VPAllStrLen / RefVLen)) #加权平均值 a = (float(Scorce1), float(Scorce2), float(Scorce3), float(Scorce4), float(Scorce5), float(Scorce6)) average = 5 * (np.average(a, weights=[8, 1, 5, 1, 1, 8])) ScorceList = str(Scorce1) + ' ' + str(Scorce2) + ' ' + str( Scorce3) + ' ' + str(Scorce4) + ' ' + str(Scorce5) + ' ' + str( Scorce6) AECResult = 'F' Result = ''.join(TestTime + ',' + AECResult + ',' + PCMPath + ',' + str(PeakdB) + ',' + str(CookedVPtime) + ',' + str(RefVPTime) + ',' + str(AECVPTimePercent) + ',' + VoicePieceList + ',' + str(AllGreaterThanMinidBTime) + ',' + str(RefTime) + ',' + str(AECFailPercent) + ',' + str(MaxVPTime) + ',' + str(MaxVPTimedB) + ',' + str(MiniVPTime) + ',' + str(MiniVPTimedB) + ',' + str(MaxVPdB) + ',' + str(MaxVPdBTime) + ',' + str(MiniVPdB) + ',' + str(MiniVPdBTime) + ',' + str(AVGVPTime) + ',' + str(AVGVPdB) + ',' + str(VoicePieceCount) + ',' + VRRestult + ',' + str(VPAllStrLen) + ',' + str(RefVLen) + ',' + str(ScorceList) + ',' + str(average)) WriteTestResult(TestResultFileName, ResultHead, Result) else: AECResult = 'P' average = 5.00 VoicePieceList = str(VoicePieceList).replace(',', '') Result = ''.join(TestTime + ',' + AECResult + ',' + PCMPath + ',' + str(PeakdB) + ',' + str(CookedVPtime) + ',' + str(RefVPTime) + ',' + str(AECVPTimePercent) + ',' + VoicePieceList + ',' + str(AllGreaterThanMinidBTime) + ',' + str(RefTime) + ',' + str(AECFailPercent) + ',' * 12 + VRRestult + ',' + str(VPAllStrLen) + ',' + str(RefVLen)) + ',' * 2 + str(average) WriteTestResult(TestResultFileName, ResultHead, Result) #双讲 elif AECMod == 'd' or AECMod == 'D': reload(sys) sys.setdefaultencoding('utf-8') (AllGreaterThanMinidBTime, PeakdB, AVGdB) = DoubleTalkPCMGreaterThanMinidBTime(PCMdBList, SampleRate, MinidB, RefPeakdB) AECFailPercent = (AllGreaterThanMinidBTime / RefTime) * 100 (VoicePieceList, VoiceRefVPTimePeakdB) = GetVoiceList.GetVoiceList( PCMdBList, SampleRate, MinidB) VoicePieceCount = len(VoicePieceList) CookedVPtime = VoiceRefVPTimePeakdB[0] AECVPTimePercent = (CookedVPtime / RefVPTime) * 100 TestResultFileName = 'DoubleTalk.csv' ResultHead = 'TestTime,Result,Cooked,PeakdB,CookedVPtime,RefVPTime,CookedTime/RefTime*100%,VPList,CookedTime,RefTime,Cooked/RefTime*100%,VRRestult,CookVLen,RefVLen' #语音识别得分 DValue = VPAllStrLen - RefVLen if DValue > 0: AECResult = 'F' Scorce1 = 0.0 Scorce2 = float((CookedVPtime - VoicePieceCount * 50) / RefVPTime - 1) if Scorce2 < 0: Scorce2 = 0 elif DValue < 0: AECResult = u'有压制' Scorce1 = float(('%.2f' % (VPAllStrLen / RefVLen))) Scorce2 = float(('%.2f' % (CookedVPtime / RefVPTime))) else: AECResult = u'效果良好' Scorce1 = 1.0 Scorce2 = 1.0 #语音残留片段 a = (float(Scorce1), float(Scorce2)) average = 5 * (np.average(a, weights=[8, 2])) ScorceList = str(Scorce1) + ' ' + str(Scorce2) #print average,ScorceList VoicePieceList = str(VoicePieceList).replace(',', '') Result = ''.join(TestTime + ',' + AECResult + ',' + PCMPath + ',' + str(PeakdB) + ',' + str(CookedVPtime) + ',' + str(RefVPTime) + ',' + str(AECVPTimePercent) + ',' + VoicePieceList + ',' + str(AllGreaterThanMinidBTime) + ',' + str(RefTime) + ',' + str(AECFailPercent) + ',' + VRRestult + ',' + str(VPAllStrLen) + ',' + str(RefVLen)) WriteTestResult(TestResultFileName, ResultHead, Result) end = time.time() print end - start, 's'