AITuberKit Documentation

repository·main·Indexed 21 days ago

https://github.com/tegnike/aituber-kit

An all-in-one toolkit for building web applications featuring interactive AI characters. AITuberKit supports LLM integration, multimodal interactions (camera/image recognition), and specialized modes for live streaming (YouTube/OneComme), digital signage with human detection, and real-time voice interaction via OpenAI's Realtime and Audio APIs. It includes a unified access policy system for securing API routes and managing server-side secrets.

Tokens
45.3K
Snippets
87
Records
169
Agent score
74%

What's inside AITuberKit

  1. Overview of AITuberKit features and capabilities

    main

    AITuberKit is an all-in-one toolkit for building AI character web applications. Key capabilities include:

    1. AI Character Interaction

    • LLM Integration: Use various API keys for dialogue.
    • Multimodal: Supports camera vision and image uploads.
    • Memory: Includes short-term conversation memory and long-term memory via RAG.

    2. AITuber Live Streaming

    • Comment Interaction: Automatically responds to YouTube live comments (via YouTube API or OneComme).
    • Autonomous Mode: Characters can speak spontaneously even without new comments.

    3. Demo Terminals & Digital Signage

    • Signage Mode: Full-screen display with password protection, NG word filtering, and input limits.
    • Human Detection: Uses camera face detection to trigger greetings or farewells.
    • Idle Mode: Automatic speech during inactivity using fixed phrases or AI-generated content.

    4. Advanced Modes

    • Realtime API: Low-latency dialogue and function execution via OpenAI Realtime API.
    • Audio Mode: Natural voice dialogue via OpenAI Audio API.
    • Reasoning Mode: Displays the AI's thought process.
    • Game Commentary: Periodically analyzes screenshots to provide live commentary.

    5. Integration & Extensions

    • External Integration: Connect via WebSocket for advanced text/image exchange.
    • Slide Mode: AI-driven presentation mode.
    • Message API: Receive external text/images to trigger AI speech.
  2. Overview of AITuberKit

    main

    AITuberKit is an all-in-one open-source toolkit for building web applications that allow users to interact with AI characters. It supports various AI services, character models, and speech synthesis engines. Key capabilities include:

    • AI Character Interaction: Chatting via LLM APIs, multimodal support (camera/images), short-term memory, and RAG-based long-term memory.
    • AITuber Broadcasting: Automatic responses to YouTube or OneComme comments, continuous dialogue modes, and customizable comment fetching intervals.
    • Demo Terminal & Digital Signage: Full-screen modes with passcode authentication, NG word filtering, face detection for visitor greeting, and 'Idle Mode' for automatic character speech when inactive.
    • Advanced Modes: Low-latency interaction via OpenAI Realtime API, natural voice dialogue via Audio API, Reasoning mode for displaying AI thought processes, and Game Commentary mode via periodic screen capture analysis.
    • Integration & Extension: WebSocket support for external server communication, Slide mode for automated presentations, and a dedicated API for receiving external text/images to trigger character speech.
  3. Overview of AITuberKit features

    main

    AITuberKit is an all-in-one toolkit for building web applications that allow users to interact with AI characters. It supports various AI services, character models, and speech synthesis engines.

    Core Capabilities

    1. AI Character Interaction

    • LLM Integration: Chat with characters using various LLM API keys.
    • Multimodal Support: Characters can recognize camera feeds or uploaded images.
    • Memory: Maintains recent conversation history and utilizes RAG-based long-term memory for context.

    2. AITuber Streaming

    • Live Comment Integration: Automatically responds to YouTube comments using either the YouTube API or OneComme (わんコメ).
    • Continuous Conversation Mode: Allows the character to speak spontaneously even when no comments are received.

    3. Demo Terminals & Digital Signage

    • Demo Terminal Mode: Full-screen display optimized for signage, featuring passcode authentication, NG word filtering, and input length limits.
    • Human Detection: Uses camera face detection to automatically trigger greetings or farewells.
    • Idle Mode: Automatically triggers speech when conversation stops, using fixed phrases, time-of-day greetings, or AI-generated content.

    4. Advanced Interaction Modes

    • Realtime API: Low-latency interaction and function calling via OpenAI's Realtime API.
    • Audio Mode: Natural voice interaction using OpenAI's Audio API.
    • Reasoning Mode: Displays the AI's thought process and allows tuning of reasoning parameters.
    • Game Commentary Mode: Periodically analyzes screen captures to generate and speak commentary based on gameplay.

    5. Integration & Extension

    • External Integration Mode: Connects to server applications via WebSocket for advanced text/image exchange.
    • Slide Mode: AI characters can automatically present slides.
    • Message Reception API: Allows external systems to send text or images to trigger character speech via a dedicated API.
  4. Logo Usage Terms for aituber-kit

    main

    The logo used in the aituber-kit repository is subject to specific usage terms. Copyright belongs to the logo creator (Ruka Design).

    Permitted Uses

    • Non-commercial use related to this repository.
    • Using the logo to introduce this repository.
    • Using the logo for linking purposes (only for links to websites related to this repository).

    Prohibited Uses

    • Commercial use without prior written permission.
    • Modifying the logo or creating derivative works.
    • Redistributing the logo to third parties.
    • Using the logo in a way that damages the reputation or credit of the repository or its owners.

    Disclaimer

    • The logo is provided "as is" without warranties of any kind. The repository owner is not liable for any damages arising from the use of the logo.
    • Terms are subject to change without notice; users are responsible for checking updates regularly.
  5. Understand the Deployment Boundary Access Policy (F1)

    main

    The project uses multiple overlapping defense mechanisms to protect API keys and resources. A unified policy model is being designed based on Deployment Context (self-host / demo / embed / kiosk / external API) × Caller × Resource.

    Existing mechanisms include:

    1. guardServerSecretAccess (src/lib/api-services/serverSecretGuard.ts): Protects server environment API keys.
    2. isRestrictedMode (src/utils/restrictedMode.ts): Disables filesystem features for serverless environments.
    3. requireApiKey (src/features/api/http.ts): Bearer authentication for external control APIs (v1/*).
    4. Cloudflare WAF rules: The fourth layer of defense applied at the edge.
  6. Refactor streaming response pipeline into a State Machine (F4)

    main

    The current AI response processing in src/features/chat/handlers.ts (specifically processAIResponse) is a complex, monolithic function that handles:

    • Token stream processing
    • Emotion/motion tag parsing
    • Sentence splitting
    • Code block processing
    • SpeakQueue ingestion
    • Side effects (Slides/WebSocket)

    The goal is to redesign this into an explicit stream transformation pipeline and a verifiable state machine that manages session/stop tokens. This ensures that cancellation semantics (interruptions/stops) are predictable and testable across different input sources (Chat, WebSocket, Realtime).

  7. Copyright and attribution for AITuberKit models

    main

    When using the models provided in aituber-kit, be aware of the following copyright structures:

    VRM Models

    • Copyright: Owned by the developer.
    • Moral Rights: Belong to the respective creators of each model.

    Live2D Models

    • Copyright: Owned by the model creators.

    Model Creators Reference

    VRM Models:

    Live2D Models:

  8. Streaming Response Pipeline (F4)

    main

    The streaming response architecture is managed by a state machine located in src/features/chat/speechPipeline/. This pipeline handles the flow of AI responses into speech segments.

    Core components include:

    • SpeechSegmenter: A pure state machine that manages the segmentation of incoming text/audio.
    • messageLogWriter: Handles logging of the conversation stream.
    • speechDispatcher: Manages the actual dispatching of speech segments.
    • consumeStream: The primary interface for consuming the stream.

    This architecture replaces the previous handlers.ts implementation with a more robust, state-driven approach that handles complex edge cases like cancellation contracts and chunk-boundary processing.

  9. Understand AITuberKit licensing terms

    main

    Since version v2.0.0, AITuberKit uses a custom license:

    • Free Usage: Permitted for personal (non-commercial), educational, and non-profit purposes.
    • Commercial Usage: Requires a separate commercial license. Refer to license_en.md for details.

    Note: Priority feature implementation (paid requests) is separate from the commercial license. Even if a feature is implemented via priority request, its commercial use still requires a commercial license.

  10. How the Streaming Response Pipeline works

    main

    The streaming response pipeline is designed as a state machine to process AI token streams. It decomposes the complex task of handling AI responses into a pure, side-effect-free transformation process using a SpeechSegmenter.

    Core Architecture

    Instead of a single monolithic loop, the system uses a "Pure State Machine + Injectable Side Effects" pattern:

    1. SpeechSegmenter (The State Machine): A push-based, pure state machine that performs sequential transformations. It handles token stream reading, emotion/motion tag parsing, sentence splitting, and code block detection without triggering any external actions.
    2. Side Effects (The Consumers): Once the segmenter produces events (like a completed sentence or a detected tag), specialized modules consume these events to perform actual work:
      • messageLogWriter: Handles chatLog upserts, message ID boundary management, and accumulating thinking content.
      • speechDispatcher: Manages session arbitration, follows stop signals, and calls speakCharacter to trigger audio.
    3. Orchestration: The processAIResponse function acts as a lightweight orchestrator (under 100 lines) that reads the stream, classifies chunks (e.g., THINKING), feeds them into the segmenter, and distributes the resulting events to the writers and dispatchers.

    Key Benefits

    • Reliable Cancellation: Fixes issues where SpeakQueue.stopAll() failed to prevent subsequent speech by ensuring the pipeline respects session stop tokens.
    • Code Block Integrity: Prevents text from leaking into or out of code blocks (``) during chunk boundaries.
    • Tag Consistency: Ensures emotion tags (e.g., [happy]) and motion tags (e.g., [motion:xxx]) are handled with consistent semantics across different input sources.
  11. Understand the WebSocket External Linkage Protocol (v1 vs v2)

    main

    AITuberKit supports two WebSocket protocols for external integration: v1 legacy and the new v2 protocol.

    • v1 legacy: Uses a simple JSON structure.
      • Client sends: {"content": "...", "type": "chat", "image": "..."}
      • Server sends: {"text": "...", "role": "assistant", "emotion": "...", "type": "", "image": "..."}
    • v2 protocol: Uses a standardized envelope for all messages, providing better reliability through session management, heartbeats, and request tracking.

    Compatibility Logic:

    • The client detects the protocol by checking if the server sends a session.ready event. If not, it falls back to v1.
    • The server detects the protocol by checking for the version: "2" field. If missing, it treats the message as v1 and normalizes it to v2 internally.
    // v2 Envelope Example
    {
      "version": "2",
      "id": "msg_...",
      "type": "chat.message",
      "sessionId": "session_...",
      "timestamp": "2026-06-20T00:00:00.000Z",
      "payload": {},
      "metadata": {}
    }