Spaces:
Running
Running
Update flare-ui/src/app/services/conversation-manager.service.ts
Browse files
flare-ui/src/app/services/conversation-manager.service.ts
CHANGED
@@ -68,6 +68,8 @@ export class ConversationManagerService implements OnDestroy {
|
|
68 |
// Error handling
|
69 |
private errorSubject = new Subject<ConversationError>();
|
70 |
public error$ = this.errorSubject.asObservable();
|
|
|
|
|
71 |
|
72 |
// Audio player reference
|
73 |
private audioPlayer: HTMLAudioElement | null = null;
|
@@ -295,6 +297,11 @@ export class ConversationManagerService implements OnDestroy {
|
|
295 |
this.addSystemMessage('Speech recognition failed to initialize. Voice input will not be available.');
|
296 |
}
|
297 |
break;
|
|
|
|
|
|
|
|
|
|
|
298 |
}
|
299 |
} catch (error) {
|
300 |
console.error('Error handling message:', error);
|
@@ -391,21 +398,27 @@ export class ConversationManagerService implements OnDestroy {
|
|
391 |
this.wsService.sendControl('audio_ended');
|
392 |
}
|
393 |
|
394 |
-
//
|
395 |
-
console.log('⏳ [ConversationManager] Waiting for
|
396 |
-
await new Promise(resolve => setTimeout(resolve, 2000)); // 2 saniye bekle
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
-
|
407 |
-
|
408 |
-
console.log('🔄 [ConversationManager] Starting audio recording after state is listening...');
|
409 |
|
410 |
if (!this.audioService.isRecording()) {
|
411 |
await this.audioService.startRecording();
|
@@ -414,7 +427,8 @@ export class ConversationManagerService implements OnDestroy {
|
|
414 |
console.warn('⚠️ [ConversationManager] Audio already recording, skipping');
|
415 |
}
|
416 |
} else {
|
417 |
-
console.error('❌ [ConversationManager]
|
|
|
418 |
}
|
419 |
|
420 |
} catch (error) {
|
@@ -755,6 +769,7 @@ export class ConversationManagerService implements OnDestroy {
|
|
755 |
this.audioQueue = [];
|
756 |
this.isInterrupting = false;
|
757 |
this.currentStateSubject.next('idle');
|
|
|
758 |
|
759 |
console.log('🧹 Conversation cleaned up');
|
760 |
} catch (error) {
|
|
|
68 |
// Error handling
|
69 |
private errorSubject = new Subject<ConversationError>();
|
70 |
public error$ = this.errorSubject.asObservable();
|
71 |
+
|
72 |
+
private sttReadySubject = new Subject<boolean>();
|
73 |
|
74 |
// Audio player reference
|
75 |
private audioPlayer: HTMLAudioElement | null = null;
|
|
|
297 |
this.addSystemMessage('Speech recognition failed to initialize. Voice input will not be available.');
|
298 |
}
|
299 |
break;
|
300 |
+
|
301 |
+
case 'stt_ready':
|
302 |
+
console.log('✅ [ConversationManager] Backend STT ready signal received');
|
303 |
+
this.sttReadySubject.next(true);
|
304 |
+
break;
|
305 |
}
|
306 |
} catch (error) {
|
307 |
console.error('Error handling message:', error);
|
|
|
398 |
this.wsService.sendControl('audio_ended');
|
399 |
}
|
400 |
|
401 |
+
// STT ready sinyalini bekle
|
402 |
+
console.log('⏳ [ConversationManager] Waiting for STT ready signal from backend...');
|
|
|
403 |
|
404 |
+
const sttReadyPromise = new Promise<boolean>((resolve) => {
|
405 |
+
// STT ready sinyalini dinle
|
406 |
+
const subscription = this.sttReadySubject.subscribe(() => {
|
407 |
+
subscription.unsubscribe();
|
408 |
+
resolve(true);
|
409 |
+
});
|
410 |
+
|
411 |
+
// Timeout için güvenlik (10 saniye)
|
412 |
+
setTimeout(() => {
|
413 |
+
subscription.unsubscribe();
|
414 |
+
resolve(false);
|
415 |
+
}, 10000);
|
416 |
+
});
|
417 |
+
|
418 |
+
const sttReady = await sttReadyPromise;
|
419 |
|
420 |
+
if (sttReady) {
|
421 |
+
console.log('✅ [ConversationManager] STT ready signal received, starting audio recording...');
|
|
|
422 |
|
423 |
if (!this.audioService.isRecording()) {
|
424 |
await this.audioService.startRecording();
|
|
|
427 |
console.warn('⚠️ [ConversationManager] Audio already recording, skipping');
|
428 |
}
|
429 |
} else {
|
430 |
+
console.error('❌ [ConversationManager] Timeout waiting for STT ready signal');
|
431 |
+
this.addSystemMessage('Speech recognition initialization timeout. Please try again.');
|
432 |
}
|
433 |
|
434 |
} catch (error) {
|
|
|
769 |
this.audioQueue = [];
|
770 |
this.isInterrupting = false;
|
771 |
this.currentStateSubject.next('idle');
|
772 |
+
this.sttReadySubject.complete();
|
773 |
|
774 |
console.log('🧹 Conversation cleaned up');
|
775 |
} catch (error) {
|