# ztp559/agent-test architecture

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

- Interactive diagram: https://gitdiagram.com/ztp559/agent-test
- Repository: https://github.com/ztp559/agent-test

## Overview

##### Main Components
a. Core Orchestrator
- Core.py / template.py / voice.py – entry point(s) coordinating the workflow
b. Audio I/O Layer
- voiceIO/record.py – captures microphone input
- voiceIO/play.py – plays synthesized audio
c. External API Wrappers (audioapi)
- s2t.py – sends recorded audio to STT service, parses transcripts
- smarttts.py – sends texts to TTS service, retrieves audio
- message_log.txt / send_log.txt – logging of requests/responses
d. Local Voice Clone Module (voiceclone)
- train.py – trains local voice models using getText.json
- tts.py – synthesizes speech locally from text
- .env / getText.json – configuration & training data
e. Configuration & Environment
- .env (root & submodules) – API keys, model parameters
- mcp.json – additional settings/config schema
- requirements.txt – dependency list
f. Legacy / Tests
- old/ – prior iterations of modules (reference only)
- test/ – (if populated) automated tests

##### Relationships & Data Flows
– User speaks into the microphone → voiceIO.record.py
– Recorded audio is handed to Core.py
– Core routes audio to either:
- audioapi.s2t.py → external STT → transcript
- (optionally) voiceclone.tts.py → local TTS (if using voice clone)
– Core processes the transcript, generates a response text (via template.py or business logic)
– Response text is sent to:
- audioapi.smarttts.py → external TTS → audio
- OR voiceclone.tts.py → local voice synthesis
– Synthesized audio is forwarded to voiceIO.play.py → speaker output
– All interactions log to audioapi/message_log.txt, send_log.txt

##### Architectural Patterns & Principles
– Layered Pipeline: separation between I/O, processing, and synthesis
– Adapter Pattern: audioapi and voiceclone modules abstract away external vs. local engines
– Config-driven: .env files and mcp.json centralize credentials and parameters
– Modular Design: easy to swap external TTS/STT for local voice clone

[ ] All major modules (voiceIO, audioapi, voiceclone, Core) represented
[ ] External cloud services depicted distinctly from local modules
[ ] Configuration stores (.env, mcp.json) drawn as data stores

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Audio I/O Layer"
        rec["record.py"]:::io
        play["play.py"]:::io
    end

    subgraph "Core Orchestrator"
        core["Core.py / template.py / voice.py"]:::orchestrator
    end

    subgraph "External API Adapters"
        s2t["s2t.py"]:::adapter
        smarttts["smarttts.py"]:::adapter
        log1["message_log.txt"]:::storage
        log2["send_log.txt"]:::storage
    end

    CloudSTT[(Cloud STT)]:::external
    CloudTTS[(Cloud TTS)]:::external

    subgraph "Local Voice Clone Module"
        train["train.py"]:::local
        ltts["tts.py"]:::local
        txt["getText.json"]:::storage
    end

    subgraph "Configuration & Environment"
        env_root[".env"]:::config
        env_api["audioapi/.env"]:::config
        env_clone["voiceclone/.env"]:::config
        mcp["mcp.json"]:::config
        req["requirements.txt"]:::config
    end

    subgraph "Legacy and Tests"
        old["old/"]:::legacy
        tests["test/"]:::legacy
    end

    rec -->|"audio chunk"| core
    core -->|"JSON request(.wav)"| s2t
    s2t -->|"transcript"| core
    s2t -->|"logs"| log1
    core -->|"response text"| smarttts
    smarttts -->|"synth request"| CloudTTS
    CloudTTS -->|"audio response"| smarttts
    smarttts -->|"audio"| audioOut["audio chunk"]:::io
    smarttts -->|"logs"| log2
    core -->|"local synth"| ltts
    ltts -->|"audio"| audioOut
    ltts -->|"training trigger"| train
    train -->|"reads data"| txt
    audioOut --> play

    env_root -.-> core
    mcp -.-> core
    env_api -.-> s2t
    env_api -.-> smarttts
    env_clone -.-> train
    env_clone -.-> ltts

    tests --> core
    old -.-> core

    click rec "https://github.com/ztp559/agent-test/blob/main/voiceIO/record.py"
    click play "https://github.com/ztp559/agent-test/blob/main/voiceIO/play.py"
    click core "https://github.com/ztp559/agent-test/blob/main/Core.py"
    click s2t "https://github.com/ztp559/agent-test/blob/main/audioapi/s2t.py"
    click smarttts "https://github.com/ztp559/agent-test/blob/main/audioapi/smarttts.py"
    click log1 "https://github.com/ztp559/agent-test/blob/main/audioapi/message_log.txt"
    click log2 "https://github.com/ztp559/agent-test/blob/main/audioapi/send_log.txt"
    click train "https://github.com/ztp559/agent-test/blob/main/voiceclone/train.py"
    click ltts "https://github.com/ztp559/agent-test/blob/main/voiceclone/tts.py"
    click txt "https://github.com/ztp559/agent-test/blob/main/voiceclone/getText.json"
    click env_clone "https://github.com/ztp559/agent-test/blob/main/voiceclone/.env"
    click env_api "https://github.com/ztp559/agent-test/blob/main/audioapi/.env"
    click env_root "https://github.com/ztp559/agent-test/blob/main/.env"
    click mcp "https://github.com/ztp559/agent-test/blob/main/mcp.json"
    click req "https://github.com/ztp559/agent-test/blob/main/requirements.txt"
    click old "https://github.com/ztp559/agent-test/tree/main/old/"
    click tests "https://github.com/ztp559/agent-test/tree/main/test/"

    classDef io fill:#f9f,stroke:#333,stroke-width:2px
    classDef orchestrator fill:#bbf,stroke:#333,stroke-width:2px,stroke-dasharray:5 5
    classDef adapter fill:#bfb,stroke:#333,stroke-width:2px
    classDef local fill:#fbf,stroke:#333,stroke-width:2px
    classDef config fill:#ffb,stroke:#333,stroke-width:2px
    classDef storage fill:#fa0,stroke:#333,stroke-width:2px
    classDef external fill:#cff,stroke:#333,stroke-width:2px,stroke-dasharray:2 2
    classDef legacy fill:#ddd,stroke:#333,stroke-width:2px,stroke-dasharray:2 2
```
