-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speech recognition API JavaScript binding problem on Chrome #86621
Comments
Hi @sowens-csd Used the following minimal code sample minimal code sampleimport 'package:flutter/material.dart';
import 'dart:html' as html;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
String _recognized = '';
html.SpeechRecognition? _webSpeech;
@override
void initState() {
super.initState();
if (html.SpeechRecognition.supported) {
_webSpeech = html.SpeechRecognition();
}
}
void _incrementCounter() {
_webSpeech?.stop();
_webSpeech?.onResult.listen((speechEvent) => _onResult(speechEvent));
_webSpeech?.interimResults = true;
_webSpeech?.continuous = true;
_webSpeech?.start();
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Text(
'You said: $_recognized',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void _onResult(html.SpeechRecognitionEvent event) {
var results = event.results;
if (null == results) return;
for (html.SpeechRecognitionResult recognitionResult in results) {
if (null == recognitionResult.length || recognitionResult.length == 0) {
continue;
}
for (var altIndex = 0; altIndex < recognitionResult.length!; ++altIndex) {
html.SpeechRecognitionAlternative alt =
recognitionResult.item(altIndex);
if (null != alt.transcript && null != alt.confidence) {
setState(() {
_recognized = alt.transcript!;
});
}
}
}
}
}
Logslogs[ ] | },
[ ] | {
[ ] | "name": "typed_data",
[ ] | "rootUri": "file:///Users/tahatesser/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0",
[ ] | "packageUri": "lib/",
[ ] | "languageVersion": "2.12"
[ ] | },
[ ] | {
[ ] | "name": "vector_math",
[ ] | "rootUri": "file:///Users/tahatesser/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0",
[ ] | "packageUri": "lib/",
[ ] | "languageVersion": "2.12"
[ ] | },
[ ] | {
[ ] | "name": "stable_flutter",
[ ] | "rootUri": "../",
[ ] | "packageUri": "lib/",
[ ] | "languageVersion": "2.12"
[ ] | }
[ ] | ],
[ ] | "generated": "2021-07-19T15:37:57.892693Z",
[ ] | "generator": "pub",
[ ] | "generatorVersion": "2.14.0-321.0.dev"
[ ] | }
[ +86 ms] Running "flutter pub get" in stable_flutter... (completed in 1,755ms)
[ +172 ms] Generating
/Users/tahatesser/StudioProjects/stable_flutter/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[ +167 ms] Launching lib/main.dart on Chrome in debug mode...
[ +169 ms] Updating assets
[ +120 ms] Waiting for connection from debug service on Chrome...
[ +86 ms] <- reset
[ +9 ms] /Users/tahatesser/Code/flutter_master/bin/cache/dart-sdk/bin/dart --disable-dart-dev
/Users/tahatesser/Code/flutter_master/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root
/Users/tahatesser/Code/flutter_master/bin/cache/flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names
--experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true --output-dill
/var/folders/2c/0n3lcxpn4s14s3t7jcgg5kmh0000gn/T/flutter_tools.paMVPk/flutter_tool.FFAWeN/app.dill --libraries-spec
file:///Users/tahatesser/Code/flutter_master/bin/cache/flutter_web_sdk/libraries.json --packages
/Users/tahatesser/StudioProjects/stable_flutter/.dart_tool/package_config.json -Ddart.vm.profile=false
-Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-root
/var/folders/2c/0n3lcxpn4s14s3t7jcgg5kmh0000gn/T/flutter_tools.paMVPk/flutter_tools.tbEhm4 --filesystem-scheme
org-dartlang-app --initialize-from-dill build/b1b715402d823b7fd5c2b68d2edcb2ce.cache.dill.track.dill --platform
file:///Users/tahatesser/Code/flutter_master/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill --sound-null-safety
[ +11 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+16213 ms] Waiting for connection from debug service on Chrome... (completed in 16.3s)
[ +1 ms] Synced 26.1MB.
[ ] <- accept
[ ] Caching compiled dill
[ +103 ms] Using Google Chrome 91.0.4472.164
[ +86 ms] executing: sysctl hw.optional.arm64
[ +6 ms] Exit code 1 from: sysctl hw.optional.arm64
[ ] sysctl: unknown oid 'hw.optional.arm64'
[ +632 ms] [CHROME]:
[ +1 ms] [CHROME]:DevTools listening on ws://127.0.0.1:54590/devtools/browser/135bb936-6eed-4b87-8123-befa5035f6a4
[+1424 ms] DwdsInjector: Received request for entrypoint at http://localhost:54575/main_module.bootstrap.js
[ +10 ms] MetadataProvider: Loading debug metadata...
[ +29 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[ +8 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:54575/main_module.bootstrap.js
[+1677 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[ +82 ms] DevHandler: Debug service listening on ws://127.0.0.1:54623/hREkLc9mFWs=/ws
[ +29 ms] This app is linked to the debug service: ws://127.0.0.1:54623/hREkLc9mFWs=/ws
[ +12 ms] Debug service listening on ws://127.0.0.1:54623/hREkLc9mFWs=/ws
[ ] 💪 Running with sound null safety 💪
[ +5 ms] 🔥 To hot restart changes while running, press "r" or "R".
[ ] For a more detailed help message, press "h". To quit, press "q".
[ +1 ms] An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:54623/hREkLc9mFWs=
[ +454 ms] DevTools activation throttled until 2021-07-19 22:23:10.775619.
[+5338 ms] The Flutter DevTools debugger and profiler on Chrome is available at:
http://127.0.0.1:9103?uri=http://127.0.0.1:54623/hREkLc9mFWs=
[+4426 ms] TypeError: recognitionResult[$item] is not a function
at main._MyHomePageState.new.[_onResult]
(http://localhost:54575/packages/stable_flutter/main.dart.lib.js:247:45)
at http://localhost:54575/packages/stable_flutter/main.dart.lib.js:225:88
at Object._checkAndCall (http://localhost:54575/dart_sdk.js:5267:16)
at Object.dcall (http://localhost:54575/dart_sdk.js:5272:17)
at SpeechRecognition.<anonymous> (http://localhost:54575/dart_sdk.js:100969:100)
[ +556 ms] TypeError: recognitionResult[$item] is not a function
at main._MyHomePageState.new.[_onResult]
(http://localhost:54575/packages/stable_flutter/main.dart.lib.js:247:45)
at http://localhost:54575/packages/stable_flutter/main.dart.lib.js:225:88
at Object._checkAndCall (http://localhost:54575/dart_sdk.js:5267:16)
at Object.dcall (http://localhost:54575/dart_sdk.js:5272:17)
at SpeechRecognition.<anonymous> (http://localhost:54575/dart_sdk.js:100969:100)
Check flutter doctor -v[✓] Flutter (Channel stable, 2.2.3, on macOS 12.0 21A5284e darwin-x64, locale en-GB)
• Flutter version 2.2.3 at /Users/tahatesser/Code/flutter_stable
• Framework revision f4abaa0735 (3 weeks ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/tahatesser/Code/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/tahatesser/Code/SDK
• Java binary at: /Users/tahatesser/Code/openjdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5.1, Build version 12E507
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] VS Code (version 1.58.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.24.0
[✓] Connected device (4 available)
• Taha’s iPhone (mobile) • 00008020-001059882212002E • ios • iOS
14.6
• iPhone 12 Pro (mobile) • 77C62AB9-8B71-43CF-BCAB-85B0A5B52F85 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS
12.0 21A5284e darwin-x64
• Chrome (web) • chrome • web-javascript • Google
Chrome 91.0.4472.164
! Doctor found issues in 1 category. [✓] Flutter (Channel master, 2.4.0-5.0.pre.87, on macOS 12.0 21A5284e darwin-x64, locale en-GB)
• Flutter version 2.4.0-5.0.pre.87 at /Users/tahatesser/Code/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision e084e9d946 (2 days ago), 2021-07-17 12:00:21 -0700
• Engine revision 14a9e9a50e
• Dart version 2.14.0 (build 2.14.0-321.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/tahatesser/Code/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/tahatesser/Code/SDK
• Java binary at: /Users/tahatesser/Code/openjdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5.1, Build version 12E507
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] VS Code (version 1.58.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.24.0
[✓] Connected device (4 available)
• Taha’s iPhone (mobile) • 00008020-001059882212002E • ios • iOS 14.6
18F72
• iPhone 12 Pro (mobile) • 77C62AB9-8B71-43CF-BCAB-85B0A5B52F85 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.0
21A5284e darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome
91.0.4472.164
! Doctor found issues in 1 category. ✅ : No Issue ❌: Issue reproduced Can you please let me know which version of Fluter it used to work? |
I just tested and was able to get It to work in 2.0.6 and not in 2.2.0. HTHs |
Hi @sowens-csd flutter doctor -v[✓] Flutter (Channel stable, 2.0.6, on macOS 12.0 21A5284e darwin-x64, locale en-GB)
• Flutter version 2.0.6 at /Users/tahatesser/Code/flutter
• Framework revision 1d9032c7e1 (3 months ago), 2021-04-29 17:37:58 -0700
• Engine revision 05e680e202
• Dart version 2.12.3
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/tahatesser/Code/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/tahatesser/Code/SDK
• Java binary at: /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5.1, Build version 12E507
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.2)
• Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
[✓] VS Code (version 1.58.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.24.0
[✓] Connected device (3 available)
• Taha’s iPhone (mobile) • 00008020-001059882212002E • ios • iOS 14.6
• macOS (desktop) • macos • darwin-x64 • macOS 12.0 21A5284e darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.164
• No issues found! |
Are there any updates on this? |
I can still reproduce this on Flutter 2.5.0. |
I'm working on a school project, and I am trying to get the speech-to-text (https://pub.dev/packages/speech_to_text) working for dart. It seems like if I could find a way to roll back to older engine for now it would work? Is that correct? Could someone point me in the right direction on how to do that? |
I can also confirm running into that problem with Flutter 2.5.3 and Chrome - Android emulation works fine
which can be found here:
|
Any update on this issue? Seems like @TahaTesser did a bunch of good work to make this easy to find and fix. Hopefully that means a fix is already in some upcoming branch? |
This needs a fix from Dart SDK, filed an issue dart-lang/sdk#47779 |
Hi everyone There is now a workaround, shared by dart-lang/sdk#47779 (comment) Try this code sample below workaround minimal code sampleimport 'package:flutter/material.dart';
import 'dart:html' as html;
import 'dart:js_util' as js_util;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
String _recognized = '';
html.SpeechRecognition? _webSpeech;
@override
void initState() {
super.initState();
if (html.SpeechRecognition.supported) {
_webSpeech = html.SpeechRecognition();
}
}
void _incrementCounter() {
_webSpeech?.stop();
_webSpeech?.onResult.listen((speechEvent) => _onResult(speechEvent));
_webSpeech?.interimResults = true;
_webSpeech?.continuous = true;
_webSpeech?.start();
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Text(
'You said: $_recognized',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void _onResult(html.SpeechRecognitionEvent event) {
var results = event.results;
if (null == results) return;
for (html.SpeechRecognitionResult recognitionResult in results) {
if (null == recognitionResult.length || recognitionResult.length == 0) {
continue;
}
for (var altIndex = 0; altIndex < recognitionResult.length!; ++altIndex) {
html.SpeechRecognitionAlternative alt =
js_util.callMethod(recognitionResult, 'item', [altIndex]);
if (null != alt.transcript && null != alt.confidence) {
setState(() {
_recognized = alt.transcript!;
});
}
}
}
}
}
|
Pretty excited about this possible work around, thanks! I just tried it on Flutter 2.5.3 and I'm getting:
html.SpeechRecognitionAlternative alt =
js_util.callMethod(recognitionResult, 'item', [altIndex]); I tried it both in my own code and using the exact minimal example copied from above. Is it a version problem or something else? |
@sowens-csd Screen.Recording.2021-12-05.at.17.14.20.mov |
Confirmed, it works on master although not on stable. This slight variant seems to be working on stable: var alt = js_util.callMethod(recognitionResult, 'item', [altIndex]);
if (null == alt) continue;
String? transcript = js_util.getProperty(alt, 'transcript');
num? confidence = js_util.getProperty(alt, 'confidence');
if (null != transcript && null != confidence) {
setState(() {
_recognized = alt.transcript!;
});
} |
[dart rotation] labeling as blocked by dart issue dart-lang/sdk#47779 |
Deduplicating into the Dart SDK issue. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
flutter create bug
.minimal code sample
Expected results:
The words you spoke should appear on screen when they are recognized by the Chrome speech recognition API.
Actual results:
An exception was caught in the IDE:
That's at line 92-93:
I also tried debugging in Chrome developer tools. Everything looks right, the
SpeechRecognitionResult
does haveitem
as one of its methods. In JS in the console in the debugger I can doresult.item(0)
and see the expectedSpeechRecognitionAlternative
value that shows the words that were recognized. Similarlyresult("item")
works fine. It seems like there's something wrong with the definition of$item
but I looked at it and it seems to match the definitions for other speech API functions used in the same file, like$onResult
for example.This was working in previous versions of Flutter.
Logs
I understand that advice, but I'm only doing this to create a small example to share. My actual use case is for a plugin.
I've also tried it in 2.2.3 with the same result.
The text was updated successfully, but these errors were encountered: