ciyidogan commited on
Commit
b0885b4
·
verified ·
1 Parent(s): 0f4dc74

Update flare-ui/src/app/services/conversation-manager.service.ts

Browse files
flare-ui/src/app/services/conversation-manager.service.ts CHANGED
@@ -299,9 +299,27 @@ export class ConversationManagerService implements OnDestroy {
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);
@@ -397,40 +415,9 @@ export class ConversationManagerService implements OnDestroy {
397
  console.log('📤 [ConversationManager] Sending audio_ended to backend');
398
  this.wsService.sendControl('audio_ended');
399
 
400
- // Backend'den STT ready sinyalini bekle
401
- console.log(' [ConversationManager] Waiting for STT ready signal...');
402
-
403
- // STT ready handler'ı kur
404
- const sttReadyPromise = new Promise<boolean>((resolve) => {
405
- const subscription = this.wsService.message$.subscribe(message => {
406
- if (message.type === 'stt_ready') {
407
- console.log('✅ [ConversationManager] STT ready signal received');
408
- subscription.unsubscribe();
409
- resolve(true);
410
- }
411
- });
412
-
413
- // 10 saniye timeout
414
- setTimeout(() => {
415
- subscription.unsubscribe();
416
- resolve(false);
417
- }, 10000);
418
- });
419
-
420
- const sttReady = await sttReadyPromise;
421
-
422
- if (sttReady) {
423
- console.log('🎤 [ConversationManager] Starting audio recording');
424
-
425
- // Recording'i başlat
426
- if (!this.audioService.isRecording()) {
427
- await this.audioService.startRecording();
428
- console.log('✅ [ConversationManager] Audio recording started');
429
- }
430
- } else {
431
- console.error('❌ [ConversationManager] STT ready timeout');
432
- this.addSystemMessage('Speech recognition initialization timeout. Please try again.');
433
- }
434
  }
435
 
436
  } catch (error) {
@@ -441,8 +428,22 @@ export class ConversationManagerService implements OnDestroy {
441
 
442
  this.audioPlayer.onerror = (error) => {
443
  console.error('Audio player error:', error);
 
 
 
 
 
 
444
  };
445
- }
 
 
 
 
 
 
 
 
446
 
447
  private stopAudioPlayback(): void {
448
  try {
 
299
  break;
300
 
301
  case 'stt_ready':
302
+ console.log('✅ [ConversationManager] STT ready signal received');
303
+ // ✅ STT hazır, recording'i başlat
304
+ if (!this.audioService.isRecording()) {
305
+ this.audioService.startRecording().then(() => {
306
+ console.log('🎤 [ConversationManager] Audio recording started');
307
+ }).catch(error => {
308
+ console.error('❌ Failed to start recording:', error);
309
+ this.handleAudioError(error);
310
+ });
311
+ }
312
  break;
313
+
314
+ case 'state_change':
315
+ const newState = message['to'];
316
+ // ✅ processing_speech state'ine geçince recording'i durdur
317
+ if (newState === 'processing_speech' && this.audioService.isRecording()) {
318
+ console.log('🛑 [ConversationManager] Stopping recording - processing speech');
319
+ this.audioService.stopRecording();
320
+ }
321
+ break;
322
+
323
  }
324
  } catch (error) {
325
  console.error('Error handling message:', error);
 
415
  console.log('📤 [ConversationManager] Sending audio_ended to backend');
416
  this.wsService.sendControl('audio_ended');
417
 
418
+ // Backend STT başlatacak ve bize stt_ready sinyali gönderecek
419
+ // ✅ Recording'i burada başlatmıyoruz, handleMessage'da stt_ready gelince başlatacağız
420
+ console.log('⏳ [ConversationManager] Waiting for STT ready signal from backend...');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
 
423
  } catch (error) {
 
428
 
429
  this.audioPlayer.onerror = (error) => {
430
  console.error('Audio player error:', error);
431
+ this.errorSubject.next({
432
+ type: 'audio',
433
+ message: 'Audio playback error occurred',
434
+ details: error,
435
+ timestamp: new Date()
436
+ });
437
  };
438
+
439
+ this.audioPlayer.onplay = () => {
440
+ console.log('▶️ [ConversationManager] Audio playback started');
441
+ };
442
+
443
+ this.audioPlayer.onpause = () => {
444
+ console.log('⏸️ [ConversationManager] Audio playback paused');
445
+ };
446
+ }
447
 
448
  private stopAudioPlayback(): void {
449
  try {