Instructions to use MaHaWo/iSparrow_test_models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use MaHaWo/iSparrow_test_models with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("MaHaWo/iSparrow_test_models") - Notebooks
- Google Colab
- Kaggle
Download google_perch_lite/preprocessor.py from MaHaWo/iSparrow_test_models: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/MaHaWo/iSparrow_test_models/resolve/main/google_perch_lite/preprocessor.py
- Command line
-
hf download hf://MaHaWo/iSparrow_test_models/google_perch_lite/preprocessor.py
-
curl -L -o preprocessor.py https://huggingface.co/MaHaWo/iSparrow_test_models/resolve/main/google_perch_lite/preprocessor.py
2.24 kB
| import numpy as np | |
| import iSparrow.preprocessor_base as ppb | |
| class Preprocessor(ppb.PreprocessorBase): | |
| def __init__( | |
| self, | |
| sample_rate: int = 32000, | |
| sample_secs: float = 5.0, | |
| resample_type: str = "kaiser_fast", | |
| **kwargs | |
| ): | |
| super().__init__( | |
| "google_perch_lite", | |
| sample_rate=sample_rate, | |
| sample_secs=sample_secs, | |
| resample_type=resample_type, | |
| **kwargs | |
| ) | |
| def process_audio_data(self, rawdata: np.array) -> np.array: | |
| # raise when sampling rate is unequal. | |
| if self.actual_sampling_rate != self.sample_rate: | |
| raise RuntimeError( | |
| "Sampling rate is not the desired one. Desired sampling rate: {self.sample_rate}, actual sampling rate: {self.actual_sampling_rate}" | |
| ) | |
| seconds = self.sample_secs | |
| minlen = 1.5 | |
| self.chunks = [] | |
| for i in range( | |
| 0, len(rawdata), int((seconds - self.overlap) * self.sample_rate) | |
| ): | |
| split = rawdata[i : (i + int(seconds * self.actual_sampling_rate))] | |
| # End of signal? | |
| if len(split) < int(minlen * self.actual_sampling_rate): | |
| break | |
| # Signal chunk too short? Fill with zeros. | |
| if len(split) < int(self.actual_sampling_rate * seconds): | |
| temp = np.zeros((int(self.actual_sampling_rate * seconds))) | |
| temp[: len(split)] = split | |
| split = temp | |
| self.chunks.append(split) | |
| print( | |
| "process audio data google: complete, read ", | |
| str(len(self.chunks)), | |
| "chunks.", | |
| flush=True, | |
| ) | |
| return self.chunks | |
| def from_cfg(cls, cfg: dict): | |
| # make sure there are no more than the allowed keyword arguments in the cfg | |
| allowed = [ | |
| "sample_rate", | |
| "sample_secs", | |
| "resample_type", | |
| "duration", | |
| "actual_sampling_rate", | |
| ] | |
| if len([key for key in cfg if key not in allowed]) > 0: | |
| raise RuntimeError("Erroneous keyword arguments in preprocessor config") | |
| return cls(**cfg) | |