# sugarlabs/speak-ai architecture

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

- Interactive diagram: https://gitdiagram.com/sugarlabs/speak-ai
- Repository: https://github.com/sugarlabs/speak-ai

## Overview

SpeakAI is a Sugar desktop activity where users type text and see a configurable face speak it aloud. The main runtime path runs from the Sugar-launched activity through speech synthesis to audio playback; the face also renders speech-related animation. The activity additionally supports persona and face selection, chat, and AI response options. The repository includes both the Kokoro TTS implementation and AIML components. Some connections are based on SOURCE INDEX references rather than inspected call sites, so the graph omits uncertain links.

Main entry points: [`activity.py`](https://github.com/sugarlabs/speak-ai/blob/main/activity.py) (Activity UI and controls), [`face.py`](https://github.com/sugarlabs/speak-ai/blob/main/face.py) (Face renderer), [`speech.py`](https://github.com/sugarlabs/speak-ai/blob/main/speech.py) (Speech playback), [`chat.py`](https://github.com/sugarlabs/speak-ai/blob/main/chat.py) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Activity interface"]
  node_activity["Activity UI and controls<br/>[activity.py]"]
  node_chat["Chat interface<br/>[chat.py]"]
  node_chatbox["Chat display<br/>[chatbox.py]"]
  node_persona["Face and voice selection<br/>[faceselect.py]"]
  node_photo["Photo face<br/>[photoface.py]"]
end

subgraph group_conversation["Conversation and AI"]
  node_llm["Remote LLM<br/>[LLM.py]"]
  node_gguf["Local GGUF inference<br/>[gguf_inference.py]"]
  node_profanity["Profanity filtering"]
  node_brain["Conversation logic<br/>[brain.py]"]
end

subgraph group_speech["Speech synthesis"]
  node_speech["Speech playback<br/>[speech.py]"]
  node_kokoro_pipeline["Text-to-audio pipeline<br/>[pipeline.py]"]
  node_kokoro_model["Kokoro model<br/>[model.py]"]
  node_decoder["Audio decoder<br/>[istftnet.py]"]
end

subgraph group_appearance["Face and animation"]
  node_face["Face renderer<br/>[face.py]"]
  node_eyes["Eye rendering<br/>[eye.py]"]
  node_eyelashes["Eyelashes<br/>[eyelashes.py]"]
  node_mouth["Mouth animation<br/>[mouth.py]"]
  node_fft_mouth["FFT mouth animation<br/>[fft_mouth.py]"]
  node_waveform_mouth["Waveform mouth animation<br/>[waveform_mouth.py]"]
  node_glasses["Face accessories<br/>[glasses.py]"]
  node_sleepy["Sleepy expression<br/>[sleepy.py]"]
  node_wireframes["Wireframe eyes<br/>[wireframes.py]"]
end

subgraph group_aiml["AIML runtime"]
  node_aiml_kernel["AIML interpreter<br/>[Kernel.py]"]
  node_aiml_parser["AIML parser<br/>[AimlParser.py]"]
end

node_sugar(("Sugar desktop"))
node_user(("User"))
node_audio(("Audio output"))

node_sugar -->|"launches"| node_activity
node_user -->|"enters text"| node_activity
node_activity -->|"requests speech"| node_speech
node_speech -->|"generates audio"| node_kokoro_pipeline
node_kokoro_pipeline -->|"uses model"| node_kokoro_model
node_kokoro_model -->|"decodes audio"| node_decoder
node_speech -->|"plays audio"| node_audio
node_activity -->|"updates face"| node_face
node_face -->|"reads speech state"| node_speech
node_face -->|"renders eyes"| node_eyes
node_face -->|"renders lashes"| node_eyelashes
node_face -->|"renders mouth"| node_mouth
node_face -->|"renders mouth"| node_fft_mouth
node_face -->|"renders mouth"| node_waveform_mouth
node_face -->|"renders accessory"| node_glasses
node_face -->|"renders expression"| node_sleepy
node_face -->|"renders eyes"| node_wireframes
node_activity -->|"selects persona"| node_persona
node_activity -->|"selects photo face"| node_photo
node_activity -->|"opens chat"| node_chat
node_chat -->|"renders messages"| node_chatbox
node_activity -->|"requests answer"| node_llm
node_activity -->|"checks response"| node_profanity
node_activity -->|"uses inference"| node_gguf
node_activity -.->|"uses conversation logic"| node_brain
node_brain -->|"queries interpreter"| node_aiml_kernel
node_aiml_kernel -->|"parses AIML"| node_aiml_parser

click node_activity "https://github.com/sugarlabs/speak-ai/blob/main/activity.py"
click node_chat "https://github.com/sugarlabs/speak-ai/blob/main/chat.py"
click node_chatbox "https://github.com/sugarlabs/speak-ai/blob/main/chatbox.py"
click node_persona "https://github.com/sugarlabs/speak-ai/blob/main/faceselect.py"
click node_photo "https://github.com/sugarlabs/speak-ai/blob/main/photoface.py"
click node_llm "https://github.com/sugarlabs/speak-ai/blob/main/LLM.py"
click node_gguf "https://github.com/sugarlabs/speak-ai/blob/main/GenAI/gguf_inference.py"
click node_profanity "https://github.com/sugarlabs/speak-ai/blob/main/GenAI/profainity_check.py"
click node_brain "https://github.com/sugarlabs/speak-ai/blob/main/brain.py"
click node_aiml_kernel "https://github.com/sugarlabs/speak-ai/blob/main/aiml/Kernel.py"
click node_aiml_parser "https://github.com/sugarlabs/speak-ai/blob/main/aiml/AimlParser.py"
click node_speech "https://github.com/sugarlabs/speak-ai/blob/main/speech.py"
click node_kokoro_pipeline "https://github.com/sugarlabs/speak-ai/blob/main/kokoro/pipeline.py"
click node_kokoro_model "https://github.com/sugarlabs/speak-ai/blob/main/kokoro/model.py"
click node_decoder "https://github.com/sugarlabs/speak-ai/blob/main/kokoro/istftnet.py"
click node_face "https://github.com/sugarlabs/speak-ai/blob/main/face.py"
click node_eyes "https://github.com/sugarlabs/speak-ai/blob/main/eye.py"
click node_eyelashes "https://github.com/sugarlabs/speak-ai/blob/main/eyelashes.py"
click node_mouth "https://github.com/sugarlabs/speak-ai/blob/main/mouth.py"
click node_fft_mouth "https://github.com/sugarlabs/speak-ai/blob/main/fft_mouth.py"
click node_waveform_mouth "https://github.com/sugarlabs/speak-ai/blob/main/waveform_mouth.py"
click node_glasses "https://github.com/sugarlabs/speak-ai/blob/main/glasses.py"
click node_sleepy "https://github.com/sugarlabs/speak-ai/blob/main/sleepy.py"
click node_wireframes "https://github.com/sugarlabs/speak-ai/blob/main/wireframes.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_activity,node_chat,node_chatbox,node_persona,node_photo,node_user toneBlue
class node_llm,node_gguf,node_profanity,node_brain toneAmber
class node_speech,node_kokoro_pipeline,node_kokoro_model,node_decoder toneMint
class node_face,node_eyes,node_eyelashes,node_mouth,node_fft_mouth,node_waveform_mouth,node_glasses,node_sleepy,node_wireframes toneRose
class node_aiml_kernel,node_aiml_parser,node_sugar,node_audio toneIndigo
```

## Components

### Activity interface

- [Activity UI and controls](https://github.com/sugarlabs/speak-ai/blob/main/activity.py): `activity.py`
- [Chat interface](https://github.com/sugarlabs/speak-ai/blob/main/chat.py): `chat.py`
- [Chat display](https://github.com/sugarlabs/speak-ai/blob/main/chatbox.py): `chatbox.py`
- [Face and voice selection](https://github.com/sugarlabs/speak-ai/blob/main/faceselect.py): `faceselect.py`
- [Photo face](https://github.com/sugarlabs/speak-ai/blob/main/photoface.py): `photoface.py`

### Conversation and AI

- [Remote LLM](https://github.com/sugarlabs/speak-ai/blob/main/LLM.py): `LLM.py`
- [Local GGUF inference](https://github.com/sugarlabs/speak-ai/blob/main/GenAI/gguf_inference.py): `GenAI/gguf_inference.py`
- [Profanity filtering](https://github.com/sugarlabs/speak-ai/blob/main/GenAI/profainity_check.py): `GenAI/profainity_check.py`
- [Conversation logic](https://github.com/sugarlabs/speak-ai/blob/main/brain.py): `brain.py`

### Speech synthesis

- [Speech playback](https://github.com/sugarlabs/speak-ai/blob/main/speech.py): `speech.py`
- [Text-to-audio pipeline](https://github.com/sugarlabs/speak-ai/blob/main/kokoro/pipeline.py): `kokoro/pipeline.py`
- [Kokoro model](https://github.com/sugarlabs/speak-ai/blob/main/kokoro/model.py): `kokoro/model.py`
- [Audio decoder](https://github.com/sugarlabs/speak-ai/blob/main/kokoro/istftnet.py): `kokoro/istftnet.py`

### Face and animation

- [Face renderer](https://github.com/sugarlabs/speak-ai/blob/main/face.py): `face.py`
- [Eye rendering](https://github.com/sugarlabs/speak-ai/blob/main/eye.py): `eye.py`
- [Eyelashes](https://github.com/sugarlabs/speak-ai/blob/main/eyelashes.py): `eyelashes.py`
- [Mouth animation](https://github.com/sugarlabs/speak-ai/blob/main/mouth.py): `mouth.py`
- [FFT mouth animation](https://github.com/sugarlabs/speak-ai/blob/main/fft_mouth.py): `fft_mouth.py`
- [Waveform mouth animation](https://github.com/sugarlabs/speak-ai/blob/main/waveform_mouth.py): `waveform_mouth.py`
- [Face accessories](https://github.com/sugarlabs/speak-ai/blob/main/glasses.py): `glasses.py`
- [Sleepy expression](https://github.com/sugarlabs/speak-ai/blob/main/sleepy.py): `sleepy.py`
- [Wireframe eyes](https://github.com/sugarlabs/speak-ai/blob/main/wireframes.py): `wireframes.py`

### AIML runtime

- [AIML interpreter](https://github.com/sugarlabs/speak-ai/blob/main/aiml/Kernel.py): `aiml/Kernel.py`
- [AIML parser](https://github.com/sugarlabs/speak-ai/blob/main/aiml/AimlParser.py): `aiml/AimlParser.py`

### Other components

- **Sugar desktop**
- **User**
- **Audio output**

## Connections

- Sugar desktop → Activity UI and controls: launches
- User → Activity UI and controls: enters text
- Activity UI and controls → Speech playback: requests speech (evidence: `activity.py`)
- Speech playback → Text-to-audio pipeline: generates audio (evidence: `speech.py`)
- Text-to-audio pipeline → Kokoro model: uses model (evidence: `kokoro/pipeline.py`)
- Kokoro model → Audio decoder: decodes audio (evidence: `kokoro/model.py`)
- Speech playback → Audio output: plays audio (evidence: `speech.py`)
- Activity UI and controls → Face renderer: updates face (evidence: `activity.py`)
- Face renderer → Speech playback: reads speech state (evidence: `face.py`)
- Face renderer → Eye rendering: renders eyes (evidence: `face.py`)
- Face renderer → Eyelashes: renders lashes (evidence: `face.py`)
- Face renderer → Mouth animation: renders mouth (evidence: `face.py`)
- Face renderer → FFT mouth animation: renders mouth (evidence: `face.py`)
- Face renderer → Waveform mouth animation: renders mouth (evidence: `face.py`)
- Face renderer → Face accessories: renders accessory (evidence: `face.py`)
- Face renderer → Sleepy expression: renders expression (evidence: `face.py`)
- Face renderer → Wireframe eyes: renders eyes (evidence: `face.py`)
- Activity UI and controls → Face and voice selection: selects persona (evidence: `activity.py`)
- Activity UI and controls → Photo face: selects photo face (evidence: `activity.py`)
- Activity UI and controls → Chat interface: opens chat (evidence: `activity.py`)
- Chat interface → Chat display: renders messages (evidence: `chat.py`)
- Activity UI and controls → Remote LLM: requests answer (evidence: `activity.py`)
- Activity UI and controls → Profanity filtering: checks response (evidence: `activity.py`)
- Activity UI and controls → Local GGUF inference: uses inference
- Activity UI and controls → Conversation logic: uses conversation logic (evidence: `activity.py`)
- Conversation logic → AIML interpreter: queries interpreter (evidence: `brain.py`)
- AIML interpreter → AIML parser: parses AIML (evidence: `aiml/Kernel.py`)
