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
@@ -392,33 +392,37 @@ export class ConversationManagerService implements OnDestroy {
|
|
392 |
});
|
393 |
|
394 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
// Önce backend'e audio bittiğini bildir
|
396 |
if (this.wsService.isConnected()) {
|
397 |
console.log('📤 [ConversationManager] Sending audio_ended to backend');
|
398 |
this.wsService.sendControl('audio_ended');
|
399 |
}
|
400 |
|
401 |
-
//
|
402 |
-
console.log('⏳ [ConversationManager] Waiting for
|
403 |
|
404 |
-
|
405 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
-
if (
|
421 |
-
console.log('✅ [ConversationManager]
|
|
|
|
|
|
|
422 |
|
423 |
if (!this.audioService.isRecording()) {
|
424 |
await this.audioService.startRecording();
|
@@ -427,8 +431,8 @@ export class ConversationManagerService implements OnDestroy {
|
|
427 |
console.warn('⚠️ [ConversationManager] Audio already recording, skipping');
|
428 |
}
|
429 |
} else {
|
430 |
-
console.error('❌ [ConversationManager]
|
431 |
-
this.addSystemMessage('Speech recognition initialization
|
432 |
}
|
433 |
|
434 |
} catch (error) {
|
|
|
392 |
});
|
393 |
|
394 |
try {
|
395 |
+
// Audio recording'in çalışmadığından emin ol
|
396 |
+
if (this.audioService.isRecording()) {
|
397 |
+
console.log('⚠️ [ConversationManager] Stopping existing recording first');
|
398 |
+
this.audioService.stopRecording();
|
399 |
+
}
|
400 |
+
|
401 |
// Önce backend'e audio bittiğini bildir
|
402 |
if (this.wsService.isConnected()) {
|
403 |
console.log('📤 [ConversationManager] Sending audio_ended to backend');
|
404 |
this.wsService.sendControl('audio_ended');
|
405 |
}
|
406 |
|
407 |
+
// Backend'in hazır olmasını bekle
|
408 |
+
console.log('⏳ [ConversationManager] Waiting for backend to be ready...');
|
409 |
|
410 |
+
// İlk olarak biraz bekle (network gecikmesi için)
|
411 |
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
|
413 |
+
// State'in listening olmasını bekle
|
414 |
+
let attempts = 0;
|
415 |
+
while (this.currentStateSubject.value !== 'listening' && attempts < 20) {
|
416 |
+
console.log(`⏳ [ConversationManager] Current state: ${this.currentStateSubject.value}, waiting... (attempt ${attempts + 1})`);
|
417 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
418 |
+
attempts++;
|
419 |
+
}
|
420 |
|
421 |
+
if (this.currentStateSubject.value === 'listening') {
|
422 |
+
console.log('✅ [ConversationManager] State is listening, starting audio recording...');
|
423 |
+
|
424 |
+
// Biraz daha bekle ki backend tamamen hazır olsun
|
425 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
426 |
|
427 |
if (!this.audioService.isRecording()) {
|
428 |
await this.audioService.startRecording();
|
|
|
431 |
console.warn('⚠️ [ConversationManager] Audio already recording, skipping');
|
432 |
}
|
433 |
} else {
|
434 |
+
console.error('❌ [ConversationManager] State is not listening after timeout');
|
435 |
+
this.addSystemMessage('Speech recognition initialization failed. Please try again.');
|
436 |
}
|
437 |
|
438 |
} catch (error) {
|