MCPcopy Create free account
hub / github.com/espnet/espnet / int2float

Function int2float

espnet2/sds/utils/utils.py:6–30  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

4
5
6def 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

Callers 4

forwardMethod · 0.90
handle_espnet_ASR_WERFunction · 0.90
TTS_psuedomosFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…