Skip to content

Commit

Permalink
feat: listenOptions added along with support for
Browse files Browse the repository at this point in the history
haptics and auto punctuation on iOS
  • Loading branch information
sowens-csd committed Jan 25, 2024
1 parent ddd1ec8 commit 874e22f
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 140 deletions.
48 changes: 28 additions & 20 deletions examples/audio_player_interaction/pubspec.lock
Expand Up @@ -53,10 +53,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -140,26 +140,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -249,17 +249,17 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
speech_to_text:
dependency: "direct main"
description:
path: "../../speech_to_text"
relative: true
source: path
version: "6.1.1"
version: "6.6.0"
speech_to_text_macos:
dependency: transitive
description:
Expand All @@ -272,26 +272,26 @@ packages:
dependency: transitive
description:
name: speech_to_text_platform_interface
sha256: "13d90215a7554b9a8c1ce47c0a1739af8eacd2cf196ca66351e54dfd2172746d"
sha256: a0df1a907091ea09880077dc25aae02af9f79811264e6e97ddb08639b7f771c2
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.2.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -312,10 +312,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand All @@ -340,6 +340,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
win32:
dependency: transitive
description:
Expand All @@ -357,5 +365,5 @@ packages:
source: hosted
version: "0.2.0"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.10.0"
7 changes: 7 additions & 0 deletions speech_to_text/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog

## 6.6.0-dev

### New
* `listen` now has a new `SpeechListenOptions listenOptions` parameter to specify the recognizer
options for the listen session. Some of the separate parameters have been deprecated as a
result. See the `listen` method for documentation.

## 6.5.1

### Fix
Expand Down
8 changes: 4 additions & 4 deletions speech_to_text/README.md
@@ -1,6 +1,6 @@
# speech_to_text

