bugfix speech-to-text and implement avatar and personal greeting
All checks were successful
Deploy FluentGerman.ai / deploy (push) Successful in 53s
All checks were successful
Deploy FluentGerman.ai / deploy (push) Successful in 53s
This commit is contained in:
@@ -11,10 +11,11 @@ class VoiceManager {
|
||||
this.audioChunks = [];
|
||||
this.onResult = null;
|
||||
this.onStateChange = null;
|
||||
this.browserSTTSupported = false;
|
||||
}
|
||||
|
||||
async init() {
|
||||
// Always init browser STT as fallback
|
||||
// Check browser STT support
|
||||
this._initBrowserSTT();
|
||||
|
||||
// Fetch voice mode from server
|
||||
@@ -23,21 +24,32 @@ class VoiceManager {
|
||||
if (response?.ok) {
|
||||
const config = await response.json();
|
||||
this.mode = config.voice_mode;
|
||||
console.log('[Voice] Mode:', this.mode);
|
||||
console.log('[Voice] Server mode:', this.mode);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[Voice] Could not fetch config, using browser mode');
|
||||
this.mode = 'browser';
|
||||
}
|
||||
|
||||
// Auto-fallback: if server says "browser" but browser doesn't support STT, use API
|
||||
if (this.mode === 'browser' && !this.browserSTTSupported) {
|
||||
console.warn('[Voice] Browser STT not supported, falling back to API mode');
|
||||
this.mode = 'api';
|
||||
showToast('Using cloud voice recognition — your browser doesn\'t support built-in speech recognition.', 'info');
|
||||
}
|
||||
|
||||
console.log('[Voice] Active mode:', this.mode);
|
||||
}
|
||||
|
||||
_initBrowserSTT() {
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
if (!SpeechRecognition) {
|
||||
console.warn('[Voice] Speech recognition not supported in this browser');
|
||||
console.warn('[Voice] SpeechRecognition API not available in this browser');
|
||||
this.browserSTTSupported = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.browserSTTSupported = true;
|
||||
this.recognition = new SpeechRecognition();
|
||||
this.recognition.continuous = false;
|
||||
this.recognition.interimResults = false;
|
||||
@@ -114,10 +126,12 @@ class VoiceManager {
|
||||
showToast('Voice recognition failed to start. Try again.', 'error');
|
||||
}
|
||||
} else {
|
||||
console.warn('[Voice] No speech recognition available');
|
||||
showToast('Speech recognition not supported in this browser', 'error');
|
||||
// Shouldn't happen after init() fallback, but safety net
|
||||
console.warn('[Voice] No speech recognition available, switching to API');
|
||||
this.mode = 'api';
|
||||
this.isRecording = false;
|
||||
if (this.onStateChange) this.onStateChange(false);
|
||||
showToast('Switched to cloud voice recognition. Please try again.', 'info');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +175,7 @@ class VoiceManager {
|
||||
this.lastInputWasVoice = true;
|
||||
if (this.onResult) this.onResult(data.text);
|
||||
} else {
|
||||
showToast('Transcription failed. Falling back to browser voice.', 'error');
|
||||
// Fallback: switch to browser mode for this session
|
||||
this.mode = 'browser';
|
||||
showToast('Transcription failed. Please try again.', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Voice] API transcription error:', e);
|
||||
|
||||
Reference in New Issue
Block a user