feat(voice-input): handle iOS simulator speech recognition
This commit is contained in:
@@ -65,6 +65,9 @@ class VoiceInputService {
|
|||||||
SttPreference get preference => _preference;
|
SttPreference get preference => _preference;
|
||||||
bool get prefersServerOnly => _preference == SttPreference.serverOnly;
|
bool get prefersServerOnly => _preference == SttPreference.serverOnly;
|
||||||
bool get prefersDeviceOnly => _preference == SttPreference.deviceOnly;
|
bool get prefersDeviceOnly => _preference == SttPreference.deviceOnly;
|
||||||
|
bool get _isIosSimulator =>
|
||||||
|
Platform.isIOS &&
|
||||||
|
Platform.environment.containsKey('SIMULATOR_DEVICE_NAME');
|
||||||
|
|
||||||
VoiceInputService({ApiService? api, Ref? ref}) : _api = api, _ref = ref;
|
VoiceInputService({ApiService? api, Ref? ref}) : _api = api, _ref = ref;
|
||||||
|
|
||||||
@@ -75,13 +78,20 @@ class VoiceInputService {
|
|||||||
Future<bool> initialize() async {
|
Future<bool> initialize() async {
|
||||||
if (_isInitialized) return true;
|
if (_isInitialized) return true;
|
||||||
if (!isSupportedPlatform) return false;
|
if (!isSupportedPlatform) return false;
|
||||||
|
final deviceTag = WidgetsBinding.instance.platformDispatcher.locale
|
||||||
|
.toLanguageTag();
|
||||||
|
|
||||||
|
if (_isIosSimulator) {
|
||||||
|
_localSttAvailable = false;
|
||||||
|
_ensureFallbackLocale(deviceTag);
|
||||||
|
_isInitialized = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Prepare local speech recognizer
|
// Prepare local speech recognizer
|
||||||
try {
|
try {
|
||||||
// Check permission and supported status
|
// Check permission and supported status
|
||||||
_localSttAvailable = await _speech.isSupported();
|
_localSttAvailable = await _speech.isSupported();
|
||||||
if (_localSttAvailable) {
|
if (_localSttAvailable) {
|
||||||
final deviceTag = WidgetsBinding.instance.platformDispatcher.locale
|
|
||||||
.toLanguageTag();
|
|
||||||
await _loadLocales(deviceTag);
|
await _loadLocales(deviceTag);
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user