# netease-youdao/confucius4-r2t2 architecture

> Architecture diagram of the GitHub repository netease-youdao/confucius4-r2t2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/netease-youdao/confucius4-r2t2
- Repository: https://github.com/netease-youdao/confucius4-r2t2

## Overview

Confucius4-R2T2 is a multilingual ASR inference package centered on append-only streaming transcription, with offline recognition and vLLM/Transformers plus optional llama.cpp decoding. The main path accepts audio, runs chunked inference, and emits stable transcript increments; a WebSocket server exposes streaming inference to clients. The llama package adds native and hybrid backends. Several modules are only partially excerpted, so links for documented capabilities rely on the README and uncertain internal details are omitted.

Main entry points: [`r2t2_llama/model.py`](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/model.py) (llama ASR Adapter), [`r2t2/r2t2_asr.py`](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py) (R2T2 ASR), [`ws_server.py`](https://github.com/netease-youdao/confucius4-r2t2/blob/master/ws_server.py) (WebSocket Server), [`r2t2_llama/llama_native_backend.py`](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/llama_native_backend.py) (Native Backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Inference API"]
  node_demo["Inference Examples<br/>[example.py]"]
  node_asr["R2T2 ASR<br/>[r2t2_asr.py]"]
  node_stream["Stable Streaming<br/>[r2t2_asr.py]"]
  node_offline["Offline Recognition<br/>[r2t2_asr.py]"]
  node_vllm["vLLM / HF Backend<br/>[r2t2_asr.py]"]
end

subgraph group_serve["Streaming Service"]
  node_wsserver["WebSocket Server<br/>[ws_server.py]"]
  node_wsclient["WebSocket Client<br/>[ws_client.py]"]
end

subgraph group_llama["llama.cpp Backends"]
  node_llama_model["llama ASR Adapter<br/>[model.py]"]
  node_native["Native Backend"]
  node_hybrid["Hybrid Backend"]
  node_native_ext["Native Extension<br/>[native_ext.cpp]"]
  node_llama_demo["llama Example<br/>[example_llama.py]"]
end

subgraph group_runtime["Runtime Support"]
  node_diagnostics["Debug Helpers<br/>[debug.py]"]
end

node_user(("Audio User"))
node_llama_server["llama-server"]
node_transcript["Transcript Output"]

node_user -->|"provides audio"| node_demo
node_demo -->|"runs inference"| node_asr
node_asr -->|"supports chunks"| node_stream
node_asr -->|"supports offline"| node_offline
node_stream -.->|"uses backend"| node_vllm
node_stream -->|"emits stable text"| node_transcript
node_offline -->|"returns text"| node_transcript
node_user -->|"sends audio"| node_wsclient
node_wsclient -->|"streams frames"| node_wsserver
node_wsserver -->|"runs ASR"| node_asr
node_wsserver -->|"sends results"| node_transcript
node_llama_demo -->|"selects backend"| node_llama_model
node_llama_model -->|"constructs backend"| node_native
node_llama_model -->|"constructs backend"| node_hybrid
node_native -->|"calls extension"| node_native_ext
node_hybrid -->|"calls extension"| node_native_ext
node_hybrid -->|"encodes audio"| node_vllm
node_native -->|"requests inference"| node_llama_server
node_llama_model -->|"uses diagnostics"| node_diagnostics

click node_demo "https://github.com/netease-youdao/confucius4-r2t2/blob/master/example.py"
click node_asr "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py"
click node_stream "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py"
click node_offline "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py"
click node_wsserver "https://github.com/netease-youdao/confucius4-r2t2/blob/master/ws_server.py"
click node_wsclient "https://github.com/netease-youdao/confucius4-r2t2/blob/master/ws_client.py"
click node_vllm "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py"
click node_llama_model "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/model.py"
click node_native "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/llama_native_backend.py"
click node_hybrid "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/llama_hybrid_backend.py"
click node_native_ext "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/native_ext.cpp"
click node_llama_demo "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/example_llama.py"
click node_diagnostics "https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/debug.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_demo,node_asr,node_stream,node_offline,node_vllm,node_user toneBlue
class node_wsserver,node_wsclient toneAmber
class node_llama_model,node_native,node_hybrid,node_native_ext,node_llama_demo,node_llama_server toneMint
class node_diagnostics toneRose
class node_transcript toneIndigo
```

## Components

### Inference API

- [Inference Examples](https://github.com/netease-youdao/confucius4-r2t2/blob/master/example.py): `example.py`
- [R2T2 ASR](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py): `r2t2/r2t2_asr.py`
- [Stable Streaming](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py): `r2t2/r2t2_asr.py`
- [Offline Recognition](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py): `r2t2/r2t2_asr.py`
- [vLLM / HF Backend](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2/r2t2_asr.py): `r2t2/r2t2_asr.py`

### Streaming Service

- [WebSocket Server](https://github.com/netease-youdao/confucius4-r2t2/blob/master/ws_server.py): `ws_server.py`
- [WebSocket Client](https://github.com/netease-youdao/confucius4-r2t2/blob/master/ws_client.py): `ws_client.py`

### llama.cpp Backends

- [llama ASR Adapter](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/model.py): `r2t2_llama/model.py`
- [Native Backend](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/llama_native_backend.py): `r2t2_llama/llama_native_backend.py`
- [Hybrid Backend](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/llama_hybrid_backend.py): `r2t2_llama/llama_hybrid_backend.py`
- [Native Extension](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/native_ext.cpp): `r2t2_llama/native_ext.cpp`
- [llama Example](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/example_llama.py): `r2t2_llama/example_llama.py`

### Runtime Support

- [Debug Helpers](https://github.com/netease-youdao/confucius4-r2t2/blob/master/r2t2_llama/debug.py): `r2t2_llama/debug.py`

### Other components

- **Audio User**
- **llama-server**
- **Transcript Output**

## Connections

- Audio User → Inference Examples: provides audio (evidence: `example.py`)
- Inference Examples → R2T2 ASR: runs inference (evidence: `example.py`)
- R2T2 ASR → Stable Streaming: supports chunks (evidence: `README.md`)
- R2T2 ASR → Offline Recognition: supports offline (evidence: `README.md`)
- Stable Streaming → vLLM / HF Backend: uses backend (evidence: `r2t2/r2t2_asr.py`)
- Stable Streaming → Transcript Output: emits stable text (evidence: `README.md`)
- Offline Recognition → Transcript Output: returns text (evidence: `README.md`)
- Audio User → WebSocket Client: sends audio (evidence: `ws_client.py`)
- WebSocket Client → WebSocket Server: streams frames (evidence: `ws_client.py`)
- WebSocket Server → R2T2 ASR: runs ASR (evidence: `ws_server.py`)
- WebSocket Server → Transcript Output: sends results (evidence: `ws_server.py`)
- llama Example → llama ASR Adapter: selects backend (evidence: `r2t2_llama/example_llama.py`)
- llama ASR Adapter → Native Backend: constructs backend (evidence: `r2t2_llama/model.py`)
- llama ASR Adapter → Hybrid Backend: constructs backend (evidence: `r2t2_llama/model.py`)
- Native Backend → Native Extension: calls extension (evidence: `r2t2_llama/llama_native_backend.py`)
- Hybrid Backend → Native Extension: calls extension (evidence: `r2t2_llama/llama_hybrid_backend.py`)
- Hybrid Backend → vLLM / HF Backend: encodes audio (evidence: `r2t2_llama/llama_hybrid_backend.py`)
- Native Backend → llama-server: requests inference (evidence: `r2t2_llama/llama_native_backend.py`)
- llama ASR Adapter → Debug Helpers: uses diagnostics (evidence: `r2t2_llama/model.py`)
