From 29f87a437bf4a22a6ad61e34b8e803aedf488bb4 Mon Sep 17 00:00:00 2001 From: sowens-csd Date: Wed, 14 Aug 2024 11:43:19 -0400 Subject: [PATCH] feat: switchover to listenOptions --- speech_to_text/android/.project | 11 +++++++++++ .../.settings/org.eclipse.buildship.core.prefs | 6 +++--- speech_to_text/example/android/.project | 11 +++++++++++ .../.settings/org.eclipse.buildship.core.prefs | 11 +++++++++++ speech_to_text/example/lib/main.dart | 2 +- speech_to_text/example/lib/provider_example.dart | 2 +- speech_to_text/example/lib/stress.dart | 6 +++--- speech_to_text/lib/speech_to_text.dart | 15 +++++++++------ speech_to_text/lib/speech_to_text_provider.dart | 15 +++++++-------- speech_to_text/test/balanced_alternates_test.dart | 1 - speech_to_text/test/speech_to_text_test.dart | 12 ++++++++---- 11 files changed, 65 insertions(+), 27 deletions(-) diff --git a/speech_to_text/android/.project b/speech_to_text/android/.project index 3050653c..97bcf1c9 100644 --- a/speech_to_text/android/.project +++ b/speech_to_text/android/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.buildship.core.gradleprojectnature + + + 1723647412412 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/speech_to_text/android/.settings/org.eclipse.buildship.core.prefs b/speech_to_text/android/.settings/org.eclipse.buildship.core.prefs index 7a23d112..09428860 100644 --- a/speech_to_text/android/.settings/org.eclipse.buildship.core.prefs +++ b/speech_to_text/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments= +arguments=--init-script /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle auto.sync=false build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.6.1)) +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home= +java.home=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/speech_to_text/example/android/.project b/speech_to_text/example/android/.project index d7d48141..51b63897 100644 --- a/speech_to_text/example/android/.project +++ b/speech_to_text/example/android/.project @@ -14,4 +14,15 @@ org.eclipse.buildship.core.gradleprojectnature + + + 1723647412410 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/speech_to_text/example/android/.settings/org.eclipse.buildship.core.prefs b/speech_to_text/example/android/.settings/org.eclipse.buildship.core.prefs index e8895216..09428860 100644 --- a/speech_to_text/example/android/.settings/org.eclipse.buildship.core.prefs +++ b/speech_to_text/example/android/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments=--init-script /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/speech_to_text/example/lib/main.dart b/speech_to_text/example/lib/main.dart index 97954c4d..2cdec733 100644 --- a/speech_to_text/example/lib/main.dart +++ b/speech_to_text/example/lib/main.dart @@ -490,7 +490,7 @@ class SpeechStatusWidget extends StatelessWidget { Widget build(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(vertical: 20), - color: Theme.of(context).colorScheme.background, + color: Theme.of(context).colorScheme.surface, child: Center( child: speech.isListening ? const Text( diff --git a/speech_to_text/example/lib/provider_example.dart b/speech_to_text/example/lib/provider_example.dart index bf792675..5144b8a9 100644 --- a/speech_to_text/example/lib/provider_example.dart +++ b/speech_to_text/example/lib/provider_example.dart @@ -151,7 +151,7 @@ class SpeechProviderExampleWidgetState ), Container( padding: const EdgeInsets.symmetric(vertical: 20), - color: Theme.of(context).colorScheme.background, + color: Theme.of(context).colorScheme.surface, child: Center( child: speechProvider.isListening ? const Text( diff --git a/speech_to_text/example/lib/stress.dart b/speech_to_text/example/lib/stress.dart index 77313f6f..d54fee2f 100644 --- a/speech_to_text/example/lib/stress.dart +++ b/speech_to_text/example/lib/stress.dart @@ -185,7 +185,7 @@ class _MyAppState extends State { ), Container( padding: const EdgeInsets.symmetric(vertical: 20), - color: Theme.of(context).colorScheme.background, + color: Theme.of(context).colorScheme.surface, child: Center( child: speech.isListening ? const Text( @@ -239,8 +239,8 @@ class _MyAppState extends State { listenFor: const Duration(seconds: 10), localeId: _currentLocaleId, onSoundLevelChange: soundLevelListener, - cancelOnError: true, - partialResults: true); + listenOptions: + SpeechListenOptions(cancelOnError: true, partialResults: true)); setState(() {}); } diff --git a/speech_to_text/lib/speech_to_text.dart b/speech_to_text/lib/speech_to_text.dart index cabde7d2..24cf9301 100644 --- a/speech_to_text/lib/speech_to_text.dart +++ b/speech_to_text/lib/speech_to_text.dart @@ -448,7 +448,7 @@ class SpeechToText { _lastRecognized = ''; _userEnded = false; _lastSpeechResult = null; - _cancelOnError = cancelOnError; + _cancelOnError = listenOptions?.cancelOnError ?? cancelOnError; _recognized = false; _notifiedFinal = false; _notifiedDone = false; @@ -457,14 +457,17 @@ class SpeechToText { _partialResults = partialResults; _notifyFinalTimer?.cancel(); _notifyFinalTimer = null; - try { - var started = await SpeechToTextPlatform.instance.listen( + final usedOptions = listenOptions ?? + SpeechListenOptions( partialResults: partialResults || null != pauseFor, onDevice: onDevice, - listenMode: listenMode.index, + listenMode: listenMode, sampleRate: sampleRate, - localeId: localeId, - options: listenOptions); + cancelOnError: cancelOnError, + ); + try { + var started = await SpeechToTextPlatform.instance + .listen(localeId: localeId, options: usedOptions); if (started) { _listenStartedAt = clock.now().millisecondsSinceEpoch; _lastSpeechEventAt = _listenStartedAt; diff --git a/speech_to_text/lib/speech_to_text_provider.dart b/speech_to_text/lib/speech_to_text_provider.dart index ec3118cd..0b16d3ca 100644 --- a/speech_to_text/lib/speech_to_text_provider.dart +++ b/speech_to_text/lib/speech_to_text_provider.dart @@ -139,27 +139,26 @@ class SpeechToTextProvider extends ChangeNotifier { ListenMode listenMode = ListenMode.confirmation}) { _lastLevel = 0; _lastResult = null; + final options = SpeechListenOptions( + partialResults: partialResults, + onDevice: onDevice, + cancelOnError: true, + listenMode: listenMode); if (soundLevel) { _speechToText.listen( - partialResults: partialResults, - onDevice: onDevice, listenFor: listenFor, pauseFor: pauseFor, - cancelOnError: true, onResult: _onListenResult, onSoundLevelChange: _onSoundLevelChange, localeId: localeId, - listenMode: listenMode); + listenOptions: options); } else { _speechToText.listen( - partialResults: partialResults, - onDevice: onDevice, listenFor: listenFor, pauseFor: pauseFor, - cancelOnError: true, onResult: _onListenResult, localeId: localeId, - listenMode: listenMode); + listenOptions: options); } } diff --git a/speech_to_text/test/balanced_alternates_test.dart b/speech_to_text/test/balanced_alternates_test.dart index 228ea546..67772d19 100644 --- a/speech_to_text/test/balanced_alternates_test.dart +++ b/speech_to_text/test/balanced_alternates_test.dart @@ -1,7 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:speech_to_text/balanced_alternates.dart'; import 'package:speech_to_text/speech_to_text.dart'; -import 'package:speech_to_text_platform_interface/speech_to_text_platform_interface.dart'; void main() { late BalancedAlternates balancedAlternates; diff --git a/speech_to_text/test/speech_to_text_test.dart b/speech_to_text/test/speech_to_text_test.dart index 5cea3304..90cd92ad 100644 --- a/speech_to_text/test/speech_to_text_test.dart +++ b/speech_to_text/test/speech_to_text_test.dart @@ -481,7 +481,8 @@ void main() { test('stops listening on permanent if cancel explicitly requested', () async { await speech.initialize(onError: listener.onSpeechError); - await speech.listen(cancelOnError: true); + await speech.listen( + listenOptions: SpeechListenOptions(cancelOnError: true)); testPlatform.onStatus!(SpeechToText.listeningStatus); testPlatform.onError!(TestSpeechChannelHandler.permanentErrorJson); expect(speech.isListening, isFalse); @@ -498,7 +499,8 @@ void main() { }); test('Error still sent after implicit cancel', () async { await speech.initialize(onError: listener.onSpeechError); - await speech.listen(cancelOnError: true); + await speech.listen( + listenOptions: SpeechListenOptions(cancelOnError: true)); testPlatform.onError!(TestSpeechChannelHandler.permanentErrorJson); testPlatform.onError!(TestSpeechChannelHandler.permanentErrorJson); expect(speech.isListening, isFalse); @@ -507,10 +509,12 @@ void main() { }); test('Error status cleared on next listen', () async { await speech.initialize(onError: listener.onSpeechError); - await speech.listen(cancelOnError: true); + await speech.listen( + listenOptions: SpeechListenOptions(cancelOnError: true)); testPlatform.onError!(TestSpeechChannelHandler.permanentErrorJson); expect(speech.isListening, isFalse); - await speech.listen(cancelOnError: true); + await speech.listen( + listenOptions: SpeechListenOptions(cancelOnError: true)); await speech.stop(); expect(speech.hasError, isFalse); });