feat(chat): add voice playback with auto-play and visual effects (#396)

## Features

### Core Functionality
- **Web Speech API Integration**: Add TTS (text-to-speech) playback for assistant messages
- **Manual Playback**: Click-to-play button next to each assistant message (🔊 icon)
- **Auto-play Mode**: Toggle switch in input bar to auto-play responses
- **Playback Controls**: Play/pause/stop with visual feedback

### User Interface
- **Playback Button**: Hover-activated button in message meta area (next to copy button)
- **Auto-play Switch**: Voice icon toggle in input top bar with state persistence
- **Mobile Optimization**: Buttons always visible on mobile (≤768px width)
- **Visual Feedback**:
  - Rainbow glowing border during playback (2px border, 10px/20px glow)
  - 4-second animation cycle through 6 colors
  - Play/pause icon toggle

### Voice Customization
- **Pitch/Rate Control**: Low-pitched (0.5) fast-speaking (1.2) "male voice"
- **Auto Voice Selection**: Attempts to select male voices across platforms (macOS: Yaoyao, Windows: David/Daniel)
- **Platform Compatibility**: Works with system-provided voices on macOS, iOS, Android, Windows

### Content Filtering
- Smart text extraction: filters code blocks, `<thinking>` tags, HTML
- Only assistant messages are eligible for playback
- Tool and system messages are excluded

### Internationalization
- Added 8 language translations (en, zh, de, es, fr, ja, ko, pt)
- New keys: `playSpeech`, `pauseSpeech`, `resumeSpeech`, `stopSpeech`, `autoPlaySpeech`, `speechNotSupported`

## Technical Details

### New Files
- `packages/client/src/composables/useSpeech.ts`: Core speech synthesis composable
  - Voice loading and selection logic
  - Single-instance global speech manager
  - Event handling (onstart, onend, onerror, onboundary)
  - State management (isPlaying, isPaused, currentMessageId)

### Modified Components
- **ChatInput.vue**: Auto-play switch with localStorage persistence
- **MessageItem.vue**:
  - Playback button integration
  - Event listener for auto-play triggers
  - Mobile-first button visibility
  - Rainbow border animation during playback

### Store Changes
- `chat.ts`:
  - Added `autoPlaySpeechEnabled` state
  - `setAutoPlaySpeech()` method
  - `playMessageSpeech()` method for event-based playback
  - Auto-play trigger on `run.completed` event

## Browser Support
- Requires Web Speech API support (all modern browsers)
- Graceful degradation: button hidden if API not supported
- Voice availability varies by platform and OS

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-02 13:26:57 +08:00
committed by GitHub
parent 4c8cff2e7c
commit caa9162f28
12 changed files with 624 additions and 13 deletions
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: 'Nachricht kopieren',
copiedBubble: 'Nachricht kopiert',
copyFailed: 'Kopieren fehlgeschlagen',
playSpeech: 'Sprache abspielen',
pauseSpeech: 'Pause',
resumeSpeech: 'Fortsetzen',
stopSpeech: 'Stoppen',
speechNotSupported: 'Sprachwiedergabe in diesem Browser nicht unterstützt',
},
// Jobs
+6
View File
@@ -111,6 +111,7 @@ export default {
emptyState: 'Start a conversation with Hermes Agent',
inputPlaceholder: 'Type a message... (Enter to send, Shift+Enter for new line)',
attachFiles: 'Attach files',
autoPlaySpeech: 'Auto-play voice',
stop: 'Stop',
start: 'Start',
stopGateway: 'Stop Gateway',
@@ -176,6 +177,11 @@ export default {
copyBubble: 'Copy message',
copiedBubble: 'Message copied',
copyFailed: 'Copy failed',
playSpeech: 'Play voice',
pauseSpeech: 'Pause',
resumeSpeech: 'Resume',
stopSpeech: 'Stop',
speechNotSupported: 'Voice playback not supported in this browser',
},
// Jobs
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: 'Copiar mensaje',
copiedBubble: 'Mensaje copiado',
copyFailed: 'Error al copiar',
playSpeech: 'Reproducir voz',
pauseSpeech: 'Pausa',
resumeSpeech: 'Reanudar',
stopSpeech: 'Detener',
speechNotSupported: 'Reproducción de voz no soportada en este navegador',
},
// Jobs
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: 'Copier le message',
copiedBubble: 'Message copié',
copyFailed: 'Échec de la copie',
playSpeech: 'Lire à voix haute',
pauseSpeech: 'Pause',
resumeSpeech: 'Reprendre',
stopSpeech: 'Arrêter',
speechNotSupported: 'Reproduction vocale non prise en charge dans ce navigateur',
},
// Jobs
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: 'メッセージをコピー',
copiedBubble: 'コピーしました',
copyFailed: 'コピーに失敗しました',
playSpeech: '音声を読み上げ',
pauseSpeech: '一時停止',
resumeSpeech: '再開',
stopSpeech: '停止',
speechNotSupported: 'このブラウザは音声読み上げをサポートしていません',
},
// スケジュールジョブ
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: '메시지 복사',
copiedBubble: '복사됨',
copyFailed: '복사 실패',
playSpeech: '음성 재생',
pauseSpeech: '일시정지',
resumeSpeech: '재개',
stopSpeech: '중지',
speechNotSupported: '이 브라우저는 음성 재생을 지원하지 않습니다',
},
// 예약 작업
+5
View File
@@ -147,6 +147,11 @@ export default {
copyBubble: 'Copiar mensagem',
copiedBubble: 'Mensagem copiada',
copyFailed: 'Falha ao copiar',
playSpeech: 'Reproduzir voz',
pauseSpeech: 'Pausar',
resumeSpeech: 'Retomar',
stopSpeech: 'Parar',
speechNotSupported: 'Reprodução de voz não suportada neste navegador',
},
// Jobs
+6
View File
@@ -111,6 +111,7 @@ export default {
emptyState: '开始与 Hermes Agent 对话',
inputPlaceholder: '输入消息... (Enter 发送,Shift+Enter 换行)',
attachFiles: '添加附件',
autoPlaySpeech: '自动播放语音',
stop: '停止',
start: '启动',
stopGateway: '停止网关',
@@ -176,6 +177,11 @@ export default {
copyBubble: '复制消息',
copiedBubble: '已复制',
copyFailed: '复制失败',
playSpeech: '播放语音',
pauseSpeech: '暂停',
resumeSpeech: '继续',
stopSpeech: '停止',
speechNotSupported: '此浏览器不支持语音播放',
},
// 定时任务