feat(tts): ensure Android default TTS engine is set before speaking
This commit is contained in:
@@ -20,6 +20,9 @@
|
|||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.speech.RecognitionService" />
|
<action android:name="android.speech.RecognitionService" />
|
||||||
</intent>
|
</intent>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.TTS_SERVICE" />
|
||||||
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class TextToSpeechService {
|
|||||||
}) async {
|
}) async {
|
||||||
_deviceEngineAvailable = false;
|
_deviceEngineAvailable = false;
|
||||||
try {
|
try {
|
||||||
|
await _ensureAndroidDefaultEngine();
|
||||||
await _tts.awaitSpeakCompletion(false);
|
await _tts.awaitSpeakCompletion(false);
|
||||||
await _tts.setVolume(volume);
|
await _tts.setVolume(volume);
|
||||||
await _tts.setSpeechRate(speechRate);
|
await _tts.setSpeechRate(speechRate);
|
||||||
@@ -108,6 +109,20 @@ class TextToSpeechService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _ensureAndroidDefaultEngine() async {
|
||||||
|
if (kIsWeb || !Platform.isAndroid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final engine = await _tts.getDefaultEngine;
|
||||||
|
if (engine is String && engine.isNotEmpty) {
|
||||||
|
await _tts.setEngine(engine);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_onError?.call(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool _computeAvailability() {
|
bool _computeAvailability() {
|
||||||
final serverAvailable = _api != null;
|
final serverAvailable = _api != null;
|
||||||
switch (_engine) {
|
switch (_engine) {
|
||||||
@@ -808,6 +823,7 @@ class TextToSpeechService {
|
|||||||
|
|
||||||
var configured = false;
|
var configured = false;
|
||||||
try {
|
try {
|
||||||
|
await _ensureAndroidDefaultEngine();
|
||||||
Map<String, dynamic>? defaultVoice;
|
Map<String, dynamic>? defaultVoice;
|
||||||
bool voiceSet = false;
|
bool voiceSet = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user