Download utils.py from brenth82/diarizer: direct link, hf CLI and curl.
- Browser
- Download file 489 Bytes
-
https://huggingface.co/spaces/brenth82/diarizer/resolve/main/utils.py
- Command line
-
hf download hf://spaces/brenth82/diarizer/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/brenth82/diarizer/resolve/main/utils.py
489 Bytes
| import numpy as np | |
| import librosa | |
| import matplotlib.pyplot as plt | |
| from librosa.display import specshow | |
| def plot_spec(y: np.ndarray, sr: int, title: str = "Spectrogram") -> plt.Figure: | |
| y[np.isnan(y)] = 0 | |
| y[np.isinf(y)] = 0 | |
| stft = librosa.stft(y=y) | |
| D = librosa.amplitude_to_db(np.abs(stft), ref=np.max) | |
| fig = plt.figure(figsize=(10, 4)) | |
| specshow(D, sr=sr, y_axis="linear", x_axis="time", cmap="viridis") | |
| plt.title(title) | |
| plt.tight_layout() | |
| return fig | |