feat(ui): implement voice interaction and enhanced home page animations

Introduces a comprehensive voice interaction system and upgrades the home page
experience with dynamic typing effects and improved layout transitions.

Key changes:
- Added `MicrophoneService` for managing media stream lifecycle and permissions.
- Added `SpeechRecognitionService` for continuous speech-to-text processing.
- Added `VoiceOrbService` using Three.js to render an animated audio-reactive
  orb.
- Enhanced `HomePage` with a randomized typing effect for welcome titles
  and improved state management for message transitions.
- Refactored `AiChatInputComponent` to support seamless switching between
  text composer and voice recording modes.
- Improved `SidebarComponent` navigation logic and styling.
- Updated global styles and component CSS for better theme consistency
  and smoother animations.
This commit is contained in:
PeymanHonarjoo
2026-10-06 17:27:52 +03:30
parent 3a0001c30d
commit d22cd65e28
16 changed files with 1736 additions and 478 deletions
@@ -0,0 +1,85 @@
import { Injectable } from '@angular/core';
export type MicrophoneErrorCode = 'unsupported' | 'denied' | 'unavailable' | 'unknown';
export class MicrophoneError extends Error {
constructor(readonly code: MicrophoneErrorCode, message?: string) {
super(message ?? code);
this.name = 'MicrophoneError';
}
}
/**
* Owns the microphone MediaStream. It does nothing except capture:
* the orb (audio level) and speech recognition consume it separately.
*/
@Injectable({ providedIn: 'root' })
export class MicrophoneService {
private stream: MediaStream | null = null;
private endedCleanup: (() => void) | null = null;
/** `mediaDevices` is undefined on non-secure (http) origins other than localhost. */
get isSupported(): boolean {
return typeof navigator !== 'undefined' && !!navigator.mediaDevices?.getUserMedia;
}
/**
* Requests microphone permission and returns the stream.
* @param onEnded called if the capture track ends unexpectedly (e.g. device unplugged).
*/
async request(onEnded?: () => void): Promise<MediaStream> {
if (!this.isSupported) {
throw new MicrophoneError('unsupported');
}
this.release();
let stream: MediaStream;
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
} catch (err) {
throw this.mapError(err);
}
this.stream = stream;
const track = stream.getAudioTracks()[0];
if (track && onEnded) {
const handler = (): void => onEnded();
track.addEventListener('ended', handler);
this.endedCleanup = () => track.removeEventListener('ended', handler);
}
return stream;
}
/** Stops every track of the given stream (defaults to the current one). */
release(stream: MediaStream | null = this.stream): void {
if (!stream) return;
if (stream === this.stream) {
this.endedCleanup?.();
this.endedCleanup = null;
this.stream = null;
}
stream.getTracks().forEach((track) => track.stop());
}
private mapError(err: unknown): MicrophoneError {
const name = err instanceof DOMException ? err.name : '';
switch (name) {
case 'NotAllowedError':
case 'SecurityError':
case 'PermissionDeniedError':
return new MicrophoneError('denied');
case 'NotFoundError':
case 'DevicesNotFoundError':
case 'NotReadableError':
case 'TrackStartError':
case 'OverconstrainedError':
return new MicrophoneError('unavailable');
default:
return new MicrophoneError('unknown');
}
}
}