Skip to content
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

Closed
sowens-csd opened this issue Jul 18, 2021 · 17 comments
Closed

Speech recognition API JavaScript binding problem on Chrome #86621

sowens-csd opened this issue Jul 18, 2021 · 17 comments
Labels
blocked Issue is blocked by another issue c: regression It was better in the past than it is now dependency: dart Dart team may need to help us found in release: 2.2 Found to occur in 2.2 found in release: 2.4 Found to occur in 2.4 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically team-web Owned by Web platform team

Comments

@sowens-csd
Copy link

sowens-csd commented Jul 18, 2021

Steps to Reproduce

  1. Run flutter create bug.
  2. Replace main.dart with this content
minimal code sample
import '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!;
          });
        }
      }
    }
  }
}
  1. Run the app on Chrome, make sure you have a microphone on your laptop / headset / etc. (I was using Chrome Version 91.0.4472.114 (Official Build) (x86_64) on Big Sur 11.4)
  2. Click the '+' button in the sample app
  3. Accept the Chrome browser request to allow the microphone to be used
  4. Say something into your microphone
  5. The app will crash

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:

Exception has occurred.
JSNoSuchMethodError (NoSuchMethodError: tried to call a non-function, such as null: 'recognitionResult[$item]')

That's at line 92-93:

html.SpeechRecognitionAlternative alt =
            recognitionResult.item(altIndex);

