This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dd2c6c
commit bc486b6
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
import numpy as np | ||
from scipy.interpolate import interp1d | ||
from whisper.audio import SAMPLE_RATE | ||
|
||
|
||
def resample(x: np.ndarray, source_sr: int) -> np.ndarray: | ||
"""Resample a numpy array to match the SAMPLE_RATE | ||
of Whisper (16 000 Hz). | ||
Args: | ||
x (np.ndarray): Source numpy array | ||
source_sr (int): Source sample rate | ||
Returns: | ||
np.ndarray: The resampled array | ||
""" | ||
|
||
if source_sr == SAMPLE_RATE: | ||
return x | ||
factor = source_sr / SAMPLE_RATE | ||
n = int(np.ceil(x.size / factor)) | ||
f = interp1d(np.linspace(0, 1, x.size), x, "linear") | ||
return f(np.linspace(0, 1, n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters