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

Function transcribe

funasr/bin/_server_app.py:192–244  ·  view source on GitHub ↗
(
        file: UploadFile = File(...),
        model: str = Form(default="fun-asr-nano"),
        language: Optional[str] = Form(default=None),
        response_format: Optional[str] = Form(default="json"),
        spk: bool = Form(default=False),
    )

Source from the content-addressed store, hash-verified

190
191 @app.post("/v1/audio/transcriptions")
192 async def transcribe(
193 file: UploadFile = File(...),
194 model: str = Form(default="fun-asr-nano"),
195 language: Optional[str] = Form(default=None),
196 response_format: Optional[str] = Form(default="json"),
197 spk: bool = Form(default=False),
198 ):
199 content = await file.read()
200 t0 = time.perf_counter()
201
202 if model == "fun-asr-nano":
203 _load_vllm_engine()
204 if app.state.use_vllm:
205 audio_data, sr = sf.read(io.BytesIO(content))
206 result = _process_vllm(audio_data, sr, language=language, use_spk=spk)
207 else:
208 suffix = os.path.splitext(file.filename)[1] if file.filename else ".wav"
209 with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
210 tmp.write(content)
211 tmp_path = tmp.name
212 try:
213 result = _process_fallback("fun-asr-nano", tmp_path, language=language)
214 finally:
215 os.unlink(tmp_path)
216 elif model in FALLBACK_CONFIGS:
217 suffix = os.path.splitext(file.filename)[1] if file.filename else ".wav"
218 with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
219 tmp.write(content)
220 tmp_path = tmp.name
221 try:
222 result = _process_fallback(model, tmp_path, language=language)
223 finally:
224 os.unlink(tmp_path)
225 else:
226 raise HTTPException(400, f"Unknown model '{model}'. Available: fun-asr-nano, {', '.join(FALLBACK_CONFIGS.keys())}")
227
228 t1 = time.perf_counter()
229
230 if response_format == "verbose_json":
231 return JSONResponse({
232 "task": "transcribe",
233 "language": language or "zh",
234 "duration": result.get("duration", 0),
235 "text": result["text"],
236 "segments": [
237 {"id": i, "start": s["start"], "end": s["end"], "text": s["text"], "words": s.get("words", [])}
238 for i, s in enumerate(result["segments"])
239 ],
240 })
241 elif response_format == "text":
242 return JSONResponse(result["text"])
243 else:
244 return JSONResponse({"text": result["text"]})
245
246 @app.post("/asr")
247 async def asr_endpoint(

Callers

nothing calls this directly

Calls 7

_load_vllm_engineFunction · 0.85
_process_vllmFunction · 0.85
_process_fallbackFunction · 0.85
keysMethod · 0.80
FileClass · 0.50
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…