This file provides guidance to Claude Code when working on this project.
funasr-server is a self-contained FunASR inference server with one-click installation. It provides a Python client SDK that communicates with a background server process over HTTP using JSON-RPC 2.0.
Host Application (Python 3.10+)
│ HTTP + JSON-RPC 2.0
▼
FunASR Server (Starlette + uvicorn, isolated uv environment)
│ Models cached in memory
▼
FunASR Core (PyTorch)
- Client SDK (
src/funasr_server/client.py):FunASRclass manages server lifecycle,Modelclass wraps loaded models - Server (
src/funasr_server/runtime_template/server.py): Runs in an isolated Python environment managed by uv. Copied to runtime dir during installation - Model Registry (
src/funasr_server/models.py): 40+ models with hub-agnostic name resolution (ModelScope for China, HuggingFace internationally) - Installer (
src/funasr_server/installer.py): Handles uv installation, runtime directory creation, dependency sync - Mirror (
src/funasr_server/mirror.py): Region detection (China vs international) via concurrent host probing
| File | Purpose |
|---|---|
src/funasr_server/__init__.py |
Public API exports |
src/funasr_server/client.py |
Core client SDK (FunASR, Model, ServerError) |
src/funasr_server/installer.py |
Runtime environment setup |
src/funasr_server/mirror.py |
Region detection and mirror selection |
src/funasr_server/models.py |
Model registry and name resolution |
src/funasr_server/runtime_template/server.py |
JSON-RPC server (deployed to runtime dir) |
src/funasr_server/runtime_template/pyproject.toml |
Server-side dependencies |
# Run all tests
python -m pytest tests/ -v
# Run unit tests only (no real server/models)
python -m pytest tests/ -v -m "not integration"
# Run integration tests (requires GPU/models, slow)
python -m pytest tests/ -v -m integration
# Run a single test file
python -m pytest tests/test_client.py -v- Unit tests (
test_client.py,test_server.py,test_installer.py,test_mirror.py,test_models.py): Use mocks, no real server needed - Integration tests (
test_integration.py): Start real server, load models, run inference. Marked with@pytest.mark.integration - Test audio fixture:
tests/fixtures/asr_example.wav - Mock RPC handler in
test_client.pysimulates server responses
- Runtime template:
server.pyis copied fromruntime_template/to the runtime directory duringInstaller.install(). Changes toruntime_template/server.pyrequire either reinstalling or manually copying to the runtime dir for testing - Model name resolution: User-friendly names (e.g. "SenseVoiceSmall") are resolved to hub-specific IDs (e.g. "iic/SenseVoiceSmall" for ModelScope) via
resolve_model_id() - Blocking methods:
infer,transcribe,load_model,download_modelrun inrun_in_executoron the server so concurrent requests (likeget_progress) can be handled - Progress tracking: Server stores progress in
_progressdict during inference, client polls viaget_progressRPC. Progress granularity depends on VAD segment count
- Client SDK: Zero external dependencies (pure Python 3.10+)
- Server runtime: FunASR, PyTorch 2.0+, torchaudio, transformers, uvicorn, starlette (managed by uv in isolated environment)
- Dev: pytest >= 8.0
paraformer-zh+fsmn-vad+ct-punc: Full pipeline, official recommendationSenseVoiceSmall+fsmn-vad: OK. Do NOT combine withct-punc(corrupts special tags)Fun-ASR-Nano: Standalone only. Errors with VAD (batch_size incompatibility in FunASR framework)cam++,emotion2vec_*,ct-punc,fsmn-vad: Standalone only