def get_mfcc_dtw(path_mapping): asim = acoustic_similarity_mapping(path_mapping, rep='mfcc', match_function='dtw', use_multi=True, num_cores=6) return asim
def calc_asim(path_mapping, rep, match_func, cache=None): asim, cache = acoustic_similarity_mapping(path_mapping, rep=rep, match_function=match_func, use_multi=True, num_cores=4, cache=cache, return_rep=True) return asim, cache
def get_mfcc_vowel_mid(path_mapping): asim = acoustic_similarity_mapping(path_mapping, rep='mfcc', match_function=midpoint_distance, use_multi=True, num_cores=6, call_back=callback) return asim
def run(self): kwargs = self.kwargs self.results = list() if kwargs['type'] == 'one': try: asim = analyze_directory(kwargs['query'], **kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return elif kwargs['type'] == 'two': try: asim, output_val = acoustic_similarity_directories( *kwargs['query'], **kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return #asim[(kwargs['query'][0],kwargs['query'][1])] = output_val elif kwargs['type'] == 'file': try: asim = acoustic_similarity_mapping(kwargs['query'], **kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return if self.stopped: return for k, v in asim.items(): if self.stopped: return self.results.append(list(k) + [v]) if kwargs['type'] == 'two': self.results.append([ os.path.basename(kwargs['query'][0]), os.path.basename(kwargs['query'][1]), output_val ]) else: self.results.append(['AVG', 'AVG', sum(asim.values()) / len(asim)]) if self.stopped: self.finishedCancelling.emit() return self.dataReady.emit(self.results)
def run(self): kwargs = self.kwargs self.results = list() if kwargs['type'] == 'one': try: asim = analyze_directory(kwargs['query'], **kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return elif kwargs['type'] == 'two': try: asim, output_val = acoustic_similarity_directories(*kwargs['query'],**kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return #asim[(kwargs['query'][0],kwargs['query'][1])] = output_val elif kwargs['type'] == 'file': try: asim = acoustic_similarity_mapping(kwargs['query'], **kwargs) except AcousticSimError as e: self.errorEncountered.emit(e) return except Exception as e: e = PCTPythonError(e) self.errorEncountered.emit(e) return if self.stopped: return for k,v in asim.items(): if self.stopped: return self.results.append(list(k) + [v]) if kwargs['type'] == 'two': self.results.append([os.path.basename(kwargs['query'][0]),os.path.basename(kwargs['query'][1]), output_val]) else: self.results.append(['AVG', 'AVG',sum(asim.values())/len(asim)]) if self.stopped: self.finishedCancelling.emit() return self.dataReady.emit(self.results)
def analyze_config(self,config, use_aic = False, num_cores = 1): kwarg_dict = config.to_kwargs() kwarg_dict['num_cores'] = num_cores asim = acoustic_similarity_mapping(self.mapping, **kwarg_dict) if use_aic: with tempfile.NamedTemporaryFile(mode='w',delete=False) as f: #with open('temp.txt','w') as f: tempname = f.name #tempname = 'temp.txt' header = [x for x in self.listenerResp[0].keys() if x != 'axbtuple'] + ['Independent'] writer = DictWriter(f,header,delimiter='\t') writer.writerow({x:x for x in header}) for line in self.listenerResp: try: line.update({'Independent': asim[line['axbtuple']]}) writer.writerow({k:v for k,v in line.items() if k != 'axbtuple'}) except KeyError: pass scriptname = os.path.join(os.path.dirname(os.path.abspath(__file__)),'get_aic.r') com = ['Rscript',scriptname,tempname] p = subprocess.Popen(com,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE) stdout, stderr = p.communicate() if stderr: print(com) print(stderr) raise(ValueError) output = str(stdout.decode()).strip() if output == 'LmerError': print(com) raise(ValueError) aic = float(output) os.remove(tempname) return aic x = [] y = [] for k,v in asim.items(): resps = array([int(l['Dependent']) for l in self.listenerResp if l['axbtuple'] == k]) if len(resps) == 0: continue x.append(sum(resps)/len(resps)) y.append(v) correlation = pearsonr(x,y) return correlation[0]
def calc_asim(path_mapping, rep, match_func, cache = None): asim, cache = acoustic_similarity_mapping(path_mapping, rep = rep, match_function = match_func, use_multi=True, num_cores = 4, cache = cache, return_rep = True) return asim, cache
def get_mfcc_vowel_mid(path_mapping): asim = acoustic_similarity_mapping(path_mapping, rep = 'mfcc', match_function = midpoint_distance, use_multi=True, num_cores = 6, call_back = callback) return asim
def get_mfcc_dtw(path_mapping): asim = acoustic_similarity_mapping(path_mapping, rep = 'mfcc', match_function = 'dtw', use_multi=True, num_cores = 6) return asim
def analyze_config(self, config, use_aic=False, num_cores=1): kwarg_dict = config.to_kwargs() kwarg_dict['num_cores'] = num_cores asim = acoustic_similarity_mapping(self.mapping, **kwarg_dict) if use_aic: with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: #with open('temp.txt','w') as f: tempname = f.name #tempname = 'temp.txt' header = [ x for x in self.listenerResp[0].keys() if x != 'axbtuple' ] + ['Independent'] writer = DictWriter(f, header, delimiter='\t') writer.writerow({x: x for x in header}) for line in self.listenerResp: try: line.update({'Independent': asim[line['axbtuple']]}) writer.writerow( {k: v for k, v in line.items() if k != 'axbtuple'}) except KeyError: pass scriptname = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'get_aic.r') com = ['Rscript', scriptname, tempname] p = subprocess.Popen(com, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) stdout, stderr = p.communicate() if stderr: print(com) print(stderr) raise (ValueError) output = str(stdout.decode()).strip() if output == 'LmerError': print(com) raise (ValueError) aic = float(output) os.remove(tempname) return aic x = [] y = [] for k, v in asim.items(): resps = array([ int(l['Dependent']) for l in self.listenerResp if l['axbtuple'] == k ]) if len(resps) == 0: continue x.append(sum(resps) / len(resps)) y.append(v) correlation = pearsonr(x, y) return correlation[0]