MCPcopy Index your code
hub / github.com/modelscope/FunASR / load_bytes

Function load_bytes

funasr/utils/load_utils.py:207–237  ·  view source on GitHub ↗

Convert audio bytes to numpy array. Args: input (bytes): Raw audio bytes. Returns: numpy.ndarray: Decoded audio samples.

(input)

Source from the content-addressed store, hash-verified

205
206
207def load_bytes(input):
208 """Convert audio bytes to numpy array.
209
210 Args:
211 input (bytes): Raw audio bytes.
212
213 Returns:
214 numpy.ndarray: Decoded audio samples.
215 """
216 # Only run the (expensive) frame-rate validation when the payload is an
217 # actual audio container (WAV, MP3, OGG, …). Raw PCM buffers have no
218 # recognisable header and would cause pydub to spend ~200 ms before
219 # raising an exception that is then silently swallowed anyway.
220 if _is_audio_container(input):
221 try:
222 input = validate_frame_rate(input)
223 except Exception:
224 pass
225 middle_data = np.frombuffer(input, dtype=np.int16)
226 middle_data = np.asarray(middle_data)
227 if middle_data.dtype.kind not in "iu":
228 raise TypeError("'middle_data' must be an array of integers")
229 dtype = np.dtype("float32")
230 if dtype.kind != "f":
231 raise TypeError("'dtype' must be a floating point type")
232
233 i = np.iinfo(middle_data.dtype)
234 abs_max = 2 ** (i.bits - 1)
235 offset = i.min + abs_max
236 array = np.frombuffer((middle_data.astype(dtype) - offset) / abs_max, dtype=np.float32)
237 return array
238
239
240def validate_frame_rate(

Callers 1

prepare_data_iteratorFunction · 0.90

Calls 2

_is_audio_containerFunction · 0.85
validate_frame_rateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…