Add low-code workflow recipes for Dify, n8n, HTTP nodes, and webhook workers using the OpenAI-compatible FunASR API.
FunASR OpenAI-Compatible API Server
Drop-in replacement for OpenAI's /v1/audio/transcriptions endpoint. Works with any agent framework that supports OpenAI audio API.
Quick Start
pip install funasr fastapi uvicorn python-multipart
python server.py --model sensevoice --device cuda --port 8000
Server starts in ~20s (model loading). Health check: GET /health
Need copy-paste integration snippets for Python SDK, HTTP clients, agent tools, or Dify/n8n-style workflows? See Client recipes and workflow recipes.
End-to-end smoke test
In another terminal, download a public sample and verify both health and transcription:
bash smoke_test.sh
Equivalent manual commands:
curl -L https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/BAC009S0764W0121.wav -o sample.wav
curl http://localhost:8000/health
curl http://localhost:8000/v1/audio/transcriptions \
-F file=@sample.wav \
-F model=sensevoice \
-F response_format=verbose_json
Usage with OpenAI SDK (Python)
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
# Basic transcription
result = client.audio.transcriptions.create(
model="sensevoice", # or "paraformer", "paraformer-en", "fun-asr-nano"
file=open("meeting.wav", "rb"),
)
print(result.text)
# With timestamps/segments
result = client.audio.transcriptions.create(
model="sensevoice",
file=open("meeting.wav", "rb"),
response_format="verbose_json",
)
# Returns: text, segments (with start/end/speaker), duration
Usage with curl
curl http://localhost:8000/v1/audio/transcriptions \
-F file=@audio.wav \
-F model=sensevoice
# With verbose output
curl http://localhost:8000/v1/audio/transcriptions \
-F file=@audio.wav \
-F model=sensevoice \
-F response_format=verbose_json
Available Models
| Model | Speed (GPU) | Speed (CPU) | Languages | Features |
|---|---|---|---|---|
sensevoice |
170x realtime | 17x realtime | zh/en/ja/ko/yue | Emotion detection |
paraformer |
120x realtime | 15x realtime | zh/en | Punctuation |
paraformer-en |
120x realtime | 15x realtime | en | English only |
fun-asr-nano |
17x realtime | 3.6x realtime | 31 languages | LLM-based, timestamps |
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/audio/transcriptions |
POST | Transcribe audio (OpenAI-compatible) |
/v1/models |
GET | List available models |
/health |
GET | Health check + loaded models |
/docs |
GET | Interactive API documentation (Swagger) |
Agent Framework Integration
Works with: LangChain, LlamaIndex, AutoGen, CrewAI, Semantic Kernel, Dify, n8n, or any framework using OpenAI audio API. See Client recipes for SDK and agent-tool patterns, plus workflow recipes for low-code HTTP nodes and webhook workers.
LangChain Example
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="x")
def transcribe_for_agent(audio_path: str) -> str:
"""Tool function for LangChain agent."""
result = client.audio.transcriptions.create(
model="sensevoice", file=open(audio_path, "rb")
)
return result.text
Docker Deployment
Build the example image from this directory. The default image starts in CPU mode so it can be used as a portable smoke test.
cd examples/openai_api
cp .env.example .env
docker compose up --build
Equivalent one-off docker run command:
docker build -t funasr-api .
docker run --rm -p 8000:8000 \
-e FUNASR_DEVICE=cpu \
-e FUNASR_MODEL=sensevoice \
funasr-api
For GPU hosts, use NVIDIA Container Toolkit and a CUDA-capable PyTorch/FunASR image. After adapting the image dependencies for CUDA, run the same server with FUNASR_DEVICE=cuda:
docker run --rm --gpus all -p 8000:8000 \
-e FUNASR_DEVICE=cuda \
-e FUNASR_MODEL=sensevoice \
funasr-api
Verify the container from another terminal:
BASE_URL=http://localhost:8000 bash smoke_test.sh
Configuration
| Arg | Default | Description |
|---|---|---|
--host |
0.0.0.0 | Bind address |
--port |
8000 | Port |
--device |
cuda | Device (cuda/cpu/mps) |
--model |
sensevoice | Pre-load model at startup |
Docker environment variables:
| Env | Default | Description |
|---|---|---|
FUNASR_PORT |
8000 | Container port passed to server.py |
FUNASR_DEVICE |
cpu | Container device mode; set to cuda only when the image has CUDA-capable dependencies |
FUNASR_MODEL |
sensevoice | Model alias loaded at container startup |
Troubleshooting
- If CUDA is unavailable, use
--device cpufor a slower but simple smoke test. - If port 8000 is occupied, start with
--port 9000and runBASE_URL=http://localhost:9000 bash smoke_test.sh. - If model download is slow, retry with a stable network or pre-download the model from ModelScope/Hugging Face.