# LiveKit Voice AI - 快速启动指南

## ✅ 状态检查

| 组件 | 状态 | 命令 |
|------|------|------|
| LiveKit Server | ✅ | Docker 运行中 |
| FunASR STT | ✅ | localhost:8080 |
| Agnes AI LLM | ✅ | api.agnes-ai.cn |
| Edge TTS | ✅ | 已启用 |

## 🚀 启动 Agent

```bash
source ~/s2s-env/bin/activate
cd /Users/leo/.hermes/workspace/livekit-agents
python3 agent_server.py start
```

## 🔑 生成 Token

```bash
python3 gen_token.py voice-ai-test user1
```

输出示例:
```
Room: voice-ai-test
Identity: user1
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

## 📱 React Native 配置

### 安装依赖
```bash
npm install livekit-client
```

### App.js 示例
```javascript
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { LiveKitRoom, useVoiceAssistant } from 'livekit-client';

const LIVEKIT_URL = 'ws://YOUR_MAC_IP:7880'; // 替换为你的 Mac IP
const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // 从 gen_token.py 获取

export default function App() {
  const { state, start, stop } = useVoiceAssistant();
  
  return (
    <LiveKitRoom
      serverUrl={LIVEKIT_URL}
      token={TOKEN}
      connectOptions={{ autoSubscribe: true }}
    >
      <View style={styles.container}>
        <Text style={styles.title}>🎙️ Voice AI</Text>
        <Text style={styles.status}>状态: {state}</Text>
        <Button title="开始对话" onPress={start} />
        <Button title="停止" onPress={stop} disabled={state === 'idle'} />
      </View>
    </LiveKitRoom>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: '#080c18', alignItems: 'center', justifyContent: 'center' },
  title: { fontSize: 28, color: '#00b4ff', marginBottom: 20 },
  status: { fontSize: 18, color: '#00ffaa', marginBottom: 30 },
});
```

### iOS HTTP 配置 (Info.plist)
```xml
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>
```

## 🔍 测试流程

1. **启动 Agent**: `python3 agent_server.py start`
2. **获取 Token**: `python3 gen_token.py`
3. **配置 React Native**: 更新 URL 和 Token
4. **运行 App**: `npx react-native run-ios`
5. **测试对话**: 点击"开始对话"并说话

## 🐛 调试

```bash
# 查看 Agent 日志
tail -f /tmp/agent.log

# 查看 LiveKit 日志
docker logs livekit-server

# 测试 Token
echo "Token: $(python3 gen_token.py)"
```
