Converts an integer PCM audio signal to a floating-point representation. This function scales an integer PCM audio waveform (typically `int16`) to a `float32` format, normalizing the values to the range [-1.0, 1.0]. Args: sound (Union[np.ndarray, list]): The
(sound: Union[np.ndarray, list])
| 4 | |
| 5 | |
| 6 | def int2float(sound: Union[np.ndarray, list]) -> np.ndarray: |
| 7 | """Converts an integer PCM audio signal to a floating-point representation. |
| 8 | |
| 9 | This function scales an integer PCM audio |
| 10 | waveform (typically `int16`) |
| 11 | to a `float32` format, normalizing the values |
| 12 | to the range [-1.0, 1.0]. |
| 13 | |
| 14 | Args: |
| 15 | sound (Union[np.ndarray, list]): |
| 16 | The input audio signal in integer format. |
| 17 | Typically a NumPy array or a list of integers. |
| 18 | |
| 19 | Returns: |
| 20 | np.ndarray: |
| 21 | The audio signal converted to `float32` format and normalized. |
| 22 | Taken from https://github.com/snakers4/silero-vad |
| 23 | """ |
| 24 | |
| 25 | abs_max = np.abs(sound).max() |
| 26 | sound = sound.astype("float32") |
| 27 | if abs_max > 0: |
| 28 | sound *= 1 / 32768 |
| 29 | sound = sound.squeeze() # depends on the use case |
| 30 | return sound |
no outgoing calls
no test coverage detected
searching dependent graphs…