Skip to content

Commit

Permalink
feat: switchover to listenOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sowens-csd committed Aug 14, 2024
1 parent 39979d3 commit 29f87a4
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 27 deletions.
11 changes: 11 additions & 0 deletions speech_to_text/android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1723647412412</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions speech_to_text/example/android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1723647412410</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion speech_to_text/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion speech_to_text/example/lib/provider_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions speech_to_text/example/lib/stress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _MyAppState extends State<MyApp> {
),
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(
Expand Down Expand Up @@ -239,8 +239,8 @@ class _MyAppState extends State<MyApp> {
listenFor: const Duration(seconds: 10),
localeId: _currentLocaleId,
onSoundLevelChange: soundLevelListener,
cancelOnError: true,
partialResults: true);
listenOptions:
SpeechListenOptions(cancelOnError: true, partialResults: true));
setState(() {});
}

Expand Down
15 changes: 9 additions & 6 deletions speech_to_text/lib/speech_to_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class SpeechToText {
_lastRecognized = '';
_userEnded = false;
_lastSpeechResult = null;
_cancelOnError = cancelOnError;
_cancelOnError = listenOptions?.cancelOnError ?? cancelOnError;
_recognized = false;
_notifiedFinal = false;
_notifiedDone = false;
Expand All @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions speech_to_text/lib/speech_to_text_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 0 additions & 1 deletion speech_to_text/test/balanced_alternates_test.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 8 additions & 4 deletions speech_to_text/test/speech_to_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});
Expand Down

0 comments on commit 29f87a4

Please sign in to comment.