maskgct / evaluation /features /long_term_average_spectrum.py
Hecheng0625's picture
Upload 167 files
8c92a11 verified
raw
history blame
573 Bytes
# Copyright (c) 2023 Amphion.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import librosa
from scipy import signal
def extract_ltas(audio, fs=None, n_fft=1024, hop_length=256):
"""Extract Long-Term Average Spectrum for a given audio."""
if fs != None:
y, _ = librosa.load(audio, sr=fs)
else:
y, fs = librosa.load(audio)
frequency, density = signal.welch(
x=y, fs=fs, window="hann", nperseg=hop_length, nfft=n_fft
)
return frequency, density