## AI Master Prompt for "Sohbet Akışı: Gerçek Zamanlı Yapay Zeka Asistanı"
### 1. PROJECT OVERVIEW
**Application Name:** Sohbet Akışı (Seamless Flow)
**Concept:** A revolutionary AI-powered application enabling real-time, full-duplex voice conversations between users and their devices. It aims to eliminate the traditional transcribe-think-synthesize pipeline, offering a single, integrated model that listens and speaks simultaneously, streaming audio chunks faster than real-time.
**Problem Solved:** Current voice interaction models are often latent, sequential, and resource-intensive, requiring cloud processing. This leads to noticeable delays and a less natural conversational experience. Furthermore, running advanced AI models locally on consumer hardware has been challenging due to computational and memory constraints, often necessitating Python environments and server-side processing.
**Value Proposition:** Sohbet Akışı provides an unparalleled, natural, and instantaneous voice interaction experience by leveraging the power of NVIDIA's PersonaPlex 7B model on Apple Silicon. Users can engage in fluid conversations with their devices, benefiting from native Swift implementation, on-device processing for enhanced privacy and speed, and multi-lingual capabilities. It democratizes advanced AI voice interaction, making it accessible directly on user hardware.
**Target Platforms:** macOS, iOS (initially focusing on Apple Silicon devices for optimal performance).
### 2. TECH STACK
* **Frontend Framework:** React (for potential web interface and future cross-platform expansion, though the core MVP will be native Swift/Objective-C for macOS/iOS).
* **UI Library:** Tailwind CSS (for rapid styling and responsive design, adaptable to both web and native UI frameworks if needed).
* **Core Logic Language:** Native Swift (for optimal performance on Apple Silicon using MLX).
* **State Management (if web frontend is considered):** Zustand or Redux Toolkit (for managing application state in a predictable manner).
* **Build Tools:** Xcode (for native development).
* **AI/ML Framework:** MLX (Apple's Metal Machine Learning Samples framework) for efficient on-device inference.
* **Model:** NVIDIA PersonaPlex 7B (4-bit quantized version, ~5.3 GB).
### 3. CORE FEATURES
**a. Full-Duplex Speech-to-Speech Conversation:**
* **User Flow:**
1. User initiates conversation via a microphone button or wake word.
2. The application continuously captures audio input.
3. The PersonaPlex 7B model, running via MLX on Apple Silicon, processes incoming audio chunks in real-time.
4. Simultaneously, the model generates audio output (speech synthesis) based on the ongoing conversation context and its understanding.
5. Both input processing and output generation happen concurrently, with audio streamed back to the user as it's generated (streaming chunks).
6. The system maintains context throughout the conversation.
* **Technical Details:** Requires careful management of audio buffers, real-time inference calls, and the MLX KV cache mechanism. The goal is sub-100ms latency per step (target RTF < 1.0).
**b. On-Device Automatic Speech Recognition (ASR):**
* **User Flow:** The model accurately transcribes spoken words into text, forming the 'listening' part of the full-duplex system.
* **Technical Details:** Utilizes the ASR capabilities integrated within PersonaPlex 7B, optimized for MLX.
**c. On-Device Text-to-Speech (TTS) Synthesis:**
* **User Flow:** The model generates natural-sounding speech from text, forming the 'speaking' part of the full-duplex system.
* **Technical Details:** Leverages the TTS capabilities of PersonaPlex 7B, including multilingual synthesis. The Mimi audio codec is integrated for efficient audio generation.
**d. Streaming Audio Chunks:**
* **User Flow:** Users hear the AI's response progressively, rather than waiting for the entire response to be generated. This mimics natural human conversation flow.
* **Technical Details:** Output audio is buffered and played back in small, near real-time chunks as they become available from the TTS engine.
**e. Native Swift / MLX Implementation:**
* **User Flow:** Users benefit from a fast, responsive application that runs efficiently on their Apple hardware without requiring background server connections or complex Python setups.
* **Technical Details:** Pure Swift implementation using MLX for GPU/ANE acceleration. Avoids Python interop, CPU-GPU tensor copying, and external dependencies where possible.
### 4. UI/UX DESIGN
* **Layout:** Single-Page Application (SPA) structure. A clean, minimalist interface focusing on the conversation. A central chat area displaying transcribed input and synthesized output. Minimal controls: a microphone button, settings access, and potentially a clear conversation button.
* **Color Palette:**
* Primary: Deep, calming blues (e.g., `#1a202c` - dark slate gray) or dark grays, evoking technology and focus.
* Accent: Vibrant, energetic accents (e.g., `#4299e1` - a bright blue or `#68d391` - a subtle green) for interactive elements like the microphone button when active, loading indicators, and highlights.
* Background: Very dark gray or off-black (`#111827`) for low eye strain, especially in low light.
* Text: Light gray or off-white (`#f3f4f6`) for readability.
* **Typography:** A modern, clean sans-serif font family (e.g., Inter, SF Pro Display). Clear hierarchy using font weights and sizes. `font-size: 16px` for body text, with larger sizes for headings and smaller for metadata.
* **Responsive Design:** While focusing on native macOS/iOS, the principles apply. On desktop, a wider chat view. On mobile, a vertically stacked view. Elements should adapt fluidly. Ensure touch targets are adequately sized for mobile.
* **Key Components:**
* `ConversationWindow`: Main area displaying the flow of conversation.
* `MessageBubble`: Represents individual user or AI messages.
* `MicrophoneButton`: Primary interaction element to start/stop listening.
* `LoadingIndicator`: Visual feedback during processing or when the AI is 'thinking'/'generating'.
* `SettingsPanel`: For audio input/output device selection, language settings, etc.
### 5. DATA MODEL & STATE MANAGEMENT
* **State Structure:** Use a central state management solution (like Zustand for React, or Swift's `ObservableObject` for native).
* `isListening`: boolean - Indicates if the microphone is active.
* `isProcessing`: boolean - Indicates if the AI is currently processing input or generating output.
* `conversationHistory`: Array<Message> - Stores the dialogue.
* `currentInputChunk`: string - Stores the text being transcribed in real-time.
* `currentOutputChunk`: string - Stores the text being synthesized in real-time.
* `settings`: object - Stores user preferences (language, model parameters, etc.).
* **Message Interface (Example):**
```typescript
interface Message {
id: string;
sender: 'user' | 'ai';
text: string;
timestamp: Date;
isStreaming?: boolean; // To indicate partial, in-progress messages
}
```
* **Local Storage/Persistence:** Conversation history might be stored locally for a session or longer-term, depending on user settings. Settings will be persisted.
* **Mock Data Format:** Messages will follow the `Message` interface. IDs can be simple timestamps or UUIDs. Timestamps will be ISO 8601 format strings.
### 6. COMPONENT BREAKDOWN (React Example - Adaptable to Swift UI)
* **`App.tsx`:**
* Props: None.
* Responsibility: Root component, sets up layout, state management, and routing (if applicable).
* Children: `Header`, `ConversationWindow`, `Footer`.
* **`Header.tsx`:**
* Props: `appName` (string).
* Responsibility: Displays the application title and potentially navigation/settings icons.
* Children: None.
* **`ConversationWindow.tsx`:**
* Props: `messages` (Array<Message>), `isAiStreaming` (boolean).
* Responsibility: Renders the list of messages, handles scrolling, and displays the incoming AI stream.
* Children: `MessageBubble` (rendered in a loop).
* **`MessageBubble.tsx`:**
* Props: `message` (Message).
* Responsibility: Renders a single chat message, styling differently based on `sender` ('user' or 'ai'). Handles displaying 'streaming' state.
* Children: None.
* **`Footer.tsx`:**
* Props: `isListening` (boolean), `isProcessing` (boolean), `onToggleListen` (function).
* Responsibility: Contains the main controls, primarily the microphone button. Manages listening and processing states visually.
* Children: `MicrophoneButton`, `LoadingIndicator` (conditionally rendered).
* **`MicrophoneButton.tsx`:**
* Props: `isListening` (boolean), `onClick` (function), `isProcessing` (boolean).
* Responsibility: The primary button to start/stop audio input. Changes appearance based on state (e.g., pulsing red when listening).
* Children: Icon (e.g., microphone).
* **`LoadingIndicator.tsx`:**
* Props: `isVisible` (boolean).
* Responsibility: Shows a visual indicator (e.g., spinner, pulsing dots) when the AI is busy.
* Children: None.
### 7. ANIMATIONS & INTERACTIONS
* **Microphone Button:** Subtle scale animation on press. Pulsing effect (color/size) when actively listening. Color change to indicate processing state.
* **Message Bubbles:** Fade-in animation as new messages appear. A subtle 'typing' animation (e.g., pulsating dots) for the AI's `isStreaming` state within the `MessageBubble`.
* **Loading States:** Smooth transitions when showing/hiding the `LoadingIndicator`.
* **Scrolling:** Smooth scrolling animation when new messages arrive that push content out of view.
* **Transitions:** Use Tailwind CSS transitions for color, scale, and opacity changes on interactive elements.
### 8. EDGE CASES & ACCESSIBILITY (a11y)
* **No Microphone Access:** Gracefully handle cases where the user denies microphone permissions, providing clear instructions on how to enable it in settings.
* **Empty State:** When `conversationHistory` is empty, display a welcoming message and instructions on how to start (e.g., "Tap the microphone to start talking!").
* **Error Handling:**:
* Network errors (if any server interaction is added later).
* Model loading errors (e.g., model file corrupted or missing).
* Audio processing errors.
* Display user-friendly error messages and recovery options.
* **Validation:** Primarily related to settings (e.g., ensuring valid language codes if applicable).
* **Accessibility:**
* Ensure sufficient color contrast for text and UI elements.
* Provide ARIA labels for all interactive elements (buttons, controls).
* Ensure keyboard navigability for all interactive components.
* Use semantic HTML elements where appropriate (if using React).
* Test with screen readers.
* **Performance:** Monitor MLX inference times. Implement throttling/debouncing if necessary for UI updates. Ensure efficient audio buffer management to prevent memory leaks.
### 9. SAMPLE DATA (Mock Data)
```json
[
{
"id": "msg_1708700000100",
"sender": "user",
"text": "Merhaba, bana bugünkü hava durumunu söyle.",
"timestamp": "2024-02-23T10:00:00.100Z",
"isStreaming": false
},
{
"id": "msg_1708700001500",
"sender": "ai",
"text": "Elbette, nerede olduğunuzu öğrenebilir miyim?",
"timestamp": "2024-02-23T10:00:01.500Z",
"isStreaming": true
},
{
"id": "msg_1708700002000",
"sender": "ai",
"text": "", // Initial empty text for streaming
"timestamp": "2024-02-23T10:00:02.000Z",
"isStreaming": true // Indicates stream is active
}
// ... more messages will be streamed and appended to the 'text' of the AI message
// Example of a completed streaming message:
{
"id": "msg_1708700003000",
"sender": "ai",
"text": "İstanbul için bugün hava parçalı bulutlu ve sıcaklık 15 derece Celsius civarında olacak.",
"timestamp": "2024-02-23T10:00:03.000Z",
"isStreaming": false // Stream finished
},
{
"id": "msg_1708700004500",
"sender": "user",
"text": "Teşekkürler! Yarın için de bilgi verebilir misin?",
"timestamp": "2024-02-23T10:00:04.500Z",
"isStreaming": false
},
{
"id": "empty_state_prompt",
"sender": "ai",
"text": "Merhaba! Sohbeti başlatmak için mikrofon simgesine dokunun.",
"timestamp": "2024-02-23T09:00:00.000Z",
"isStreaming": false
}
]
```
### 10. DEPLOYMENT NOTES
* **Build Process:** Standard Xcode build for macOS and iOS applications. For a potential web interface, standard React build (`npm run build` or `yarn build`).
* **Environment Variables:** Use `.env` files for configuration (e.g., API keys if any backend services are introduced later, model paths). For MLX, model paths will likely be relative or configured during the build.
* **Model Management:** The PersonaPlex 7B model file (~5.3 GB) needs to be bundled with the application or downloaded on first run. Consider download progress indicators and offline availability.
* **Performance Optimization:**
* Ensure MLX is correctly configured to utilize Apple Silicon's Neural Engine (ANE) and GPU.
* Optimize audio encoding/decoding.
* Profile the application regularly to identify and fix performance bottlenecks, especially during continuous audio processing.
* Lazy load components if the UI becomes complex.
* **Code Signing:** Proper code signing is crucial for macOS and iOS applications to run without security warnings.
* **Updates:** Plan for model updates (new versions of PersonaPlex) and application updates. Consider a mechanism for background model updates if feasible.
* **Testing:** Implement unit tests for state management logic and utility functions. Integration tests for core features like audio processing. End-to-end testing on target devices is critical.