[![pub package](https://img.shields.io/badge/pub-v6.5.1-blue)](https://pub.dartlang.org/packages/speech_to_text) [![build status](https://github.com/csdcorp/speech_to_text/workflows/Test/badge.svg)](https://github.com/csdcorp/speech_to_text/actions?query=workflow%3ATest) [![codecov](https://codecov.io/gh/csdcorp/speech_to_text/branch/main/graph/badge.svg?token=4LV3HESMS4)](undefined)
[![pub package](https://img.shields.io/badge/pub-v6.6.0-blue)](https://pub.dartlang.org/packages/speech_to_text) [![build status](https://github.com/csdcorp/speech_to_text/workflows/Test/badge.svg)](https://github.com/csdcorp/speech_to_text/actions?query=workflow%3ATest) [![codecov](https://codecov.io/gh/csdcorp/speech_to_text/branch/main/graph/badge.svg?token=4LV3HESMS4)](undefined)

A library that exposes device specific speech recognition capability.

Expand All @@ -24,10 +24,10 @@ _speech: means most speech recognition features work. Platforms with build but n

## Recent Updates

6.5.0 New `initialize` option to improve support for some mobile browsers, `SpeechToText.webDoNotAggregate`. Test the browser user agent to see if it should be used.
6.6.0 `listen` now uses 'SpeechListenOptions' to specify the options for the current listen session, including new
options for controlling haptics and punctuation during recognition on iOS.

6.4.0 Better support for newer Android devices, now returns the list of supported languages for
on device speech recognition.
6.5.0 New `initialize` option to improve support for some mobile browsers, `SpeechToText.webDoNotAggregate`. Test the browser user agent to see if it should be used.

*Note*: Feedback from any test devices is welcome.

Expand Down
12 changes: 8 additions & 4 deletions speech_to_text/example/lib/main.dart
Expand Up @@ -123,6 +123,13 @@ class _SpeechSampleAppState extends State<SpeechSampleApp> {
lastError = '';
final pauseFor = int.tryParse(_pauseForController.text);
final listenFor = int.tryParse(_listenForController.text);
final options = SpeechListenOptions(
onDevice: _onDevice,
listenMode: ListenMode.confirmation,
cancelOnError: true,
partialResults: true,
autoPunctuation: true,
enableHapticFeedback: true);
// Note that `listenFor` is the maximum, not the minimum, on some
// systems recognition will be stopped before this value is reached.
// Similarly `pauseFor` is a maximum not a minimum and may be ignored
Expand All @@ -131,12 +138,9 @@ class _SpeechSampleAppState extends State<SpeechSampleApp> {
onResult: resultListener,
listenFor: Duration(seconds: listenFor ?? 30),
pauseFor: Duration(seconds: pauseFor ?? 3),
partialResults: true,
localeId: _currentLocaleId,
onSoundLevelChange: soundLevelListener,
cancelOnError: true,
listenMode: ListenMode.confirmation,
onDevice: _onDevice,
listenOptions: options,
);
setState(() {});
}
Expand Down
22 changes: 11 additions & 11 deletions speech_to_text/example/pubspec.lock
Expand Up @@ -58,10 +58,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: ad76540d21c066228ee3f9d1dad64a9f7e46530e8bb7c85011a88bc1fd874bc5
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.0.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -148,18 +148,18 @@ packages:
dependency: transitive
description:
name: plugin_platform_interface
sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.6"
version: "2.1.8"
provider:
dependency: "direct main"
description:
name: provider
sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
url: "https://pub.dev"
source: hosted
version: "6.0.5"
version: "6.1.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -179,23 +179,23 @@ packages:
path: ".."
relative: true
source: path
version: "6.4.1"
version: "6.6.0"
speech_to_text_macos:
dependency: transitive
description:
name: speech_to_text_macos
sha256: "6b5575e5a8346be1779838b0a482c259474965b5943668830b479147a75b5bfc"
sha256: e685750f7542fcaa087a5396ee471e727ec648bf681f4da83c84d086322173f6
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.1.0"
speech_to_text_platform_interface:
dependency: transitive
description:
name: speech_to_text_platform_interface
sha256: "2ef9c0abf3b4340998fcb489afc4fc8cd7574eff21d912673be59b60ff16850c"
sha256: a0df1a907091ea09880077dc25aae02af9f79811264e6e97ddb08639b7f771c2
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.2.0"
stack_trace:
dependency: transitive
description:
Expand Down
21 changes: 16 additions & 5 deletions speech_to_text/ios/Classes/SwiftSpeechToTextPlugin.swift
Expand Up @@ -111,11 +111,16 @@ public class SwiftSpeechToTextPlugin: NSObject, FlutterPlugin {
initialize( result )
case SwiftSpeechToTextMethods.listen.rawValue:
guard let argsArr = call.arguments as? Dictionary<String,AnyObject>,
let partialResults = argsArr["partialResults"] as? Bool, let onDevice = argsArr["onDevice"] as? Bool, let listenModeIndex = argsArr["listenMode"] as? Int, let sampleRate = argsArr["sampleRate"] as? Int
let partialResults = argsArr["partialResults"] as? Bool,
let onDevice = argsArr["onDevice"] as? Bool,
let listenModeIndex = argsArr["listenMode"] as? Int,
let sampleRate = argsArr["sampleRate"] as? Int,
let autoPunctuation = argsArr["autoPunctuation"] as? Bool,
let enableHaptics = argsArr["enableHaptics"] as? Bool
else {
DispatchQueue.main.async {
result(FlutterError( code: SpeechToTextErrors.missingOrInvalidArg.rawValue,
message:"Missing arg partialResults, onDevice, listenMode, and sampleRate are required",
message:"Missing arg partialResults, onDevice, listenMode, autoPunctuatio, enableHaptics and sampleRate are required",
details: nil ))
}
return
Expand All @@ -133,7 +138,7 @@ public class SwiftSpeechToTextPlugin: NSObject, FlutterPlugin {
return
}

listenForSpeech( result, localeStr: localeStr, partialResults: partialResults, onDevice: onDevice, listenMode: listenMode, sampleRate: sampleRate )
listenForSpeech( result, localeStr: localeStr, partialResults: partialResults, onDevice: onDevice, listenMode: listenMode, sampleRate: sampleRate, autoPunctuation: autoPunctuation, enableHaptics: enableHaptics )
case SwiftSpeechToTextMethods.stop.rawValue:
stopSpeech( result )
case SwiftSpeechToTextMethods.cancel.rawValue:
Expand Down Expand Up @@ -348,7 +353,8 @@ public class SwiftSpeechToTextPlugin: NSObject, FlutterPlugin {
stopping = false
}

private func listenForSpeech( _ result: @escaping FlutterResult, localeStr: String?, partialResults: Bool, onDevice: Bool, listenMode: ListenMode, sampleRate: Int ) {
private func listenForSpeech( _ result: @escaping FlutterResult, localeStr: String?, partialResults: Bool,
onDevice: Bool, listenMode: ListenMode, sampleRate: Int, autoPunctuation: Bool, enableHaptics: Bool ) {
if ( nil != currentTask || listening ) {
sendBoolResult( false, result );
return
Expand Down Expand Up @@ -381,6 +387,9 @@ public class SwiftSpeechToTextPlugin: NSObject, FlutterPlugin {
}
try self.audioSession.setMode(AVAudioSession.Mode.default)
try self.audioSession.setActive(true, options: .notifyOthersOnDeactivation)
if #available(iOS 13.0, *) {
try self.audioSession.setAllowHapticsAndSystemSoundsDuringRecording(enableHaptics)
}
if let sound = listeningSound {
self.onPlayEnd = {()->Void in
if ( !self.failedListen ) {
Expand Down Expand Up @@ -417,7 +426,9 @@ public class SwiftSpeechToTextPlugin: NSObject, FlutterPlugin {
default:
break
}

if #available(iOS 16.0, *) {
currentRequest.addsPunctuation = autoPunctuation
}
self.currentTask = self.recognizer?.recognitionTask(with: currentRequest, delegate: self )
let recordingFormat = inputNode?.outputFormat(forBus: self.busForNodeTap)
let theSampleRate = audioSession.sampleRate
Expand Down

0 comments on commit 874e22f

Please sign in to comment.