> For the complete documentation index, see [llms.txt](https://agenttank.gitbook.io/agenttank/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agenttank.gitbook.io/agenttank/developers/core-infrastructure.md).

# Core Infrastructure

## Systems

This infrastructure provides the foundation for fluid, natural interaction between users and agents across the desktop environment.

### Narration System

The voice that brings agents to life:

* Real-time text-to-speech generation
* Voice model management
* Audio stream handling
* Emotion and tone control
* Performance optimization

```python
class VoiceHandler:
    async def generate_and_play(self, text: str):
        """Generate and play voice response"""
        audio = await self.elevenlabs_client.generate(
            text=text,
            voice_id=self.voice_id,
            model=self.voice_model
        )
        await self.play_audio(audio)
```

### Voice Command System

Natural language interface for agents:

* Voice input processing
* Command recognition
* Context awareness
* Multi-command chaining
* Real-time response

```python
class VoiceCommandSystem:
    def __init__(self, config):
        self.client = AsyncOpenAI(api_key=config['api_keys']['openai'])
        self.sample_rate = 16000
        self.recording = False
        self.chunks = []

    async def start_recording(self):
        self.recording = True
        self.stream = sd.InputStream(
            channels=1,
            samplerate=self.sample_rate,
            callback=self._audio_callback
        )
        self.stream.start()

    async def stop_and_transcribe(self):
        self.recording = False
        self.stream.stop()
        audio_data = np.concatenate(self.chunks)
        
        # Send to Whisper API for transcription
        response = await self.client.audio.transcriptions.create(
            model="whisper-1",
            file=("audio.wav", self._prepare_audio(audio_data))
        )
        return response.text
```

### Command Acceleration System

Supercharging agent actions:

* Hotkey management
* Command shortcuts
* Action chaining
* Quick access menus
* Custom command flows

```python
class CommandAccelerator:
    def __init__(self, config):
        self.client = AsyncOpenAI(api_key=config['api_keys']['openai'])
        self.command_history = []

    async def enhance_command(self, command: str) -> str:
        response = await self.client.chat.completions.create(
            model="gpt-4o-mini",
            messages=[
                {"role": "system", "content": "Enhance this command:"},
                {"role": "user", "content": command}
            ],
            temperature=0.7
        )
        enhanced = response.choices[0].message.content
        self.command_history.append((command, enhanced))
        return enhanced

    def get_command_suggestions(self, partial_command: str) -> list[str]:
        return [cmd for cmd, _ in self.command_history 
                if cmd.startswith(partial_command)]
```

### Avatar Management System

Visual representation control:

* Dynamic avatar states
* Emotion visualization
* Real-time animation
* Style customization
* Visual feedback

```python
class AvatarManager:
    def __init__(self):
        self.current_avatar = None
        self.avatars = {}
        self.observers = []

    def set_avatar(self, avatar_id: str):
        if avatar_id in self.avatars:
            self.current_avatar = self.avatars[avatar_id]
            self._notify_observers()

    def update_avatar_state(self, state: str):
        if self.current_avatar:
            self.current_avatar.state = state
            self._notify_observers()

    def _notify_observers(self):
        for observer in self.observers:
            observer.on_avatar_update(self.current_avatar)
```

### UI System

Modern, responsive interface:

* Circular video avatar
* Command input
* Region selection
* Status indicators

```python
def init_ui(self):
    """Initialize the user interface"""
    # Set window size with scaling
    base_width = 200
    base_height = 380
    self.resize(
        int(base_width * self.scaling_factor * 0.5),
        int(base_height * self.scaling_factor * 0.5)
    )
    
    # Setup window properties
    self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
    self.setAttribute(Qt.WA_TranslucentBackground)
```

### Notification System

Seamless user updates:

* Animated notifications
* Progress tracking
* Status updates

```python
class NotificationWindow(QWidget):
    def show_message(self, message: str):
        """Show animated notification"""
        self.message_label.setText(message)
        self.animation.start()
        self.progress_timer.start()
```
