# andresayac/edge-tts architecture

> Architecture diagram of the GitHub repository andresayac/edge-tts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andresayac/edge-tts
- Repository: https://github.com/andresayac/edge-tts

## Overview

##### Main Components
a. CLI Layer
- **Entry Point** (`src/index.ts`)
- **Command Modules** (`src/commands/SynthesizeCommand.ts`, `src/commands/VoiceListCommand.ts`)
- **CLI Adapters** (`src/cli/edge-tts.ts`)
b. Core Service Layer
- **EdgeTTS Service** (`src/services/EdgeTTS.ts`)
c. Configuration & Constants
- **Config** (`src/config/constants.ts`)
d. Build & Packaging
- **Build Script** (`scripts/build.ts`)
- **Package Metadata** (`package.json`, `bun.lockb`, `.npmignore`)
e. External Dependencies
- **Microsoft Edge TTS Endpoint** (cloud API or local Edge process)
- **Node/Bun Runtime**

##### Relationships & Data Flow
- CLI Entry → Dispatch to Command Modules
- Commands → Invoke EdgeTTS Service API
- EdgeTTS Service → HTTP/WebSocket call to Microsoft Edge TTS → Returns audio stream
- Service → Applies export methods (`toBase64()`, `toFile()`, `toRaw()`) → Returns to CLI
- CLI → Writes output to filesystem or stdout

##### Architectural Patterns & Principles
- **Separation of Concerns**:
- CLI parsing (src/cli)
- Command definitions (src/commands)
- Core business logic (src/services)
- **Modularity & Extensibility**: Each command is a plugin-like class extending a common interface
- **Single Responsibility**: Export functions (toFile/… ) isolated in service layer
- **Build Pipeline**: TypeScript → Bun bundler → npm package

##### Putting It All Together
CLI entrypoint → Command Handler → EdgeTTS Service → Microsoft Edge TTS → back to Service → Export Module → CLI output

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        Entry["src/index.ts (Entry Point)"]:::cli
        Adapter["edge-tts.ts (CLI Adapter)"]:::cli
        Synthesize["SynthesizeCommand"]:::cli
        VoiceList["VoiceListCommand"]:::cli
    end

    %% Core Service Layer
    subgraph "Core Service Layer"
        direction TB
        EdgeService["EdgeTTS Service"]:::service
        Config["constants.ts (Config)"]:::config
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        MSAPI["Microsoft Edge TTS API"]:::external
        Runtime["Node/Bun Runtime"]:::external
    end

    %% Build & Packaging
    subgraph "Build & Packaging"
        direction TB
        BuildScript["build.ts (Build Script)"]:::build
        PackJSON["package.json"]:::build
        BunLock["bun.lockb"]:::build
        NpmIgnore[".npmignore"]:::build
    end

    %% Data Flows
    Entry -->|"dispatch command"| Synthesize
    Entry -->|"dispatch command"| VoiceList
    Synthesize -->|"calls CLI Adapter"| Adapter
    VoiceList -->|"calls CLI Adapter"| Adapter
    Adapter -->|"invoke service API"| EdgeService
    EdgeService -->|"HTTP/WebSocket"| MSAPI
    MSAPI -->|"audio stream"| EdgeService
    EdgeService -->|"Audio buffer / export data"| Synthesize
    EdgeService -->|"Audio buffer / export data"| VoiceList
    EdgeService -->|uses| Config
    Synthesize -->|"writes to stdout/file"| Entry
    VoiceList -->|"writes to stdout/file"| Entry

    %% Build Flows
    Entry -->|"source"| BuildScript
    EdgeService -->|"source"| BuildScript
    BuildScript -->|bundles| PackJSON
    BuildScript -->|bundles| BunLock
    BuildScript -->|bundles| NpmIgnore

    %% Click Events
    click Entry "https://github.com/andresayac/edge-tts/blob/main/src/index.ts"
    click Synthesize "https://github.com/andresayac/edge-tts/blob/main/src/commands/SynthesizeCommand.ts"
    click VoiceList "https://github.com/andresayac/edge-tts/blob/main/src/commands/VoiceListCommand.ts"
    click Adapter "https://github.com/andresayac/edge-tts/blob/main/src/cli/edge-tts.ts"
    click EdgeService "https://github.com/andresayac/edge-tts/blob/main/src/services/EdgeTTS.ts"
    click Config "https://github.com/andresayac/edge-tts/blob/main/src/config/constants.ts"
    click BuildScript "https://github.com/andresayac/edge-tts/blob/main/scripts/build.ts"
    click PackJSON "https://github.com/andresayac/edge-tts/blob/main/package.json"
    click BunLock "https://github.com/andresayac/edge-tts/blob/main/bun.lockb"
    click NpmIgnore "https://github.com/andresayac/edge-tts/blob/main/.npmignore"

    %% Styles
    classDef cli fill:#AED6F1,stroke:#1B4F72,stroke-width:1px;
    classDef service fill:#ABEBC6,stroke:#1D8348,stroke-width:1px;
    classDef external fill:#F5B041,stroke:#B9770E,stroke-width:1px;
    classDef config fill:#D5DBDB,stroke:#5D6D7E,stroke-width:1px;
    classDef build fill:#D5DBDB,stroke:#5D6D7E,stroke-width:1px;
```
