feat(voice): implement real-time voice-to-voice streaming engine
Introduce a complete low-level audio processing and streaming pipeline for live voice conversations. - Implement `VoiceAudioEngine` using `AudioWorklet` for low-latency PCM16 capture and playback. - Add `pcm-capture` and `pcm-playback` worklets for high-performance audio processing outside the main thread. - Implement `VoiceStreamService` to manage the voice-to-voice state machine (LISTENING, PROCESSING, SPEAKING, INTERRUPTED). - Add `VoiceApiService` for managing conversation and session lifecycle via REST and WebSocket. - Create `VoiceStreamPanelComponent` to display real-time transcripts, status indicators, and the animated voice orb. - Integrate voice streaming into the `AiChatInputComponent` with support for seamless UI transitions between text and voice modes.
This commit is contained in:
@@ -0,0 +1,374 @@
|
||||
:host {
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.stream-panel {
|
||||
direction: rtl;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem 1.25rem 1.25rem;
|
||||
background: var(--surface-bg);
|
||||
border: 1px solid var(--surface-border);
|
||||
border-radius: 1.5rem;
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
/* ---------- Orb ---------- */
|
||||
.orb-container {
|
||||
width: 170px;
|
||||
height: 170px;
|
||||
max-width: 100%;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.orb-container canvas {
|
||||
display: block;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
}
|
||||
|
||||
.orb-fallback {
|
||||
width: 70%;
|
||||
height: 70%;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle at 35% 30%, #93c5fd, #3b82f6 55%, #1e3a5f);
|
||||
box-shadow: 0 0 40px rgba(59, 130, 246, 0.35);
|
||||
animation: fallbackPulse 2.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes fallbackPulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.06);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Status ---------- */
|
||||
.stream-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
margin: 0;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--text-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--muted);
|
||||
flex-shrink: 0;
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
|
||||
.stream-status[data-state='LISTENING'] .status-dot {
|
||||
background: #22c55e;
|
||||
animation: dotPulse 1.6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.stream-status[data-state='PROCESSING'] .status-dot {
|
||||
background: #818cf8;
|
||||
animation: dotPulse 0.9s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.stream-status[data-state='SPEAKING'] .status-dot {
|
||||
background: #a78bfa;
|
||||
animation: dotPulse 0.7s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.stream-status[data-state='INTERRUPTED'] .status-dot {
|
||||
background: #f59e0b;
|
||||
}
|
||||
|
||||
@keyframes dotPulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.55;
|
||||
transform: scale(1.3);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Transcript ---------- */
|
||||
.stream-transcript {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
max-width: 640px;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.25rem 0.25rem;
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
.stream-transcript::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
.stream-transcript::-webkit-scrollbar-thumb {
|
||||
background: var(--muted);
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.transcript-empty {
|
||||
margin: auto;
|
||||
font-size: 0.875rem;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* RTL: user bubbles sit on the right (start), assistant bubbles on the left (end). */
|
||||
.bubble-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.bubble-row.is-user {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
max-width: 85%;
|
||||
padding: 0.5rem 0.875rem;
|
||||
border-radius: 1.125rem;
|
||||
background: var(--sidebar-hover);
|
||||
color: var(--text-primary);
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.7;
|
||||
text-align: right;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
border-end-end-radius: 0.375rem;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.bubble.is-user {
|
||||
background: var(--color-primary);
|
||||
color: #ffffff;
|
||||
border-end-end-radius: 1.125rem;
|
||||
border-end-start-radius: 0.375rem;
|
||||
}
|
||||
|
||||
.bubble.is-partial {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.bubble.is-interrupted .bubble-text {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.bubble-tag {
|
||||
margin-inline-start: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
/* ---------- Sources (retrieved documents) ---------- */
|
||||
.source-list {
|
||||
list-style: none;
|
||||
margin: 0.375rem 0 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.source-chip {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.375rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border: 1px solid var(--surface-border);
|
||||
border-radius: 0.625rem;
|
||||
background: var(--surface-bg);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.source-chip.is-unavailable {
|
||||
opacity: 0.55;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.source-ref {
|
||||
flex-shrink: 0;
|
||||
padding: 0 0.375rem;
|
||||
border-radius: 9999px;
|
||||
background: var(--color-primary);
|
||||
color: #ffffff;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* ---------- Retryable server error ---------- */
|
||||
.stream-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
max-width: 640px;
|
||||
box-sizing: border-box;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid rgba(239, 68, 68, 0.45);
|
||||
border-radius: 0.875rem;
|
||||
color: #dc2626;
|
||||
font-size: 0.8125rem;
|
||||
line-height: 1.6;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stream-error span {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stream-error-close {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stream-error-close:focus-visible {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
/* ---------- Actions ---------- */
|
||||
.stream-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.625rem;
|
||||
flex-wrap: wrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stream-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 1.25rem;
|
||||
border: 1px solid var(--surface-border);
|
||||
border-radius: 9999px;
|
||||
background: var(--surface-bg);
|
||||
color: var(--text-secondary);
|
||||
font-family: inherit;
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.stream-btn:hover:not(:disabled) {
|
||||
background: var(--sidebar-hover);
|
||||
color: var(--text-primary);
|
||||
transform: scale(1.03);
|
||||
}
|
||||
|
||||
.stream-btn:active:not(:disabled) {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
|
||||
.stream-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.stream-btn:focus-visible {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.stream-btn.is-active {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border-color: rgba(239, 68, 68, 0.5);
|
||||
color: #dc2626;
|
||||
}
|
||||
|
||||
.stream-btn.is-end {
|
||||
background: #ef4444;
|
||||
border-color: #ef4444;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.stream-btn.is-end:hover:not(:disabled) {
|
||||
background: #dc2626;
|
||||
border-color: #dc2626;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.status-dot,
|
||||
.orb-fallback,
|
||||
.stream-btn,
|
||||
.bubble,
|
||||
.stream-transcript {
|
||||
animation: none !important;
|
||||
transition: none !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.stream-panel {
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.orb-container {
|
||||
width: 130px;
|
||||
height: 130px;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
max-width: 92%;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.stream-btn {
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user