MCPcopy Create free account
hub / github.com/modelscope/FunASR / _pcm_duration_ms

Function _pcm_duration_ms

runtime/python/websocket/funasr_wss_server.py:141–148  ·  view source on GitHub ↗

根据 fs/ch/sampwidth 计算 PCM 时长,避免写死 16k -> 32 bytes/ms。

(pcm_bytes: bytes, fs: int, ch: int = 1, sampwidth: int = 2)

Source from the content-addressed store, hash-verified

139
140
141def _pcm_duration_ms(pcm_bytes: bytes, fs: int, ch: int = 1, sampwidth: int = 2) -> int:
142 """根据 fs/ch/sampwidth 计算 PCM 时长,避免写死 16k -> 32 bytes/ms。"""
143 if not pcm_bytes:
144 return 0
145 bytes_per_ms = (fs * ch * sampwidth) / 1000.0
146 if bytes_per_ms <= 0:
147 return 0
148 return int(len(pcm_bytes) / bytes_per_ms)
149
150
151def _safe_int(v, default):

Callers 2

ws_serveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…