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:
@@ -1,7 +1,30 @@
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
inject,
|
||||
signal,
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AiChatInputComponent } from '../../shared/ui/ai-chat-input/ai-chat-input.component';
|
||||
import { Router, NavigationEnd } from '@angular/router';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { ThemeService } from '../../services/theme/theme.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
const HOME_TITLES = [
|
||||
'چه چیزی میخواهید بدانید؟...',
|
||||
'سوالتان را بپرسید، با شما هستم...',
|
||||
'هر سوالی دارید، از من بپرسید...',
|
||||
'از هر چیزی که میخواهید شروع کنید...',
|
||||
'سوالتان را مطرح کنید، پاسخ میدهم...',
|
||||
'بپرسید؛ با هم به پاسخ میرسیم...',
|
||||
'هر سوالی در ذهن دارید، بپرسید...',
|
||||
'دنبال یک پاسخ دقیق هستید؟...',
|
||||
'سوالتان را همینجا مطرح کنید...',
|
||||
'آمادهام به سوالتان پاسخ بدهم...',
|
||||
];
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -11,14 +34,92 @@ import { ThemeService } from '../../services/theme/theme.service';
|
||||
templateUrl: './home.page.html',
|
||||
styleUrl: './home.page.css',
|
||||
})
|
||||
export class HomePage {
|
||||
export class HomePage implements OnInit, OnDestroy {
|
||||
private readonly themeService = inject(ThemeService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
readonly isDarkMode = this.themeService.isDarkMode;
|
||||
|
||||
readonly logoSrc = () => this.isDarkMode() ? 'assets/images/RaymandLogo.png' : 'assets/images/login.png';
|
||||
readonly logoSrc = () =>
|
||||
this.isDarkMode() ? 'assets/images/RaymandLogo.png' : 'assets/images/login.png';
|
||||
|
||||
readonly hasMessages = signal(false);
|
||||
|
||||
readonly homeTitle = signal('');
|
||||
readonly streamedText = signal('');
|
||||
readonly isStreaming = signal(false);
|
||||
|
||||
private typingTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private routerSubscription?: Subscription;
|
||||
|
||||
constructor() {
|
||||
this.routerSubscription = this.router.events
|
||||
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||
.subscribe((event: NavigationEnd) => {
|
||||
if (event.url === '/' || event.url === '') {
|
||||
this.hasMessages.set(false);
|
||||
this.setRandomTitle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.setRandomTitle();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.stopTyping();
|
||||
this.routerSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
private setRandomTitle(): void {
|
||||
this.stopTyping();
|
||||
|
||||
const index = Math.floor(Math.random() * HOME_TITLES.length);
|
||||
const title = HOME_TITLES[index];
|
||||
|
||||
this.homeTitle.set(title);
|
||||
this.startTyping(title);
|
||||
}
|
||||
|
||||
private startTyping(text: string): void {
|
||||
this.streamedText.set('');
|
||||
this.isStreaming.set(true);
|
||||
|
||||
let index = 0;
|
||||
|
||||
const typeNextCharacter = () => {
|
||||
if (index >= text.length) {
|
||||
this.streamedText.set(text);
|
||||
this.isStreaming.set(false);
|
||||
this.typingTimer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
this.streamedText.set(text.substring(0, index));
|
||||
|
||||
// Slightly random timing makes it feel more natural
|
||||
const delay = 12 + Math.random() * 8;
|
||||
|
||||
this.typingTimer = setTimeout(typeNextCharacter, delay);
|
||||
};
|
||||
|
||||
typeNextCharacter();
|
||||
}
|
||||
|
||||
private stopTyping(): void {
|
||||
if (this.typingTimer !== null) {
|
||||
clearTimeout(this.typingTimer);
|
||||
this.typingTimer = null;
|
||||
}
|
||||
|
||||
this.isStreaming.set(false);
|
||||
}
|
||||
|
||||
onMessageSent(message: string): void {
|
||||
this.hasMessages.set(true);
|
||||
console.log('Message sent:', message);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user