def do_GET(s): s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() path = s.path if '-' in path: acao, nome, pessoa = path.split('-') if acao.replace('/', '') == 'gravar': #Adicionando pessoa ao banco db.add_model((caminhoVoz + nome), pessoa) v = Voiceid(db, (caminhoVoz + nome + ".wav")) s.wfile.write("Gravado") if acao.replace('/', '') == 'biometria': #Verificação de arquivo de voz v = Voiceid(db, (caminhoVoz + nome + ".wav")) usuario = v.extract_speakers() s.wfile.write("%s" % usuario) if not "S0 (unknown)" in str(usuario): ser.write(ledLigado) for the_file in os.listdir(caminhoVoz): file_path = os.path.join(caminhoVoz, the_file) try: if os.path.isfile(file_path): os.unlink(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) except Exception, e: print e
def set_name(device_id, voice_path, new_name): print "set " + voice_path + " to: " + new_name new_name = new_name.replace(' ', '') if not new_name.isalnum(): print 'error: SPEAKER_ID must be alphanumeric' return if new_name in db.get_speakers()['U'] or new_name in db.get_speakers( )['M'] or new_name in db.get_speakers()['F']: voice = Voiceid(db, voice_path, single=True) voice.extract_speakers(quiet=True, thrd_n=3) cluster = voice.get_cluster('S0') cluster.set_speaker(new_name) voice.update_db() return try: # assume only one speaker in one sample ww = fm.file2wav(voice_path) file_basename, extension = os.path.splitext(ww) db.add_model(file_basename, new_name) os.remove(file_basename + ".seg") os.remove(file_basename + ".ident.seg") os.remove(file_basename + ".init.gmm") except IOError: print "voice file doesn't exist" except OSError: print "WARNING: error deleting some intermediate files" except TypeError: print "Type error"
def segment_input(wavfile, dbpath='./voicedb'): db = GMMVoiceDB(dbpath) v = Voiceid(db, wavfile) v.extract_speakers() speaker_clusters={} for c in v.get_clusters(): cluster = v.get_cluster(c) print cluster cluster.print_segments() print
def voicerec(fname): db = GMMVoiceDB('models') v = Voiceid(db, fname) v.extract_speakers() txt = '' for c in v.get_clusters(): cl = v.get_cluster(c) cluster = str(cl) cluster = cluster.split(' ') cluster = cluster[1] cluster = cluster.strip('(') cluster = cluster.strip(')') txt = txt + 'Speaker : ' + cluster seg = str(cl.print_segments()) txt = txt + '\n' + seg out.insertPlainText(txt + "\n")
def recognize(device_id, voice_path): # voice_db_lock.acquire() print db.get_speakers() # assume only one speaker in one sample, To Do: multiple speakers in one sample # set to True to force to avoid diarization, in case a single speaker in the file try: voice = Voiceid(db, voice_path, single=True) # extract_speakers(interactive=False, quiet=False, thrd_n=1) voice.extract_speakers(quiet=True, thrd_n=3) # clusters = voice.get_clusters() cluster = voice.get_cluster('S0') # speaker = cluster.get_best_speaker() speaker = "unknown" speakers = cluster.get_best_five() if len(speakers) > 0: value = speakers[0][1] if value > -33.0: speaker = speakers[0][0] # speaker = cluster.get_speaker() print speaker payload = { 'audio': 'http://52.24.205.33/voice/' + voice_path, 'userName': speaker, 'time': '1' } requests.post('http://129.236.234.21:8080/message', data=json.dumps(payload), headers=HEADERS) client.publish("ais/recognize/result/" + device_id + "/" + voice_path, speaker) os.remove(voice.get_file_basename() + '.seg') os.remove(voice.get_file_basename() + '.g.seg') os.remove(voice.get_file_basename() + '.s.seg') w = voice.get_file_basename() + '.wav' if voice.get_filename() != w: os.remove(w) shutil.rmtree(voice.get_file_basename()) except IOError: print "voice file doesn't exist"
from voiceid.sr import Voiceid from voiceid.db import GMMVoiceDB # create voice db db = GMMVoiceDB("voice") # add models to db: params the basename of # 'giov_wave.wav' and the speaker, Giovanni # db.add_model("rec", "test") # db.add_model("irina", "irina") # print db.get_speakers() # process a video/audio file containing various speakers v = Voiceid(db, "rec.wav") # extract the speakers from file and search into db v.extract_speakers() bestUsers = v.get_user() print "Dict: " + str(bestUsers) print "Max: " + max(bestUsers, key=bestUsers.get) """ for c in v.get_clusters(): cluster = v.get_cluster(c) print cluster.get_best_speaker() """
def checkAudio(self, audio): """ Check voices inside audio file """ v = Voiceid(self._db, audio) v.extract_speakers(quiet=True) return v
def save_callback(self, file_=None): """ Adds a file to the queue after it's been saved """ if self.test_mode == True: vid = Voiceid(self.db, file_, single=True) self.queue_processes.append((vid, None))
#Using voiceid(google opensource project) for voice recognisation using python from voiceid.sr import Voiceid from voiceid.db import GMMVoiceDB db = GMMVoiceDB('mydir') #creating database/directory of registered voices db.add_model('C:\Users\raman\Documents\raman.wma', 'Raman','M') db.add_model('C:\Users\raman\Documents\lalit.wma', 'Lalit','M') db.add_model('C:\Users\raman\Documents\aneesha.wma', 'Aneesha','F') db.add_model('C:\Users\raman\Documents\priyanka.wma', 'Priyanka','F') db.get_speakers() # this will get all the speakers in the database/directory if(db.matchvoice('C:\Users\raman\Documents\lalit.wma', 'Lalit')) #the matchvoice function will compare the voices { print "Lalit is present" } else print "Lalit is absent" v = Voiceid(db) v.extract_speakers() for c in v.get_clusters(): cluster = v.get_cluster(c) print cluster cluster.print_segments()