import librosa
import numpy as np
import matplotlib.pyplot as plt
[docs]
class VoiceSample:
"""Class to load and process audio samples."""
def __init__(self, x: np.ndarray, fs: int):
"""Initialize with audio waveform and sampling rate."""
self.x = x
self.fs = fs
[docs]
@classmethod
def from_wav(cls, file_path: str, sr: int = None):
"""Load a WAV file and return a VoiceSample instance."""
x, fs = librosa.load(file_path, sr=sr)
return cls(x, fs)
[docs]
def get_sampling_rate(self):
"""Return the sampling rate."""
return self.fs