🧠 ALGE MASTER SYSTEM – Full AI Toy Platform (DLD/SES)

1. SYSTEM OVERVIEW

ALGE ist ein KI-basiertes Sprach- und Lernsystem für Kinder mit DLD/SES. Es kombiniert:
🧸 Raspberry Pi Spielzeug
🌐 Docker Backend Server
🧠 LLM + Memory + Emotion + DLD Engine

2. FULL ARCHITECTURE

🧸 Raspberry Pi (Toy Device)
- Mikrofon
- Lautsprecher
- Wake Word
- Audio Capture

        ↓ WLAN

🐳 Docker Server (ALGE Core)
- FastAPI Backend
- Memory Engine
- DLD/SES Adapter
- Whisper STT
- Emotion + Confidence

        ↓

🧠 AI Layer
- GPT / Local LLM
- Kontextanalyse
- Antwortgenerierung
- Lernlogik

3. DOCKER START (1 CLICK SYSTEM)

docker-compose up --build

4. DOCKER COMPOSE

version: "3.9"

services:
  backend:
    build: ./backend
    ports:
      - "8000:8000"
    volumes:
      - ./db.sqlite:/app/db.sqlite
    restart: always

5. FASTAPI CORE

from fastapi import FastAPI, File, UploadFile, Form
import shutil

app = FastAPI()

@app.post("/chat_audio")
def chat_audio(child_id: str, "temp.wav"

    with open(path, "wb") as buffer:
        shutil.copyfileobj(file.file, buffer)

    text = transcribe_audio(path)
    adapted = adapt_text(text)
    memory = load_memory(child_id)

    response = interpret(adapted, memory)

    save_memory(child_id, "last_input", text)

    return {
        "response": response,
        "text": text
    }

6. MEMORY SYSTEM (Learning Core)

import sqlite3

def load_memory(child_id):
    conn = sqlite3.connect("db.sqlite")
    c = conn.cursor()
    c.execute("SELECT key,value FROM memory WHERE child_id=?", (child_id,))
    return dict(c.fetchall())

7. DLD/SES ADAPTER

def adapt_text(text):
    rules = {
        "pappen": "krapfen",
        "tae": "katze",
        "ba": "ball",
        "hun": "hund"
    }

    for k,v in rules.items():
        text = text.replace(k,v)

    return text

8. EMOTION + CONFIDENCE (v3 CORE)

def emotion(text):
    if "nicht" in text:
        return "frust"
    return "neutral"


def confidence(text):
    return 0.8 if len(text) > 3 else 0.4

9. LLM ENGINE

def interpret(text, memory):
    prompt = f"""
Kind: {text}
Memory: {memory}

- freundlich antworten
- nicht bewerten
- sanft korrigieren
"""
    return "KI Antwort"

10. WHISPER STT

import whisper

model = whisper.load_model("base")

def transcribe_audio(path):
    return model.transcribe(path, language="de")["text"]

11. RASPBERRY PI CLIENT

import requests
import sounddevice as sd
from scipy.io.wavfile import write

def record():
    audio = sd.rec(16000*4, samplerate=16000, channels=1)
    sd.wait()
    write("input.wav",16000,audio)

def send():
    return requests.post(
        "http://SERVER:8000/chat_audio",
        files={"file": open("input.wav","rb")},
        data={"child_id":"toy_1"}
    ).json()

12. TEXT TO SPEECH

from gtts import gTTS
import os

def speak(text):
    tts = gTTS(text, lang="de")
    tts.save("out.mp3")
    os.system("mpg123 out.mp3")

13. MAIN LOOP (TOY BEHAVIOR)

while True:
    input("🎮 ENTER drücken")
    record()
    res = send()
    speak(res["response"])

14. SYSTEM CAPABILITIES

✔ DLD/SES Sprachverständnis
✔ Emotionserkennung
✔ Memory über Zeit
✔ KI Dialogsystem
✔ Lernverhalten
✔ Raspberry Pi Spielzeug
✔ Docker Backend Deployment

15. FINAL STATUS

ALGE MASTER ist ein Research-Grade AI Toy System für:
- Sprachtherapie
- Human-AI Interaction
- Assistive Communication
- Educational AI Systems