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
@@ -323,6 +323,15 @@ export class ConversationManagerService implements OnDestroy {
|
|
323 |
this.transcriptionSubject.next('');
|
324 |
}
|
325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
// Log state changes for debugging
|
327 |
console.log(`🎤 Continuous listening mode - state: ${to}`);
|
328 |
}
|
@@ -371,15 +380,32 @@ export class ConversationManagerService implements OnDestroy {
|
|
371 |
private setupAudioPlayerHandlers(): void {
|
372 |
if (!this.audioPlayer) return;
|
373 |
|
374 |
-
this.audioPlayer.onended = () => {
|
375 |
console.log('🎵 Audio playback ended');
|
376 |
-
|
377 |
-
|
378 |
-
|
|
|
|
|
379 |
this.wsService.sendControl('audio_ended');
|
380 |
-
} catch (error) {
|
381 |
-
console.error('Failed to send audio_ended signal:', error);
|
382 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
}
|
384 |
};
|
385 |
|
@@ -700,7 +726,11 @@ export class ConversationManagerService implements OnDestroy {
|
|
700 |
this.subscriptions.unsubscribe();
|
701 |
this.subscriptions = new Subscription();
|
702 |
|
703 |
-
|
|
|
|
|
|
|
|
|
704 |
this.wsService.disconnect();
|
705 |
this.stopAudioPlayback();
|
706 |
|
|
|
323 |
this.transcriptionSubject.next('');
|
324 |
}
|
325 |
|
326 |
+
// listening state'ine geçerken audio recording'in açık olduğundan emin ol
|
327 |
+
if (to === 'listening' && !this.audioService.isRecording()) {
|
328 |
+
console.log('⚠️ Entered listening state but audio not recording, starting...');
|
329 |
+
this.audioService.startRecording().catch(error => {
|
330 |
+
console.error('Failed to start audio recording in listening state:', error);
|
331 |
+
this.handleAudioError(error);
|
332 |
+
});
|
333 |
+
}
|
334 |
+
|
335 |
// Log state changes for debugging
|
336 |
console.log(`🎤 Continuous listening mode - state: ${to}`);
|
337 |
}
|
|
|
380 |
private setupAudioPlayerHandlers(): void {
|
381 |
if (!this.audioPlayer) return;
|
382 |
|
383 |
+
this.audioPlayer.onended = async () => {
|
384 |
console.log('🎵 Audio playback ended');
|
385 |
+
|
386 |
+
// TTS bittiğinde audio recording'i restart et
|
387 |
+
try {
|
388 |
+
// Önce backend'e audio bittiğini bildir
|
389 |
+
if (this.wsService.isConnected()) {
|
390 |
this.wsService.sendControl('audio_ended');
|
|
|
|
|
391 |
}
|
392 |
+
|
393 |
+
// Audio recording'i restart et
|
394 |
+
console.log('🔄 Restarting audio recording after TTS...');
|
395 |
+
|
396 |
+
// Mevcut recording'i durdur
|
397 |
+
this.audioService.stopRecording();
|
398 |
+
|
399 |
+
// Kısa bir bekleme süresi
|
400 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
401 |
+
|
402 |
+
// Yeni recording başlat
|
403 |
+
await this.audioService.startRecording();
|
404 |
+
console.log('✅ Audio recording restarted successfully');
|
405 |
+
|
406 |
+
} catch (error) {
|
407 |
+
console.error('❌ Failed to restart audio recording after TTS:', error);
|
408 |
+
this.handleAudioError(error);
|
409 |
}
|
410 |
};
|
411 |
|
|
|
726 |
this.subscriptions.unsubscribe();
|
727 |
this.subscriptions = new Subscription();
|
728 |
|
729 |
+
// Audio recording'i kesinlikle durdur
|
730 |
+
if (this.audioService.isRecording()) {
|
731 |
+
this.audioService.stopRecording();
|
732 |
+
}
|
733 |
+
|
734 |
this.wsService.disconnect();
|
735 |
this.stopAudioPlayback();
|
736 |
|