# oussama-sil/audio2face_api architecture

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

- Interactive diagram: https://gitdiagram.com/oussama-sil/audio2face_api
- Repository: https://github.com/oussama-sil/audio2face_api

## Overview

##### Project type and purpose
- This is a Python client library (an open-source tool) that wraps NVIDIA’s Audio2Face Headless Mode API.
- It provides two operational modes:
- Direct Mode: sends whole audio files via HTTP and exports blendshapes to JSON.
- Stream Mode: streams audio chunks via gRPC, optionally captures frames via the LiveLink plugin.

##### File structure
- Top-level:
- pyproject.toml / setup: package metadata and dependencies
- assets/: sample audio and USD scene files used by tests
- src/audio2face_api/: main library code
- tests/: integration tests showing typical usage
- In src/audio2face_api/ you have:
- A2F.py and A2F_CONFIG.py: classes and config for Audio2Face (Direct & Stream)
- A2E.py and A2E_CONFIG.py: emotion‐control submodule
- Buffer.py: audio chunk buffer logic for streaming
- LiveLink.py: handling the LiveLink plugin callbacks
- grpc/: protocol definitions (audio2face.proto) and generated client stubs
- http_client.py: HTTP client for Direct mode

##### README for additional insights
- The README shows how user code instantiates either Audio2FaceDirect or Audio2FaceStream, configures emotion settings, and either exports JSON or streams audio and collects frames.
- It mentions two external endpoints: HTTP API (e.g. http://localhost:8011) and gRPC server (e.g. localhost:50051).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Tests
    subgraph "Tests"
        direction TB
        TestDirect["tests/test_api.py"]:::external
        TestStream["tests/test_api_stream.py"]:::external
    end

    %% File System Storage
    Assets[(Assets)]:::storage
    Output[(Output)]:::storage

    %% Library Modules
    subgraph "audio2face_api Library"
        direction TB
        A2FDirect["Audio2FaceDirect\n/Audio2FaceStream"]:::library
        A2E["A2E Module"]:::library
        A2EConfig["A2E_CONFIG.py"]:::library
        Buffer["Audio Chunk Buffer"]:::library
        LiveLink["LiveLink Handler"]:::library
        HTTPClient["HTTP Transport Client"]:::library
        GRPCStub["gRPC Stubs"]:::library
        Proto["audio2face.proto"]:::library
    end

    %% External Services
    HTTPAPI["Audio2Face HTTP API"]:::external
    gRPCServer["Audio2Face gRPC Server"]:::external
    LiveLinkHost["LiveLink Plugin Host"]:::external

    %% Interactions: Tests to Library
    TestDirect -->|"instantiate Audio2FaceDirect"| A2FDirect
    TestStream -->|"instantiate Audio2FaceStream"| A2FDirect

    %% Assets input
    Assets -->|"load audio/scene"| A2FDirect
    Assets -->|"load audio/scene"| A2FDirect

    %% Direct Mode Flow
    A2FDirect -->|"uses HTTPClient"| HTTPClient
    HTTPClient -->|"HTTP POST /blendshapes"| HTTPAPI
    HTTPAPI -->|"JSON blendshapes"| HTTPClient
    HTTPClient -->|"return data"| A2FDirect
    A2FDirect -->|"write JSON"| Output

    %% Stream Mode Flow
    A2FDirect -->|"uses Buffer"| Buffer
    Buffer -->|"gRPC Stream<AudioChunk>"| GRPCStub
    GRPCStub -->|"stream chunks"| gRPCServer
    gRPCServer -->|"stream frames"| GRPCStub
    GRPCStub -->|"deliver frames"| Buffer
    Buffer -->|"return data"| A2FDirect
    A2FDirect -->|"write JSON"| Output

    %% Optional LiveLink
    A2FDirect -.->|"if use_livelink"| LiveLink
    LiveLink -->|"subscribe frames"| LiveLinkHost
    LiveLinkHost -->|"callback frames"| LiveLink
    LiveLink -->|"return frames"| A2FDirect

    %% Emotion Module
    A2FDirect -->|"apply emotion controls"| A2E
    A2FDirect -->|"load config"| A2EConfig

    %% gRPC proto mapping
    GRPCStub --> Proto

    %% Click events
    click TestDirect "https://github.com/oussama-sil/audio2face_api/blob/main/tests/test_api.py"
    click TestStream "https://github.com/oussama-sil/audio2face_api/blob/main/tests/test_api_stream.py"
    click A2FDirect "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/A2F.py"
    click A2EConfig "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/A2E_CONFIG.py"
    click A2E "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/A2E.py"
    click Buffer "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/Buffer.py"
    click LiveLink "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/LiveLink.py"
    click HTTPClient "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/http_client.py"
    click GRPCStub "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/grpc/audio2face_pb2.py"
    click Proto "https://github.com/oussama-sil/audio2face_api/blob/main/src/audio2face_api/grpc/proto/audio2face.proto"
    click Assets "https://github.com/oussama-sil/audio2face_api/tree/main/assets/"

    %% Styles
    classDef library fill:#D6EAF8,stroke:#1B4F72
    classDef external fill:#D5F5E3,stroke:#186A3B
    classDef storage fill:#FCF3CF,stroke:#7D6608
```
