flowchart TD
%% --- USER INPUT LAYER ---
A0([User]) --> A1[Microphone Capture]
A1 --> A2[Noise Reduction + Audio Cleanup]
A2 --> A3[Voice Activity Detection VAD]
A3 -->|Speech Detected| A4[Segment Audio Chunks]
%% --- SPEECH-TO-TEXT PIPELINE ---
A4 --> A5[Whisper STT Engine]
A5 --> A6[Text Normalization & Cleanup]
A6 --> A7[Intent + Emotion Inference Natural Language Understanding]
%% --- ROUTING CORE ---
A7 -->|General Conversation| B1[Maiya Brain Core]
A7 -->|Command / Action| B2[Execution & Tool Layer]
A7 -->|Vision or Image Mention| B3[Vision Request Router]
%% --- MEMORY + LEARNING ---
B1 --> M1[Short-term Conversation Memory]
B1 --> M2[Long-term Personalization Memory]
M1 --> B1
M2 --> B1
%% --- TOOL LAYER ---
B2 --> T1[Local System Actions]
B2 --> T2[Web/Knowledge Lookup]
B2 --> T3[Program & App Control]
T1 --> B1
T2 --> B1
T3 --> B1
%% --- VISION + OCR PIPELINE ---
B3 --> V1[Image Capture / Upload Input]
V1 --> V2[Image Understanding Module]
V1 --> V3[OCR Text Extraction]
V2 --> B1
V3 --> B1
%% --- EMOTION + RESPONSE FORMATION ---
B1 --> R1[Response Text Generator]
R1 --> R2[Context-based Tone Selector]
R2 --> R3[Emotion Modeling Layer]
R3 --> R4[Speech Formatting Pauses Pitch Prosody Notes]
%% --- TEXT-TO-SPEECH PIPELINE ---
R4 --> S1[Voice Persona Selector]
S1 --> S2[Expressive TTS Engine]
S2 --> S3[Audio Post-Processing Breaths Warmth Presence]
S3 --> S4[Speaker Output]
%% --- USER FEEDBACK LOOP ---
S4 --> A0
%% Styling
classDef userNode fill:#ff6b6b,stroke:#c92a2a,stroke-width:3px,color:#fff
classDef processNode fill:#4ecdc4,stroke:#15aabf,stroke-width:2px,color:#fff
classDef memoryNode fill:#ffe066,stroke:#fcc419,stroke-width:2px,color:#2d3436
classDef toolNode fill:#a8e6cf,stroke:#55a3ff,stroke-width:2px,color:#2d3436
classDef visionNode fill:#dda0dd,stroke:#9370db,stroke-width:2px,color:#fff
classDef responseNode fill:#ff8b94,stroke:#ff6b6b,stroke-width:2px,color:#fff
classDef ttsNode fill:#74b9ff,stroke:#0984e3,stroke-width:2px,color:#fff
class A0 userNode
class A1,A2,A3,A4,A5,A6,A7 processNode
class B1,B2,B3 processNode
class M1,M2 memoryNode
class T1,T2,T3 toolNode
class V1,V2,V3 visionNode
class R1,R2,R3,R4 responseNode
class S1,S2,S3,S4 ttsNode