def get_pitch_and_formants(f): func = PitchTrackFunction(time_step=0.01, min_pitch=75, max_pitch=600) pitch = func(f) func = FormantTrackFunction(time_step=0.01, window_length=0.025, num_formants=5, max_frequency=5500) formants = func(f) # sync kp = np.array( list( pitch.keys() ) ) kf = np.array( list( formants.keys() ) ) synced = {} for t in kp: # find nearest value in formants idx = (np.abs( kf - t )).argmin() formants_freqs_list = [] formants_ratios_list = [] formants_amps_list = [] current_pitch = pitch[ t ] if current_pitch[0] != 0: for fmnt in formants[ kf[ idx ] ]: if current_pitch[0] is not None and fmnt[0] is not None: formants_freqs_list.append( fmnt[0] ) formants_amps_list.append( fmnt[1] ) formants_ratios_list.append( fmnt[0]/current_pitch[0] ) synced[ t ] = { 'pitch': pitch[ t ], 'time': t, 'formants_freqs': formants_freqs_list, 'formants_amps': formants_amps_list, 'formants_ratios': formants_ratios_list, } return synced, pitch, formants, kp, kf
def test_formants_praat(base_filenames): for f in base_filenames: wavpath = f + '.wav' func = FormantTrackFunction(time_step=0.01, window_length=0.025, num_formants=5, max_frequency=5500) formants = func(wavpath) sig, sr = librosa.load(wavpath) formants2 = func(SignalSegment(sig, sr))
def generate_base_formants_function(corpus_context, gender=None): algorithm = corpus_context.config.formant_source max_freq = 5500 if gender == 'M': max_freq = 5000 if algorithm == 'praat': if getattr(corpus_context.config, 'praat_path', None) is None: raise (AcousticError('Could not find the Praat executable')) formant_function = PraatSegmentFormantTrackFunction( praat_path=corpus_context.config.praat_path, max_frequency=max_freq, num_formants=5, window_length=0.025, time_step=0.01) else: formant_function = FormantTrackFunction(max_frequency=max_freq, time_step=0.01, num_formants=5, window_length=0.025) return formant_function
def generate_base_formants_function(corpus_context, gender=None, source='praat'): """ Parameters ---------- corpus_context : :class:`polyglot.corpus.context.CorpusContext` The CorpusContext object of the corpus. gender : str The gender to use for the function, if "M"(male) then the max frequency is 5000 Hz, otherwise 5500 source : str The source of the function, if it is "praat" then the formants will be calculated with Praat over each segment otherwise it will simply be tracks Returns ------- formant_function : Partial function object The function used to call Praat. """ max_freq = 5500 if gender == 'M': max_freq = 5000 if source == 'praat': if getattr(corpus_context.config, 'praat_path', None) is None: raise (AcousticError('Could not find the Praat executable')) formant_function = PraatSegmentFormantTrackFunction( praat_path=corpus_context.config.praat_path, max_frequency=max_freq, num_formants=5, window_length=0.025, time_step=0.01) else: formant_function = FormantTrackFunction(max_frequency=max_freq, time_step=0.01, num_formants=5, window_length=0.025) return formant_function
def formants_func(): func = FormantTrackFunction(max_frequency=5000, time_step=0.01, num_formants=5, window_length=0.025) return func