feat: Ajout d'un support spécifique pour Chromium dans le service TTS
This commit is contained in:
@@ -7,6 +7,7 @@ class TextToSpeechService {
|
||||
static bool _isInitialized = false;
|
||||
static bool _voicesLoaded = false;
|
||||
static List<web.SpeechSynthesisVoice> _cachedVoices = [];
|
||||
static bool _isChromium = false;
|
||||
|
||||
/// Initialiser le service TTS
|
||||
static Future<void> initialize() async {
|
||||
@@ -15,8 +16,28 @@ class TextToSpeechService {
|
||||
try {
|
||||
_isInitialized = true;
|
||||
|
||||
// Détecter si on est sur Chromium
|
||||
final userAgent = web.window.navigator.userAgent.toLowerCase();
|
||||
_isChromium = userAgent.contains('chrome') && !userAgent.contains('edg');
|
||||
|
||||
if (_isChromium) {
|
||||
DebugLog.info('[TextToSpeechService] Chromium detected - applying workarounds');
|
||||
}
|
||||
|
||||
final synthesis = web.window.speechSynthesis;
|
||||
|
||||
// WORKAROUND CHROMIUM: Forcer le chargement des voix avec un speak/cancel
|
||||
if (_isChromium) {
|
||||
try {
|
||||
final dummy = web.SpeechSynthesisUtterance('');
|
||||
synthesis.speak(dummy);
|
||||
synthesis.cancel();
|
||||
DebugLog.info('[TextToSpeechService] Chromium voice loading triggered');
|
||||
} catch (e) {
|
||||
DebugLog.warning('[TextToSpeechService] Chromium workaround failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Essayer de charger les voix immédiatement
|
||||
_cachedVoices = synthesis.getVoices().toDart;
|
||||
|
||||
@@ -210,6 +231,14 @@ class TextToSpeechService {
|
||||
// Lire le texte
|
||||
synthesis.speak(utterance);
|
||||
DebugLog.info('[TextToSpeechService] Speech command sent');
|
||||
|
||||
// WORKAROUND CHROMIUM: Appeler resume() immédiatement après speak()
|
||||
// Ceci est nécessaire sur Chromium/Linux pour que le TTS démarre réellement
|
||||
if (_isChromium) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
synthesis.resume();
|
||||
DebugLog.info('[TextToSpeechService] Chromium resume() called');
|
||||
}
|
||||
} catch (e) {
|
||||
DebugLog.error('[TextToSpeechService] Erreur lors de la lecture', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user