feat: voice mode bottom sheet with hold/tap/auto talk modes
This commit is contained in:
@@ -144,33 +144,15 @@
|
||||
</div>
|
||||
{#if activeTab && tabs.find(t => t.id === activeTab)?.connected && activeVoice()}
|
||||
{@const v = activeVoice()}
|
||||
<div class="ml-auto flex items-center gap-1">
|
||||
<div class="ml-auto">
|
||||
<button
|
||||
class="px-2 py-1 rounded text-sm transition-colors {v.ttsEnabled ? (v.speaking ? 'text-indigo-400' : 'text-emerald-400') : 'text-surface-500 hover:text-surface-300'}"
|
||||
title={v.ttsEnabled ? 'Disable TTS' : 'Enable TTS'}
|
||||
onclick={() => { v.toggleTts(); voiceTick++; }}
|
||||
>
|
||||
{#if !v.ttsEnabled}
|
||||
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 5L6 9H2v6h4l5 4V5z"/><line x1="23" y1="9" x2="17" y2="15"/><line x1="17" y1="9" x2="23" y2="15"/></svg>
|
||||
{:else if v.speaking}
|
||||
<svg class="w-4 h-4 animate-pulse" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 5L6 9H2v6h4l5 4V5z"/><path d="M15.54 8.46a5 5 0 010 7.07"/><path d="M19.07 4.93a10 10 0 010 14.14"/></svg>
|
||||
{:else}
|
||||
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 5L6 9H2v6h4l5 4V5z"/><path d="M15.54 8.46a5 5 0 010 7.07"/></svg>
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
class="px-2 py-1 rounded text-sm transition-colors {v.listening ? 'text-rose-400 animate-pulse' : v.sttAvailable ? 'text-surface-500 hover:text-surface-300' : 'text-surface-700 cursor-not-allowed'}"
|
||||
title={!v.sttAvailable ? 'STT not supported in this browser' : v.listening ? 'Stop mic' : 'Start mic'}
|
||||
class="px-2 py-1 rounded text-sm transition-colors {v.voiceMode ? 'text-rose-400' : v.sttAvailable ? 'text-surface-500 hover:text-surface-300' : 'text-surface-700 cursor-not-allowed'}"
|
||||
title={!v.sttAvailable ? 'STT not supported' : v.voiceMode ? 'Voice mode on' : 'Enter voice mode'}
|
||||
disabled={!v.sttAvailable}
|
||||
onclick={() => { v.toggleMic(); voiceTick++; }}
|
||||
onclick={() => { if (!v.voiceMode) v.enterVoiceMode(); else v.exitVoiceMode(); voiceTick++; }}
|
||||
>
|
||||
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
|
||||
</button>
|
||||
<button
|
||||
class="px-1.5 py-0.5 rounded text-xs font-medium transition-colors text-surface-400 hover:text-surface-200 hover:bg-surface-800"
|
||||
title="Switch language"
|
||||
onclick={() => { v.cycleLang(); voiceTick++; }}
|
||||
>{v.langLabel}</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -185,9 +167,78 @@
|
||||
<div class={activeTab === tab.id ? '' : 'hidden'}>
|
||||
<div
|
||||
use:initTerminal={tab}
|
||||
class="h-[calc(100vh-10rem)] rounded-xl overflow-hidden shadow-lg border border-surface-700"
|
||||
style="background: #0f172a;"
|
||||
class="rounded-xl overflow-hidden shadow-lg border border-surface-700 transition-all duration-300"
|
||||
style="background: #0f172a; height: calc(100vh - {activeVoice()?.voiceMode ? '25rem' : '10rem'});"
|
||||
></div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if activeVoice()?.voiceMode}
|
||||
{@const v = activeVoice()}
|
||||
<div class="mt-2 rounded-xl bg-surface-800/95 border border-surface-700 shadow-xl overflow-hidden animate-slide-up" style="height: 180px;">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b border-surface-700/50">
|
||||
<span class="text-sm font-medium text-surface-300">Voice Mode</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="px-1.5 py-0.5 rounded text-xs font-medium text-surface-400 hover:text-surface-200 hover:bg-surface-700"
|
||||
onclick={() => { v.cycleLang(); voiceTick++; }}
|
||||
>{v.langLabel}</button>
|
||||
<button
|
||||
class="px-1.5 py-0.5 rounded text-xs font-medium text-surface-400 hover:text-surface-200 hover:bg-surface-700"
|
||||
onclick={() => { v.cycleTalkMode(); voiceTick++; }}
|
||||
>{v.modeLabel}</button>
|
||||
<button
|
||||
class="px-1.5 py-0.5 rounded text-xs text-surface-500 hover:text-rose-400"
|
||||
onclick={() => { v.exitVoiceMode(); voiceTick++; }}
|
||||
>×</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Transcript -->
|
||||
<div class="px-4 py-2 h-[60px] overflow-y-auto">
|
||||
{#if v.transcript}
|
||||
<p class="text-sm text-surface-400 italic">"{v.transcript}"</p>
|
||||
{:else}
|
||||
<p class="text-sm text-surface-600 italic">{v.speaking ? 'Speaking...' : 'Waiting for speech...'}</p>
|
||||
{/if}
|
||||
</div>
|
||||
<!-- Mic area -->
|
||||
<div class="flex flex-col items-center gap-1 py-2">
|
||||
{#if v.talkMode === "hold"}
|
||||
<button
|
||||
aria-label="Hold to talk"
|
||||
class="w-14 h-14 rounded-full flex items-center justify-center transition-colors {v.listening ? 'bg-rose-500/30 text-rose-400' : 'bg-surface-700 text-surface-300 hover:bg-surface-600'}"
|
||||
onpointerdown={() => { v.startHold(); voiceTick++; }}
|
||||
onpointerup={() => { v.releaseHold(); voiceTick++; }}
|
||||
onpointerleave={() => { if (v.listening) { v.releaseHold(); voiceTick++; } }}
|
||||
>
|
||||
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
|
||||
</button>
|
||||
<span class="text-xs text-surface-500">{v.listening ? 'Release to send' : 'Hold to talk'}</span>
|
||||
{:else if v.talkMode === "tap"}
|
||||
<button
|
||||
aria-label="Tap to talk"
|
||||
class="w-14 h-14 rounded-full flex items-center justify-center transition-colors {v.listening ? 'bg-rose-500/30 text-rose-400' : 'bg-surface-700 text-surface-300 hover:bg-surface-600'}"
|
||||
onclick={() => { v.tapMic(); voiceTick++; }}
|
||||
>
|
||||
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
|
||||
</button>
|
||||
<span class="text-xs text-surface-500">{v.listening ? 'Tap to send' : 'Tap to talk'}</span>
|
||||
{:else}
|
||||
<div class="w-14 h-14 rounded-full flex items-center justify-center {v.listening ? 'bg-emerald-500/20 text-emerald-400 animate-pulse' : 'bg-surface-700 text-surface-500'}">
|
||||
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
|
||||
</div>
|
||||
<span class="text-xs text-surface-500">{v.listening ? 'Listening...' : v.speaking ? 'Speaking...' : 'Ready'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@keyframes slide-up {
|
||||
from { transform: translateY(100%); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
.animate-slide-up { animation: slide-up 0.25s ease-out; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user