# moonshine-ai/moonshine architecture

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

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

## Overview

Moonshine Voice is an on-device toolkit for real-time voice applications. Its principal workflow accepts live or recorded audio, transcribes it, and exposes transcript events; applications can also synthesize speech, identify speakers, and match spoken phrases by meaning. The graph includes the C/C++ runtime, speech and language-processing capabilities, and available platform entry points. README establishes the major product capabilities; sampled source confirms selected runtime implementations and the WASM worker flow, but not the wiring of every platform or subsystem.

Main entry points: [`core/moonshine-cpp.h`](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-cpp.h) (C++ API), [`core/moonshine-streaming-model.cpp`](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-streaming-model.cpp) (Streaming Runtime), [`core/moonshine-c-api.cpp`](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-c-api.cpp) (C API), [`language-bindings/python/src/moonshine_voice/embedding_model.py`](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/python/src/moonshine_voice/embedding_model.py) (Python Embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_speech["Speech Recognition"]
  node_model_runtime["Model Runtime"]
  node_streaming_runtime["Streaming Runtime"]
  node_transcriber["Transcription<br/>[transcriber.cpp]"]
end

subgraph group_speech_processing["Speech Processing"]
  node_audio_prep["Audio Preparation<br/>[resampler.cpp]"]
  node_speech_clip["Speech Clips<br/>[speech-clip.cpp]"]
  node_vad["Voice Detection<br/>[silero-vad.cpp]"]
  node_diarization["Speaker Diarization"]
  node_annote_engine["Diarization Engine"]
end

subgraph group_language["Language Features"]
  node_tts["Text-to-Speech<br/>[moonshine-tts.cpp]"]
  node_g2p["Grapheme-to-Phoneme<br/>[moonshine-g2p.cpp]"]
  node_embedding_api["Embedding API<br/>[text-embedder.cpp]"]
  node_gemma["Gemma Embeddings"]
  node_cached_embeddings["Embedding Cache"]
end

subgraph group_interfaces["Runtime Interfaces"]
  node_c_api["C API"]
  node_cpp_api["C++ API<br/>[moonshine-cpp.h]"]
  node_model_catalog["Model Catalog"]
  node_wasm_host["WASM Worker Host<br/>[stt-worker-host.ts]"]
  node_wasm_worker["WASM Worker<br/>[stt-worker.ts]"]
  node_python_embedding["Python Embeddings<br/>[embedding_model.py]"]
  node_swift_embedding["Swift Embeddings"]
  node_android_download["Android Downloads"]
end

node_developer(("Application Developer"))

node_developer -->|"uses library"| node_cpp_api
node_developer -->|"uses library"| node_c_api
node_developer -->|"selects models"| node_model_catalog
node_cpp_api -->|"runs models"| node_model_runtime
node_cpp_api -->|"streams audio"| node_streaming_runtime
node_wasm_host -->|"dispatches requests"| node_wasm_worker
node_wasm_worker -->|"transcribes streams"| node_transcriber
node_transcriber -->|"processes audio"| node_streaming_runtime
node_streaming_runtime -->|"runs inference"| node_model_runtime
node_developer -->|"provides audio"| node_audio_prep
node_audio_prep -->|"prepares clips"| node_speech_clip
node_developer -->|"detects speech"| node_vad
node_developer -->|"requests speakers"| node_diarization
node_diarization -->|"analyzes speakers"| node_annote_engine
node_developer -->|"requests synthesis"| node_tts
node_tts -->|"converts text"| node_g2p
node_developer -->|"requests embeddings"| node_embedding_api
node_embedding_api -->|"embeds text"| node_gemma
node_python_embedding -->|"calls native API"| node_c_api
node_python_embedding -->|"uses cache"| node_cached_embeddings
node_swift_embedding -->|"calls native API"| node_c_api
node_android_download -.->|"prepares model assets"| node_model_catalog

click node_c_api "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-c-api.cpp"
click node_cpp_api "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-cpp.h"
click node_model_catalog "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-model-catalog.cpp"
click node_model_runtime "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-model.cpp"
click node_streaming_runtime "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-streaming-model.cpp"
click node_transcriber "https://github.com/moonshine-ai/moonshine/blob/main/core/transcriber.cpp"
click node_wasm_host "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/wasm/src/stt-worker-host.ts"
click node_wasm_worker "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/wasm/src/stt-worker.ts"
click node_audio_prep "https://github.com/moonshine-ai/moonshine/blob/main/core/resampler.cpp"
click node_speech_clip "https://github.com/moonshine-ai/moonshine/blob/main/core/speech-clip.cpp"
click node_vad "https://github.com/moonshine-ai/moonshine/blob/main/core/silero-vad.cpp"
click node_diarization "https://github.com/moonshine-ai/moonshine/blob/main/core/speaker-diarizer.cpp"
click node_annote_engine "https://github.com/moonshine-ai/moonshine/blob/main/core/cpp-annote/src/cpp-annote-engine.h"
click node_tts "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-tts/src/moonshine-tts.cpp"
click node_g2p "https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-tts/src/moonshine-g2p.cpp"
click node_embedding_api "https://github.com/moonshine-ai/moonshine/blob/main/core/text-embedder.cpp"
click node_gemma "https://github.com/moonshine-ai/moonshine/blob/main/core/gemma-embedding-model.cpp"
click node_python_embedding "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/python/src/moonshine_voice/embedding_model.py"
click node_cached_embeddings "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/python/src/moonshine_voice/cached_embeddings.py"
click node_swift_embedding "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/swift/Sources/MoonshineVoice/EmbeddingModel.swift"
click node_android_download "https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/android/java/main/java/ai/moonshine/voice/MoonshineDownloadWorker.java"

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_model_runtime,node_streaming_runtime,node_transcriber toneBlue
class node_audio_prep,node_speech_clip,node_vad,node_diarization,node_annote_engine toneAmber
class node_tts,node_g2p,node_embedding_api,node_gemma,node_cached_embeddings toneMint
class node_c_api,node_cpp_api,node_model_catalog,node_wasm_host,node_wasm_worker,node_python_embedding,node_swift_embedding,node_android_download toneRose
class node_developer toneIndigo
```

## Components

### Speech Recognition

- [Model Runtime](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-model.cpp): `core/moonshine-model.cpp`
- [Streaming Runtime](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-streaming-model.cpp): `core/moonshine-streaming-model.cpp`
- [Transcription](https://github.com/moonshine-ai/moonshine/blob/main/core/transcriber.cpp): `core/transcriber.cpp`

### Speech Processing

- [Audio Preparation](https://github.com/moonshine-ai/moonshine/blob/main/core/resampler.cpp): `core/resampler.cpp`
- [Speech Clips](https://github.com/moonshine-ai/moonshine/blob/main/core/speech-clip.cpp): `core/speech-clip.cpp`
- [Voice Detection](https://github.com/moonshine-ai/moonshine/blob/main/core/silero-vad.cpp): `core/silero-vad.cpp`
- [Speaker Diarization](https://github.com/moonshine-ai/moonshine/blob/main/core/speaker-diarizer.cpp): `core/speaker-diarizer.cpp`
- [Diarization Engine](https://github.com/moonshine-ai/moonshine/blob/main/core/cpp-annote/src/cpp-annote-engine.h): `core/cpp-annote/src/cpp-annote-engine.h`

### Language Features

- [Text-to-Speech](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-tts/src/moonshine-tts.cpp): `core/moonshine-tts/src/moonshine-tts.cpp`
- [Grapheme-to-Phoneme](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-tts/src/moonshine-g2p.cpp): `core/moonshine-tts/src/moonshine-g2p.cpp`
- [Embedding API](https://github.com/moonshine-ai/moonshine/blob/main/core/text-embedder.cpp): `core/text-embedder.cpp`
- [Gemma Embeddings](https://github.com/moonshine-ai/moonshine/blob/main/core/gemma-embedding-model.cpp): `core/gemma-embedding-model.cpp`
- [Embedding Cache](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/python/src/moonshine_voice/cached_embeddings.py): `language-bindings/python/src/moonshine_voice/cached_embeddings.py`

### Runtime Interfaces

- [C API](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-c-api.cpp): `core/moonshine-c-api.cpp`
- [C++ API](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-cpp.h): `core/moonshine-cpp.h`
- [Model Catalog](https://github.com/moonshine-ai/moonshine/blob/main/core/moonshine-model-catalog.cpp): `core/moonshine-model-catalog.cpp`
- [WASM Worker Host](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/wasm/src/stt-worker-host.ts): `language-bindings/wasm/src/stt-worker-host.ts`
- [WASM Worker](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/wasm/src/stt-worker.ts): `language-bindings/wasm/src/stt-worker.ts`
- [Python Embeddings](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/python/src/moonshine_voice/embedding_model.py): `language-bindings/python/src/moonshine_voice/embedding_model.py`
- [Swift Embeddings](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/swift/Sources/MoonshineVoice/EmbeddingModel.swift): `language-bindings/swift/Sources/MoonshineVoice/EmbeddingModel.swift`
- [Android Downloads](https://github.com/moonshine-ai/moonshine/blob/main/language-bindings/android/java/main/java/ai/moonshine/voice/MoonshineDownloadWorker.java): `language-bindings/android/java/main/java/ai/moonshine/voice/MoonshineDownloadWorker.java`

### Other components

- **Application Developer**

## Connections

- Application Developer → C++ API: uses library
- Application Developer → C API: uses library
- Application Developer → Model Catalog: selects models
- C++ API → Model Runtime: runs models
- C++ API → Streaming Runtime: streams audio
- WASM Worker Host → WASM Worker: dispatches requests
- WASM Worker → Transcription: transcribes streams
- Transcription → Streaming Runtime: processes audio
- Streaming Runtime → Model Runtime: runs inference
- Application Developer → Audio Preparation: provides audio
- Audio Preparation → Speech Clips: prepares clips
- Application Developer → Voice Detection: detects speech
- Application Developer → Speaker Diarization: requests speakers
- Speaker Diarization → Diarization Engine: analyzes speakers
- Application Developer → Text-to-Speech: requests synthesis
- Text-to-Speech → Grapheme-to-Phoneme: converts text
- Application Developer → Embedding API: requests embeddings
- Embedding API → Gemma Embeddings: embeds text
- Python Embeddings → C API: calls native API
- Python Embeddings → Embedding Cache: uses cache
- Swift Embeddings → C API: calls native API
- Android Downloads → Model Catalog: prepares model assets