I also tried debugging in Chrome developer tools. Everything looks right, the SpeechRecognitionResult does have item as one of its methods. In JS in the console in the debugger I can do result.item(0) and see the expected SpeechRecognitionAlternative value that shows the words that were recognized. Similarly result("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
[  +81 ms] executing: sysctl hw.optional.arm64
[  +17 ms] Exit code 1 from: sysctl hw.optional.arm64
[        ] sysctl: unknown oid 'hw.optional.arm64'
[   +7 ms] executing: [/Users/stephen.owens/Documents/dev/flutter/sdk/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +19 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] d79295af24c3ed621c33713ecda14ad196fd9c31
[        ] executing: [/Users/stephen.owens/Documents/dev/flutter/sdk/flutter/] git tag --points-at d79295af24c3ed621c33713ecda14ad196fd9c31
[  +23 ms] Exit code 0 from: git tag --points-at d79295af24c3ed621c33713ecda14ad196fd9c31
[        ] 2.2.2
[   +6 ms] executing: [/Users/stephen.owens/Documents/dev/flutter/sdk/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +12 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/Users/stephen.owens/Documents/dev/flutter/sdk/flutter/] git ls-remote --get-url origin
[  +12 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +90 ms] executing: [/Users/stephen.owens/Documents/dev/flutter/sdk/flutter/] git rev-parse --abbrev-ref HEAD
[  +13 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[   +5 ms] executing: sw_vers -productName
[  +16 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +12 ms] Exit code 0 from: sw_vers -productVersion
[        ] 11.4
[        ] executing: sw_vers -buildVersion
[  +13 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 20F71
[  +60 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +42 ms] executing: /Users/stephen.owens/Library/Android/sdk/platform-tools/adb devices -l
[  +11 ms] executing: sysctl hw.optional.arm64
[   +4 ms] Exit code 1 from: sysctl hw.optional.arm64
[        ] sysctl: unknown oid 'hw.optional.arm64'
[        ] executing: xcrun xcodebuild -version
[ +109 ms] Exit code 0 from: xcrun xcodebuild -version
[   +1 ms] Xcode 12.5.1
           Build version 12E507
[   +3 ms] executing: xcrun xcdevice list --timeout 2
[   +3 ms] xcrun simctl list --json devices
[        ] executing: xcrun simctl list --json devices
[  +43 ms] List of devices attached
[ +181 ms] {
             "devices" : {
             }
           }
[+2380 ms] [
           ]
[   +7 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +69 ms] Skipping pub get: version match.
[  +95 ms] Generating /Users/stephen.owens/Documents/dev/csd/csd-flutter-plugins/stt_sample/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[ +204 ms] Launching lib/main.dart on Chrome in debug mode...
[  +95 ms] Updating assets
[  +58 ms] Waiting for connection from debug service on Chrome...
[  +67 ms] <- reset
[   +6 ms] /Users/stephen.owens/Documents/dev/flutter/sdk/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /Users/stephen.owens/Documents/dev/flutter/sdk/flutter/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root /Users/stephen.owens/Documents/dev/flutter/sdk/flutter/bin/cache/flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true --output-dill /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/flutter_tools.2jGAbA/flutter_tool.UMPn1U/app.dill --libraries-spec file:///Users/stephen.owens/Documents/dev/flutter/sdk/flutter/bin/cache/flutter_web_sdk/libraries.json --packages /Users/stephen.owens/Documents/dev/csd/csd-flutter-plugins/stt_sample/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-root /var/folders/z9/n2qxppwx25ldw1xmstdf_lh00000gq/T/flutter_tools.2jGAbA/flutter_tools.hbaNCC --filesystem-scheme org-dartlang-app --initialize-from-dill build/b1b715402d823b7fd5c2b68d2edcb2ce.cache.dill.track.dill --platform file:///Users/stephen.owens/Documents/dev/flutter/sdk/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill --sound-null-safety
[   +7 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+13443 ms] Waiting for connection from debug service on Chrome... (completed in 13.5s)
[        ] Synced 28.3MB.
[        ] <- accept
[        ] Caching compiled dill
[  +75 ms] Using Google Chrome 91.0.4472.164 

[+1228 ms] [CHROME]:
[   +1 ms] [CHROME]:DevTools listening on ws://127.0.0.1:52709/devtools/browser/3a492468-4290-4b26-abab-40a633f43716
[ +877 ms] DwdsInjector: Received request for entrypoint at http://localhost:52688/main_module.bootstrap.js
[   +6 ms] MetadataProvider: Loading debug metadata...
[  +13 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[   +6 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:52688/main_module.bootstrap.js
[+1164 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[  +57 ms] DevHandler: Debug service listening on ws://127.0.0.1:52727/VkSzb2nNtGs=/ws

[  +20 ms] This app is linked to the debug service: ws://127.0.0.1:52727/VkSzb2nNtGs=/ws
[   +6 ms] Debug service listening on ws://127.0.0.1:52727/VkSzb2nNtGs=/ws
[        ] 💪 Running with sound null safety 💪
[   +2 ms] 🔥  To hot restart changes while running, press "r" or "R".
[        ] For a more detailed help message, press "h". To quit, press "q".
[+32635 ms] TypeError: recognitionResult[$item] is not a function
                at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
                at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
                at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
                at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
                at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[+1092 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[ +710 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[ +595 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[ +608 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[ +105 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[+1085 ms] TypeError: recognitionResult[$item] is not a function
               at main._MyHomePageState.new.[_onResult] (http://localhost:52688/packages/stt_sample/main.dart.lib.js:500:45)
               at http://localhost:52688/packages/stt_sample/main.dart.lib.js:478:88
               at Object._checkAndCall (http://localhost:52688/dart_sdk.js:5246:16)
               at Object.dcall (http://localhost:52688/dart_sdk.js:5251:17)
               at SpeechRecognition.<anonymous> (http://localhost:52688/dart_sdk.js:100646:100)
[+10432 ms] DevHandler: Stopped debug service on ws://127.0.0.1:52725

[ +993 ms] Application finished.
[   +5 ms] "flutter run" took 68,608ms.
[ +131 ms] ensureAnalyticsSent: 129ms
[   +1 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 0
flutter analyze
Analyzing stt_sample...                                                 

   info • Avoid using web-only libraries outside Flutter web plugin packages • lib/main.dart:2:1 •
          avoid_web_libraries_in_flutter

1 issue found. (ran in 2.9s)

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.

[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-CA)
    • Flutter version 2.2.2 at /Users/stephen.owens/Documents/dev/flutter/sdk/flutter
    • Framework revision d79295af24 (5 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/stephen.owens/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/stephen.owens/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] 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 /Applications/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)

[✓] IntelliJ IDEA Community Edition (version 2017.2.5)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] 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)
    • Chrome (web)                       • chrome                               • web-javascript • Google Chrome 91.0.4472.164

! Doctor found issues in 1 category.
@TahaTesser TahaTesser added the in triage Presently being triaged by the triage team label Jul 19, 2021
@TahaTesser
Copy link
Member

Hi @sowens-csd
Thanks for filing the issue, I can reproduce the issue on multiple platforms using Edge and Chrome.

Used the following minimal code sample

minimal code sample
import '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!;
          });
        }
      }
    }
  }
}

Logs

logs
[        ]     |     },
[        ]     |     {
[        ]     |       "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)
stable master

Check flutter doctor -v outputs for each channel below

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?

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 19, 2021
@sowens-csd
Copy link
Author

sowens-csd commented Jul 19, 2021

I just tested and was able to get It to work in 2.0.6 and not in 2.2.0. HTHs

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 19, 2021
@TahaTesser
Copy link
Member

Hi @sowens-csd
Thank you so much, I can confirm 2.0.6 works and text is updated with speech

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!

@TahaTesser TahaTesser added dependency: dart Dart team may need to help us found in release: 2.2 Found to occur in 2.2 found in release: 2.4 Found to occur in 2.4 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically c: regression It was better in the past than it is now and removed in triage Presently being triaged by the triage team labels Jul 20, 2021
@sowens-csd
Copy link
Author

Are there any updates on this?

@sowens-csd
Copy link
Author

I can still reproduce this on Flutter 2.5.0.

@TahaTesser
Copy link
Member

TahaTesser commented Sep 21, 2021

I have bisected the commit that introduced bug in Flutter from March 10th, 2021, bug was introduced in a dart roll into engine, which was then rolled into Flutter

good bad
047dcc7 a0c70d8

@ajfrankman
Copy link

ajfrankman commented Oct 19, 2021

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?

@Terranic
Copy link

Terranic commented Nov 1, 2021

I can also confirm running into that problem with Flutter 2.5.3 and Chrome - Android emulation works fine

Running with sound null safety 
Debug service listening on ws://127.0.0.1:61980/DZKgesn4nCI=/ws
TypeError: recognitionResult[$item] is not a function at speech_to_text_web.SpeechToTextPlugin.new.[_onResult] (http://localhost:61938/packages/speech_to_text/speech_to_text_web.dart.lib.js:173:45)
    at http://localhost:61938/packages/speech_to_text/speech_to_text_web.dart.lib.js:108:98
    at Object._checkAndCall (http://localhost:61938/dart_sdk.js:5268:16)
    at Object.dcall (http://localhost:61938/dart_sdk.js:5273:17)
    at SpeechRecognition.<anonymous> (http://localhost:61938/dart_sdk.js:101824:100)

which can be found here:

 void _onResult(html.SpeechRecognitionEvent event) {
    var isFinal = false;
    var recogResults = <SpeechRecognitionWords>[];
    var results = event.results;
    if (null == results) return;
    for (var recognitionResult in results) {
      if (null == recognitionResult.length || recognitionResult.length == 0) {
        continue;
      }
      for (var altIndex = 0; altIndex < recognitionResult.length!; ++altIndex) {
        var alt = recognitionResult.item(altIndex);                  <-- Exception here
        if (null != alt.transcript && null != alt.confidence) {
          recogResults.add(SpeechRecognitionWords(
              alt.transcript!, alt.confidence!.toDouble()));
        }
      }
    }
    var result = SpeechRecognitionResult(recogResults, isFinal);
    onTextRecognition?.call(jsonEncode(result.toJson()));
    _resultSent = true;
  }

@sowens-csd
Copy link
Author

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?

@TahaTesser
Copy link
Member

TahaTesser commented Nov 25, 2021

This needs a fix from Dart SDK, filed an issue dart-lang/sdk#47779
it can be reproduced just using dart html in a dart based web app (without Fluttter)

@TahaTesser TahaTesser removed this from To do in Nevercode Nov 25, 2021
@TahaTesser
Copy link
Member

TahaTesser commented Dec 5, 2021

Hi everyone

There is now a workaround, shared by dart-lang/sdk#47779 (comment)

Try this code sample below

workaround minimal code sample
import '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!;
          });
        }
      }
    }
  }
}

@sowens-csd
Copy link
Author

Pretty excited about this possible work around, thanks!

I just tried it on Flutter 2.5.3 and I'm getting:

"Error: Expected a value of type 'SpeechRecognitionAlternative', but got one of type 'JavaScriptObject'
The error is from this line:

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?

@TahaTesser
Copy link
Member

@sowens-csd
I've tested it on the master channel

Screen.Recording.2021-12-05.at.17.14.20.mov

@sowens-csd
Copy link
Author

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!;
  });
}

@annagrin
Copy link
Contributor

[dart rotation] labeling as blocked by dart issue dart-lang/sdk#47779

@annagrin annagrin added the blocked Issue is blocked by another issue label Jan 27, 2022
@flutter-triage-bot flutter-triage-bot bot added the team-web Owned by Web platform team label Jul 8, 2023
@yjbanov
Copy link
Contributor

yjbanov commented Jul 20, 2023

Deduplicating into the Dart SDK issue.

@yjbanov yjbanov closed this as completed Jul 20, 2023
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

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 flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked Issue is blocked by another issue c: regression It was better in the past than it is now dependency: dart Dart team may need to help us found in release: 2.2 Found to occur in 2.2 found in release: 2.4 Found to occur in 2.4 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically team-web Owned by Web platform team
Projects
None yet
Development

No branches or pull requests

7 participants