# soul-ailab/soulx-duplug architecture

> Architecture diagram of the GitHub repository soul-ailab/soulx-duplug, 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/soul-ailab/soulx-duplug
- Repository: https://github.com/soul-ailab/soulx-duplug

## Overview

SoulX-Duplug is a streaming semantic turn-state prediction service for full-duplex speech. A client streams audio chunks over WebSocket; the server manages per-session state and invokes the turn-taking engine, which processes audio through the turn model and returns states such as blank, idle, nonidle, and speak. The model also performs ASR and text normalization. The README documents these behaviors; some internal wiring is supported only by the SOURCE INDEX, so unsampled details are not expanded.

Main entry points: [`service/model.py`](https://github.com/soul-ailab/soulx-duplug/blob/main/service/model.py) (Turn model), [`server.py`](https://github.com/soul-ailab/soulx-duplug/blob/main/server.py) (WebSocket server), [`model/glm_4_voice/speech_tokenizer/modeling_whisper.py`](https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/modeling_whisper.py) (Whisper VQ model), [`service/session.py`](https://github.com/soul-ailab/soulx-duplug/blob/main/service/session.py) (Turn session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Streaming service"]
  node_server["WebSocket server<br/>[server.py]"]
  node_session["Turn session<br/>[session.py]"]
  node_engine["Turn engine<br/>[engine.py]"]
end

subgraph group_inference["Turn inference"]
  node_turnmodel["Turn model<br/>[model.py]"]
  node_config["Inference config<br/>[config.py]"]
  node_stateprediction["State prediction<br/>[model.py]"]
end

subgraph group_speech["Speech processing"]
  node_asr["Speech recognition<br/>[asr.py]"]
  node_whispermodel["Whisper VQ model"]
  node_whisperconfig["Whisper VQ config"]
  node_whispergeneration["Whisper generation"]
end

subgraph group_text["Text utilities"]
  node_textnorm["Text normalization<br/>[textnorm.py]"]
  node_chinesetn["Chinese normalization<br/>[cn_tn.py]"]
  node_textutils["Text utilities<br/>[text_utils.py]"]
  node_backchannel["Backchannel utilities"]
end

node_client(("Audio client"))

node_client -->|"streams audio"| node_server
node_server -->|"creates session"| node_session
node_server -->|"feeds audio"| node_session
node_server -->|"returns state"| node_client
node_server -->|"creates engine"| node_engine
node_session -->|"processes audio"| node_engine
node_engine -->|"runs inference"| node_turnmodel
node_turnmodel -->|"loads settings"| node_config
node_turnmodel -->|"uses prediction model"| node_stateprediction
node_turnmodel -->|"uses ASR"| node_asr
node_turnmodel -->|"uses audio tokenizer"| node_whispermodel
node_whispermodel -->|"uses config"| node_whisperconfig
node_whispermodel -->|"uses generation"| node_whispergeneration
node_turnmodel -->|"normalizes text"| node_textnorm
node_textnorm -->|"uses Chinese normalizer"| node_chinesetn
node_turnmodel -->|"uses text helpers"| node_textutils
node_turnmodel -->|"uses backchannel helpers"| node_backchannel

click node_server "https://github.com/soul-ailab/soulx-duplug/blob/main/server.py"
click node_session "https://github.com/soul-ailab/soulx-duplug/blob/main/service/session.py"
click node_engine "https://github.com/soul-ailab/soulx-duplug/blob/main/service/engine.py"
click node_turnmodel "https://github.com/soul-ailab/soulx-duplug/blob/main/service/model.py"
click node_config "https://github.com/soul-ailab/soulx-duplug/blob/main/config/config.py"
click node_stateprediction "https://github.com/soul-ailab/soulx-duplug/blob/main/model/model.py"
click node_asr "https://github.com/soul-ailab/soulx-duplug/blob/main/model/asr.py"
click node_whispermodel "https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/modeling_whisper.py"
click node_whisperconfig "https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/configuration_whisper.py"
click node_whispergeneration "https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/generation_whisper.py"
click node_textnorm "https://github.com/soul-ailab/soulx-duplug/blob/main/utils/MyTn/textnorm.py"
click node_chinesetn "https://github.com/soul-ailab/soulx-duplug/blob/main/utils/MyTn/cn_tn.py"
click node_textutils "https://github.com/soul-ailab/soulx-duplug/blob/main/utils/text_utils.py"
click node_backchannel "https://github.com/soul-ailab/soulx-duplug/blob/main/utils/backchannel_utils.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_server,node_session,node_engine,node_client toneBlue
class node_turnmodel,node_config,node_stateprediction toneAmber
class node_asr,node_whispermodel,node_whisperconfig,node_whispergeneration toneMint
class node_textnorm,node_chinesetn,node_textutils,node_backchannel toneRose
```

## Components

### Streaming service

- [WebSocket server](https://github.com/soul-ailab/soulx-duplug/blob/main/server.py): `server.py`
- [Turn session](https://github.com/soul-ailab/soulx-duplug/blob/main/service/session.py): `service/session.py`
- [Turn engine](https://github.com/soul-ailab/soulx-duplug/blob/main/service/engine.py): `service/engine.py`

### Turn inference

- [Turn model](https://github.com/soul-ailab/soulx-duplug/blob/main/service/model.py): `service/model.py`
- [Inference config](https://github.com/soul-ailab/soulx-duplug/blob/main/config/config.py): `config/config.py`
- [State prediction](https://github.com/soul-ailab/soulx-duplug/blob/main/model/model.py): `model/model.py`

### Speech processing

- [Speech recognition](https://github.com/soul-ailab/soulx-duplug/blob/main/model/asr.py): `model/asr.py`
- [Whisper VQ model](https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/modeling_whisper.py): `model/glm_4_voice/speech_tokenizer/modeling_whisper.py`
- [Whisper VQ config](https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/configuration_whisper.py): `model/glm_4_voice/speech_tokenizer/configuration_whisper.py`
- [Whisper generation](https://github.com/soul-ailab/soulx-duplug/blob/main/model/glm_4_voice/speech_tokenizer/generation_whisper.py): `model/glm_4_voice/speech_tokenizer/generation_whisper.py`

### Text utilities

- [Text normalization](https://github.com/soul-ailab/soulx-duplug/blob/main/utils/MyTn/textnorm.py): `utils/MyTn/textnorm.py`
- [Chinese normalization](https://github.com/soul-ailab/soulx-duplug/blob/main/utils/MyTn/cn_tn.py): `utils/MyTn/cn_tn.py`
- [Text utilities](https://github.com/soul-ailab/soulx-duplug/blob/main/utils/text_utils.py): `utils/text_utils.py`
- [Backchannel utilities](https://github.com/soul-ailab/soulx-duplug/blob/main/utils/backchannel_utils.py): `utils/backchannel_utils.py`

### Other components

- **Audio client**

## Connections

- Audio client → WebSocket server: streams audio (evidence: `README.md`)
- WebSocket server → Turn session: creates session (evidence: `server.py`)
- WebSocket server → Turn session: feeds audio (evidence: `server.py`)
- WebSocket server → Audio client: returns state (evidence: `README.md`)
- WebSocket server → Turn engine: creates engine (evidence: `server.py`)
- Turn session → Turn engine: processes audio (evidence: `service/session.py`)
- Turn engine → Turn model: runs inference (evidence: `service/engine.py`)
- Turn model → Inference config: loads settings (evidence: `service/model.py`)
- Turn model → State prediction: uses prediction model (evidence: `service/model.py`)
- Turn model → Speech recognition: uses ASR (evidence: `service/model.py`)
- Turn model → Whisper VQ model: uses audio tokenizer
- Whisper VQ model → Whisper VQ config: uses config (evidence: `model/glm_4_voice/speech_tokenizer/modeling_whisper.py`)
- Whisper VQ model → Whisper generation: uses generation (evidence: `model/glm_4_voice/speech_tokenizer/modeling_whisper.py`)
- Turn model → Text normalization: normalizes text (evidence: `service/model.py`)
- Text normalization → Chinese normalization: uses Chinese normalizer (evidence: `utils/MyTn/textnorm.py`)
- Turn model → Text utilities: uses text helpers (evidence: `service/model.py`)
- Turn model → Backchannel utilities: uses backchannel helpers (evidence: `service/model.py`)
