A flutter plugin to use the speech recognition iOS10+ / Android 4.1+
- Depend on it Add this to your package's pubspec.yaml file:
dependencies: speech_recognition: "^0.3.0"
- Install it You can install packages from the command line:
$ flutter packages get
- Import it Now in your Dart code, you can use:
//.. _speech = SpeechRecognition(); // The flutter app not only call methods on the host platform, // it also needs to receive method calls from host. _speech.setAvailabilityHandler((bool result) => setState(() => _speechRecognitionAvailable = result)); // handle device current locale detection _speech.setCurrentLocaleHandler((String locale) => setState(() => _currentLocale = locale)); _speech.setRecognitionStartedHandler(() => setState(() => _isListening = true)); // this handler will be called during recognition. // the iOS API sends intermediate results, // On my Android device, only the final transcription is received _speech.setRecognitionResultHandler((String text) => setState(() => transcription = text)); _speech.setRecognitionCompleteHandler(() => setState(() => _isListening = false)); // 1st launch : speech recognition permission / initialization _speech .activate() .then((res) => setState(() => _speechRecognitionAvailable = res)); //.. speech.listen(locale:_currentLocale).then((result)=> print('result : $result')); // ... speech.cancel(); // || speech.stop();
infos.plist, add :
- Privacy - Microphone Usage Description
- Privacy - Speech Recognition Usage Description
<key>NSMicrophoneUsageDescription</key> <string>This application needs to access your microphone</string> <key>NSSpeechRecognitionUsageDescription</key> <string>This application needs the speech recognition permission</string>
⚠️ iOS : Swift project
<uses-permission android:name="android.permission.RECORD_AUDIO" />
On iOS, by default the plugin is configured for French, English, Russian, Spanish, Italian. On Android, without additional installations, it will probably works only with the default device locale.
If you get a MissingPluginException, try to
flutter build apk on Android, or
flutter build ios
For help getting started with Flutter, view our online documentation.
For help on editing plugin code, view the documentation.
- Built-in types and core primitives for a Flutter application. [...]
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- Classes and utilities that supplement the collection support in dart:core. [...]
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- Built-in types, collections, and other core functionality for every Dart program. [...]
- Interact with developer tools such as the debugger and inspector. [...]
- Mathematical constants and functions, plus a random number generator. [...]
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]