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

Function validate_frame_rate

funasr/utils/load_utils.py:240–274  ·  view source on GitHub ↗

Validate frame rate. Args: input: Input audio/text data. fs: TODO.

(
    input,
    fs: int = 16000,
)

Source from the content-addressed store, hash-verified

238
239
240def validate_frame_rate(
241 input,
242 fs: int = 16000,
243):
244
245 # 将文件读取为字节流
246 """Validate frame rate.
247
248 Args:
249 input: Input audio/text data.
250 fs: TODO.
251 """
252 byte_data = BytesIO(input)
253
254 # 使用 pydub 加载音频
255 try:
256 audio = AudioSegment.from_file(byte_data)
257 except:
258 raise RuntimeError(
259 "You are decoding the pcm data, please install pydub first. via `pip install pydub`."
260 )
261
262 # 确保采样率为 16000 Hz
263 if audio.frame_rate != fs:
264 audio = audio.set_frame_rate(fs)
265
266 # 将重新采样后的音频导出为字节流
267 output = BytesIO()
268 audio.export(output, format="wav")
269 output.seek(0)
270
271 # 获取重新采样后的字节流数据
272 input = output.read()
273
274 return input
275
276
277def extract_fbank(data, data_len=None, data_type: str = "sound", frontend=None, **kwargs):

Callers 1

load_bytesFunction · 0.85

Calls 2

exportMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…