Hello
I am trying to compute formants using the following code , but getting all values as NaN. Tried the code for both mono (16khz) and stereo (44.1khz) files. the output is NaN.
When i executed code for pitch, intensity, vowel onset point, the wav file worked well and gave correct output, only problem lies while computing formants. so i am sharing code for formants computation.
import parselmouth
def extract_formants(audio_path):
try:
# Load the audio using parselmouth
sound = parselmouth.Sound(audio_path)
# Extract formants
formants = sound.to_formant_burg()
# Extract F1, F2, F3 frequencies
f1_freqs = formants.get_value_at_time(1, 0) # First formant frequency
f2_freqs = formants.get_value_at_time(2, 0) # Second formant frequency
f3_freqs = formants.get_value_at_time(3, 0) # Third formant frequency
return f1_freqs, f2_freqs, f3_freqs
except Exception as e:
print(f"Error processing {audio_path}: {str(e)}")
return None, None, None
# Example usage:
audio_path = 'C:/Users/m.wav'
f1, f2, f3 = extract_formants(audio_path)
if f1 is not None and f2 is not None and f3 is not None:
print(f"F1: {f1} Hz, F2: {f2} Hz, F3: {f3} Hz")
else:
print("Formant extraction failed.")
Inputs are welcomed;