def diarization(file_properties): cd_go="cd " + get_base_dir() + "/plugins_script/speaker_extractor/;" java="java -Xmx2048m " #da definire in base alla macchina java_classpath = " -classpath " + get_base_dir() + "/plugins_script/speaker_extractor/lium_spkdiarization-8.4.1.jar " commandline=java+java_classpath+" it.crs4.identification.DBScore \""+file_properties + "\"" #commandline = java+java_classpath + " it.crs4.active.diarization.Diarization \"" +file_properties + "\"" # effettua solo lo splitting print "diarization -- command \n" print commandline start_subprocess(commandline)
def _build_model(audio_file,train_wav_file,name_surname,duration, token): classpath= os.path.join(get_base_dir(), 'plugins_script',"speaker_extractor","lium_spkdiarization-8.4.1.jar" ) ubm= os.path.join(get_media_root(),"models/audio/globals/ubm.gmm") start=0 audio_file="/tmp/prova.wav" gmm_path= build_model (classpath, ubm,audio_file, start, duration, train_wav_file, name_surname, token) return gmm_path
def __build_model(auth_params, func_params): """ Funzione utilizzata per costruire il modello di riconoscimento audio a partire da un insieme di istanze che vengono fornite dall'utente attraverso l'apposita GUI. In particolar ela funzione consente di : - ottenere la lista di istanze specificate dall'utente - recuperare il path completo associato a ciascuna istanza - unire le istanze in un unico file audio - effettuare la costruzione del modello di riconoscimento vocale - creare la persona e il modello sul database - associare i file creati alla persona e al modello - rimuovere tutti i file temporanei creati """ try: token = auth_params.get('token', '1234') f_name = func_params.get('first_name', 'Pinco') s_name = func_params.get('last_name', 'Pallino') inst_ids = func_params.get('inst_list', []) ubm = os.path.join(get_media_root(), 'models', 'audio', 'globals', 'ubm.gmm') classpath= os.path.join(get_base_dir(), 'plugins_script', 'speaker_extractor' , 'lium_spkdiarization-8.4.1.jar') # crea un modello e una persona con i dati forniti person = create_person(f_name, s_name, token=token) model = create_model(person['id'], 'audio', f_name + ' ' + s_name, last_update=None, token=token) #print person, model # recupera gli oggetti corrispondenti alle istanze #print inst_ids inst_paths = [] for inst_id in inst_ids: inst = get_instance(inst_id, token=token) inst_paths.append(os.path.join(get_media_root(), inst['features'])) #print inst_paths # concat all provided feature files temp = '/tmp/model_' + str(model['id']) + '.wav' concatena_multi(inst_paths, temp) #print temp # calcola e imposta il modello generato nel database model_path = create_new_model(classpath, ubm, temp, 0, None, None) set_model_file(model['id'], model_path, token=token) #print model_path # remove all created temporary files #os.remove(model_path) except Exception as e: print e return 'Error during entity model building'
def post_di_esempio(id_item, fp,token): print "***** PLUGIN SPEAKER RECOGNITION: POST DI ESEMPIO ---> Start" classpath= os.path.join(get_base_dir(), 'plugins_script',"speaker_extractor","lium_spkdiarization-8.4.1.jar" ) ubm= os.path.join(get_media_root(),"models/audio/globals/ubm.gmm") id_persona=None #id_item=3601 #name_p=open(name_file, "r") #name_p_list=name_p.readlines() #result=make_name_compact(fp) #result simile a [[nome,start,stop][nome,start,stop]] result=segfile_compact_name2(fp) print "result=",result uniform_tag_ids_arr =[] for res in result: try: name=res[0] feature_path = None model = None p=re.compile('[A-Z]') print "find name ", name st=int( float(res[1]))#*1000 ) print "start ", st dur=int (float(res[2]))#*1000) print "dur ",dur #feature_path = split4diarization(fp,st,dur,fp+"_"+str(st)+"_"+str(dur)) feature_path = split4diarization(os.path.join(get_media_root(), 'items', str(id_item), 'audio.wav'),st,dur,"/tmp/model.wav") print "feature_path ", feature_path inst = create_instance('audio', False, token=token) # impostare id modello set_instance_feature(inst['id'], feature_path, token) #if name.find("GiacomoMameli")>-1: # print "trovato giacomino" # id_persona=create_person("Giacomo","Mameli", token)["id"] # #createTagKeyword(id_item, 'Giacomo', 'Mameli', token) # print "id persona ",id_persona #else: if True: mai=p.findall(name) print "mai ",mai #if len(mai)==2: if True: #f_name=name.split(mai[1])[0] #s_name=mai[1]+name.split(mai[1])[1] f_name="Unknown" s_name=name + '_' + str(id_item) print "f_name, s_name ", f_name, s_name # corregge il problema delle identita' duplicate persona = None #feature_path = split4diarization(fp,st,dur,"/tmp/model_wav") if f_name == "Unknown": print "name Unknown" persona=create_person(f_name,s_name, token) #feature_path = split4diarization(fp,0,None,"/tmp/model_wav") #model_path=_build_model("/tmp/model.wav", None, [f_name, s_name],dur, token) # crea il modello associato alla persona sconosciuta #model_path= create_new_model (classpath, ubm,feature_path, 0, dur,None) #f_name+"_"+ s_name) #print "model_path ",model_path #model = create_model(persona['id'], 'audio', f_name + ' ' + s_name, last_update=None, token=token) ##set_model_file(model['id'], model_path, token=token) #else: # print " persona nota ", f_name, s_name # persona=create_person(f_name, s_name, token) # print "persona ", persona # # list out of bound # model = get_models_by_entity(persona['id'], token=token)[0] # print "model ", model # create a tag for person name #createTagKeyword(id_item, persona['first_name'], persona['last_name'], token) print "calcolo id persona" id_persona=persona["id"] print "id_persona ",id_persona #else: # persona=create_person("Il","Manutentore", token) # id_persona=persona["id"] print "create_tag id_item,id_persona ", id_item, " ",id_persona tag=create_tag(id_item,id_persona, "speaker", token) print "tag ",tag dtag=create_dtag(tag["id"], st*10, dur*10, token=token) print "dtag ",dtag uniform_tag = create_tag(id_item, id_persona, "face+speaker", token) print 'uniform tag', uniform_tag uniform_tag_ids_arr.append(uniform_tag['id']) # update the instance with the model id print 'instance, model', inst, model #edit_instance(inst['id'], model_id=model['id'], token=token) print 'ascallo' except Exception, e: print e