# saheedniyi02/yarngpt architecture

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

- Interactive diagram: https://gitdiagram.com/saheedniyi02/yarngpt
- Repository: https://github.com/saheedniyi02/yarngpt

## Overview

YarnGPT is a neural text-to-speech system for Nigerian-accented speech, with a Python wrapper and a lower-level tokenizer implementation. Its principal workflow accepts text and a speaker choice, builds and tokenizes a speech prompt, generates model output, extracts audio codes, and decodes them to a waveform. The tokenizer also contains local-language prompt support and audio-to-text utilities. The graph follows the sampled wrapper and tokenizer code; additional capabilities are included where documented or visible, while unsampled internals and uncertain links are omitted.

Main entry points: [`python-wrapper/yarngpt/core.py`](https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py) (Speech API), [`audiotokenizer.py`](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py) (Prompt Builder), [`default_speakers`](https://github.com/saheedniyi02/yarngpt/tree/main/default_speakers) (Preset Voices)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Python API"]
  node_speech_api["Speech API<br/>[core.py]"]
  node_model_loader["Model Loader<br/>[core.py]"]
  node_speaker_validation["Speaker Selection<br/>[core.py]"]
end

subgraph group_synthesis["Speech Synthesis"]
  node_text_prompt["Prompt Builder<br/>[audiotokenizer.py]"]
  node_text_tokenization["Prompt Tokenizer<br/>[audiotokenizer.py]"]
  node_language_model["YarnGPT Model"]
  node_speaker_profiles["Preset Voices"]
end

subgraph group_audio["Audio Processing"]
  node_code_extraction["Audio Code Extraction<br/>[audiotokenizer.py]"]
  node_audio_decoder["Waveform Decoder<br/>[audiotokenizer.py]"]
  node_wav_tokenizer["WavTokenizer"]
  node_waveform["Speech Waveform"]
end

subgraph group_language["Language Tools"]
  node_local_speech["Local-Language Prompts<br/>[audiotokenizer.py]"]
  node_audio_input["Audio Input"]
  node_audio_quantization["Audio Quantization<br/>[audiotokenizer.py]"]
  node_asr_prompt["ASR Prompt Builder<br/>[audiotokenizer.py]"]
  node_asr_result["ASR Text Extraction<br/>[audiotokenizer.py]"]
end

node_user(("Application User"))

node_user -->|"requests speech"| node_speech_api
node_speech_api -->|"validates voice"| node_speaker_validation
node_speech_api -->|"loads components"| node_model_loader
node_speech_api -->|"builds prompt"| node_text_prompt
node_speech_api -->|"tokenizes prompt"| node_text_tokenization
node_speech_api -->|"generates tokens"| node_language_model
node_speech_api -->|"extracts codes"| node_code_extraction
node_speech_api -->|"decodes codes"| node_audio_decoder
node_audio_decoder -->|"decodes features"| node_wav_tokenizer
node_audio_decoder -->|"returns audio"| node_waveform
node_text_prompt -->|"loads voice data"| node_speaker_profiles
node_user -->|"provides audio"| node_audio_input
node_audio_input -->|"quantizes audio"| node_audio_quantization
node_audio_quantization -->|"encodes audio"| node_wav_tokenizer
node_audio_quantization -->|"supplies codes"| node_asr_prompt
node_asr_prompt -.->|"can be generated"| node_language_model
node_language_model -.->|"provides model output"| node_asr_result
node_text_prompt -->|"supports language variants"| node_local_speech

click node_speech_api "https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py"
click node_model_loader "https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py"
click node_speaker_validation "https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py"
click node_text_prompt "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_text_tokenization "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_code_extraction "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_audio_decoder "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_speaker_profiles "https://github.com/saheedniyi02/yarngpt/tree/main/default_speakers"
click node_local_speech "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_audio_quantization "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_asr_prompt "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py"
click node_asr_result "https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.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_speech_api,node_model_loader,node_speaker_validation,node_user toneBlue
class node_text_prompt,node_text_tokenization,node_language_model,node_speaker_profiles toneAmber
class node_code_extraction,node_audio_decoder,node_wav_tokenizer,node_waveform toneMint
class node_local_speech,node_audio_input,node_audio_quantization,node_asr_prompt,node_asr_result toneRose
```

## Components

### Python API

- [Speech API](https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py): `python-wrapper/yarngpt/core.py`
- [Model Loader](https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py): `python-wrapper/yarngpt/core.py`
- [Speaker Selection](https://github.com/saheedniyi02/yarngpt/blob/main/python-wrapper/yarngpt/core.py): `python-wrapper/yarngpt/core.py`

### Speech Synthesis

- [Prompt Builder](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- [Prompt Tokenizer](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- **YarnGPT Model**
- [Preset Voices](https://github.com/saheedniyi02/yarngpt/tree/main/default_speakers): `default_speakers`

### Audio Processing

- [Audio Code Extraction](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- [Waveform Decoder](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- **WavTokenizer**
- **Speech Waveform**

### Language Tools

- [Local-Language Prompts](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- **Audio Input**
- [Audio Quantization](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- [ASR Prompt Builder](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`
- [ASR Text Extraction](https://github.com/saheedniyi02/yarngpt/blob/main/audiotokenizer.py): `audiotokenizer.py`

### Other components

- **Application User**

## Connections

- Application User → Speech API: requests speech (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Speaker Selection: validates voice (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Model Loader: loads components (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Prompt Builder: builds prompt (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Prompt Tokenizer: tokenizes prompt (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → YarnGPT Model: generates tokens (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Audio Code Extraction: extracts codes (evidence: `python-wrapper/yarngpt/core.py`)
- Speech API → Waveform Decoder: decodes codes (evidence: `python-wrapper/yarngpt/core.py`)
- Waveform Decoder → WavTokenizer: decodes features (evidence: `audiotokenizer.py`)
- Waveform Decoder → Speech Waveform: returns audio (evidence: `audiotokenizer.py`)
- Prompt Builder → Preset Voices: loads voice data (evidence: `README.md`)
- Application User → Audio Input: provides audio
- Audio Input → Audio Quantization: quantizes audio (evidence: `audiotokenizer.py`)
- Audio Quantization → WavTokenizer: encodes audio (evidence: `audiotokenizer.py`)
- Audio Quantization → ASR Prompt Builder: supplies codes (evidence: `audiotokenizer.py`)
- ASR Prompt Builder → YarnGPT Model: can be generated
- YarnGPT Model → ASR Text Extraction: provides model output
- Prompt Builder → Local-Language Prompts: supports language variants (evidence: `audiotokenizer.py`)
