A Flutter plugin to use speech recognition on iOS & Android (Swift/Java)

Overview

speech_recognition

A flutter plugin to use the speech recognition iOS10+ / Android 4.1+

screenshot

Installation

  1. Depend on it Add this to your package's pubspec.yaml file:
dependencies:
  speech_recognition: "^0.3.0"
  1. Install it You can install packages from the command line:
$ flutter packages get
  1. Import it Now in your Dart code, you can use:
import 'package:speech_recognition/speech_recognition.dart';

Usage

//..
_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();

Recognition

Permissions

iOS

⚠️ iOS : Swift 4.2 project

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>

Android

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Limitation

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.

Troubleshooting

If you get a MissingPluginException, try to flutter build apk on Android, or flutter build ios

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Comments
  • Volume decreases after invoking speech recognition on IOS.

    Volume decreases after invoking speech recognition on IOS.

    Hi team. I’m using speech_recognition 0.3.0+1 with flutter. I’ve tested with simulator IOS, it worked properly. But when I build and test on a real device (iPhone 7 plus), have a problem, when the first time I start the app, volume work as normal, but whenever I invoke a speech recognition, the overall volume of the app decreases. I tried to fix follow guide. But it still not works.

    Please help me to find the solution for this, thanks team

    opened by daothan1211 5
  • Add support to dart sdk version above 2.0.0

    Add support to dart sdk version above 2.0.0

    I am getting this error while running flutter packages get.,

    Running "flutter packages get" in App... The current Dart SDK version is 2.1.0-dev.0.0.flutter-be6309690f.

    Because App depends on speech_recognition >=0.2.0+1 which requires SDK version <2.0.0, version solving failed.

    Can you please add support to the dart 2.1?

    opened by DineshkumarThiran 4
  • Speech recognition only works once

    Speech recognition only works once

    If you do a recognition, click on stop and try again immediately, no text will be recognised. Only if you wait for approx 30 seconds, recognition will work again.

    opened by mploigt 3
  • Dart SDK <2.0.0 required while running packages get . (pug get failed (1))

    Dart SDK <2.0.0 required while running packages get . (pug get failed (1))

    D:\Flutter\Sdk\flutter\bin\flutter.bat --no-color packages upgrade Running "flutter packages upgrade" in music_player... The current Dart SDK version is 2.1.0-dev.3.1.flutter-760a9690c2. Because music_player depends on speech_recognition any which requires SDK version >=1.23.0 <2.0.0, version solving failed. pub upgrade failed (1)

    opened by Aman-Malhotra 3
  • speech_recognition ios build target change

    speech_recognition ios build target change

    I upgraded my phone's ios version to 13.3.1 and it messed up my flutter project. I don't remember my older phone ios version, but the flutter project ran great and installed the app on my phone as expected. Since my initial build error I've looked online and tried the following:

    -Upgraded Xcode to 11.3.1 -Changed ios build target in IOS to 12.2 in xcode for the flutter runner target in Build Settings -I change the podfile and added

    config.build_settings['SWIFT_VERSION'] = '4.2'

    to the post_install do |installer| section

    -In Flutter, I've run flutter clean and tried to upgrade all packages

    My current state is the following:

    Running flutter run I get the following: `Xcode's output: ↳ /Users/xxxxxxxx/Development/myapp/ios/Runner/AppDelegate.swift:8:51: error: 'UIApplicationLaunchOptionsKey' has been renamed to 'UIApplication.LaunchOptionsKey' didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UIApplication.LaunchOptionsKey UIKit.UIApplicationLaunchOptionsKey:2:18: note: 'UIApplicationLaunchOptionsKey' was obsoleted in Swift 4.2 public typealias UIApplicationLaunchOptionsKey = UIApplication.LaunchOptionsKey ^ /Users/xxxxxxxx/Development/myapp/ios/Runner/AppDelegate.swift:6:17: error: method does not override any method from its superclass override func application( ~~~~~~~~ ^ note: Using new build system note: Planning build note: Constructing build description

    Could not build the precompiled application for the device. `

    -Running flutter build ios I get the following `Xcode's output: ↳ fatal error: file '/Users/xxxxxxxx/Development/myapp/ios/Flutter/Flutter.framework/Headers/FlutterTexture.h' has been modified since the precompiled header '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/Runner-bxrjdjogpfyjgwfrxuwqrcdwwypk/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_3V8XQWPRZ 3HOV-clang_219AO8AD13IWK.pch' was built note: '/Users/xxxxxxxx/Development/myapp/ios/Flutter/Flutter.framework/Headers/FlutterTexture.h' required by '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/219AO8AD13IWK/Flutter-1KG53IL0U6S6I.pcm' note: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/219AO8AD13IWK/Flutter-1KG53IL0U6S6I.pcm' required by '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/Runner-bxrjdjogpfyjgwfrxuwqrcdwwypk/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_3V8XQWPRZ 3HOV-clang_219AO8AD13IWK.pch' note: please rebuild precompiled header '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/Runner-bxrjdjogpfyjgwfrxuwqrcdwwypk/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_3V8XQWPRZ 3HOV-clang_219AO8AD13IWK.pch' note: imported by '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/Runner-bxrjdjogpfyjgwfrxuwqrcdwwypk/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_3V8XQWPRZ 3HOV-clang_219AO8AD13IWK.pch' /Users/xxxxxxxx/Development/myapp/ios/Runner/AppDelegate.swift:8:51: error: 'UIApplicationLaunchOptionsKey' has been renamed to 'UIApplication.LaunchOptionsKey' didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UIApplication.LaunchOptionsKey UIKit.UIApplicationLaunchOptionsKey:2:18: note: 'UIApplicationLaunchOptionsKey' was obsoleted in Swift 4.2 public typealias UIApplicationLaunchOptionsKey = UIApplication.LaunchOptionsKey ^ /Users/xxxxxxxx/Development/myapp/ios/Runner/AppDelegate.swift:6:17: error: method does not override any method from its superclass override func application( ~~~~~~~~ ^ note: Using new build system note: Planning build note: Constructing build description

    Encountered error while building for device.`

    • In Xcode after running flutter build ios or flutter run, I see the following errors for numerous files: Stale file '/Users/xxxxxxxx/Development/myapp/build/ios/Debug-iphoneos/path_provider/path_provider.framework' is located outside of the allowed root paths.

    -My Mac OSX version is 10.14.6 if that matters.

    Any help would be extremely appreciated! Thanks, Andy

    opened by crashinc99 2
  • SpeechRecognitionPlugin.java uses or overrides a deprecated API.

    SpeechRecognitionPlugin.java uses or overrides a deprecated API.

    When I Run app, I got a note Note: C:\src\flutter.pub-cache\hosted\pub.dartlang.org\speech_recognition-0.3.0+1\android\src\main\java\bz\rxla\flutter\speechrecognition\SpeechRecognitionPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

    opened by toshiossada 2
  • Error on Android Pie

    Error on Android Pie

    I tried to run example on android Pie API 28 but when I clicked to record I got following error

    I/flutter (13784): _platformCallHandler call speech.onSpeechAvailability false I/flutter (13784): _platformCallHandler call speech.onError 2 I/flutter (13784): Unknowm method speech.onError

    opened by toshiossada 2
  • iOS Build Fail

    iOS Build Fail

    Launching lib/main.dart on iPhone Xʀ in debug mode...
    Running Xcode build...                                                  
                                                       
    Xcode build done.                                           13.3s
    Failed to build iOS app
    Error output from Xcode build:
    ↳
        ** BUILD FAILED **
    
    
    Xcode's output:
    ↳
        /Users/pathfinder/labs/development/flutter/.pub-cache/hosted/pub.dartlang.org/speech_recognition-0.3.0+1/ios/Classes/SwiftSpeechRecognitionPlugin.swift:111:34: error:
        type 'AVAudioSession.Category' (aka 'NSString') has no member 'record'
            try audioSession.setCategory(AVAudioSession.Category.record, mode: .default)
                                         ^~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
        /Users/pathfinder/labs/development/flutter/.pub-cache/hosted/pub.dartlang.org/speech_recognition-0.3.0+1/ios/Classes/SwiftSpeechRecognitionPlugin.swift:112:30: error:
        type 'AVAudioSession.Mode' (aka 'NSString') has no member 'measurement'
            try audioSession.setMode(AVAudioSession.Mode.measurement)
                                     ^~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
        /Users/pathfinder/labs/development/flutter/.pub-cache/hosted/pub.dartlang.org/speech_recognition-0.3.0+1/ios/Classes/SwiftSpeechRecognitionPlugin.swift:186:9: error:
        value of type 'AVAudioSession.Category' (aka 'NSString') has no member 'rawValue'
                return input.rawValue
                       ^~~~~ ~~~~~~~~
    
    Could not build the application for the simulator.
    Error launching application on iPhone Xʀ.
    
    opened by uber1geek 2
  • Push new version to pub.dartlang.org

    Push new version to pub.dartlang.org

    I would like to use recent major feature updates in a larger project, however, the most recent build available from pub.dartlang.org is back from November. This prevents us from being able to use features such as the error handling, which is a big deal! I would greatly appreciate it if you could update the package listing with a recent build. We really appreciate the work that you have done on this library already!

    Many thanks,

    Ed

    opened by nerddigestive 2
  • iOS Code Error

    iOS Code Error

    On building for iOS, the code is throwing an error on line 115 in the file "SwiftSpeechRecognitionPlugin.swift":

    guard let inputNode = audioEngine.inputNode else {
    

    ** BUILD FAILED ** Xcode's output: ↳ === BUILD TARGET speech_recognition OF PROJECT Pods WITH CONFIGURATION Debug === /<flutter-lib>/.pub-cache/hosted/pub.dartlang.org/speech_recognition-0.2.0+1/ios/Classes/SwiftSpeechRecognitionPlugin.swift:115:11: error: initializer for conditional binding must have Optional type, not 'AVAudioInputNode' guard let inputNode = audioEngine.inputNode else { ^

    The cause seems to be that audioEngine is not an Optional type, and according to the AVAudioEngine Documentation neither is the inputNode member, and without an Optional value, guard throws an error.

    opened by andrewackerman 2
  • new problem on flutter > iOS build (from android studio)

    new problem on flutter > iOS build (from android studio)

    Hey, during flutter -> iOS build (from android studio) the build was done during last days ... Bot Now: today: the build failed Message is : /Users/berndkroeger/flutter/.pub-cache/hosted/pub.dartlang.org/speech_recognition-0.3.0+1/ios/Classes/SwiftSpeechRecognitionPlugin.swift:57:9: warning: switch covers known cases, but 'SFSpeechRecognizerAuthorizationStatus' may have additional unknown values, possibly added in future versions switch authStatus { ^

    I am g Bildschirmfoto 2021-01-27 um 12 00 17 rateful fo any help :) Bernd

    opened by bjkroeger 1
  • Can this be used offline?

    Can this be used offline?

    Not an issue but a question:

    I found a stackoverflow post that mentions that speech_recognition can be used offline? Ref: https://stackoverflow.com/questions/58060889/flutter-dart-speech-to-text-offline-and-continuous-for-any-language

    Is offline mode available? I'm not seeing a way to configure this.

    I'm trying to implement voice commands. I really only need 3 words to be recognized. An offline mode would be ideal for what I'm doing. I know there's picovoice but that's priced way to high for the small project I'm working.

    opened by crashinc99 0
  • does not work for Android while is working with iOS

    does not work for Android while is working with iOS

    Speech Recognitions works with iOS , but with android I get no recognition: running your example gives: E/SpeechRecognizer( 6042): bind to recognition service failed

    I edited AndroidManifest.xml correctly -> adding:

    See the resulting screenshot I get during running your example main.dart:

    Bildschirmfoto 2021-02-03 um 08 22 28
    opened by bjkroeger 0
  • Unknowm method speech.onError

    Unknowm method speech.onError

    I am getting this error when pressing the listen button

    Restarted application in 2,034ms.
    I/GED     (15123): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 15, oppidx_max 15, oppidx_min 0
    I/flutter (15123): _MyAppState.activateSpeechRecognizer...
    D/SpeechRecognitionPlugin(15123): Current Locale : en_GB
    I/flutter (15123): _platformCallHandler call speech.onCurrentLocale en_GB
    I/flutter (15123): _MyAppState.onCurrentLocale... en_GB
    D/ColorViewRootUtil(15123): nav bar mode ignore false downX 428 downY 1056 mScreenHeight 1520 mScreenWidth 720 mStatusBarHeight 36 globalScale 1.125 nav mode 0 rotation 0 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=428.0, y[0]=1056.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=59352798, downTime=59352798, deviceId=2, source=0x1002, displayId=0 }
    D/SpeechRecognitionPlugin(15123): onError : 9
    I/flutter (15123): _MyAppState.start => result true
    I/flutter (15123): _platformCallHandler call speech.onSpeechAvailability false
    I/flutter (15123): _platformCallHandler call speech.onError 9
    I/flutter (15123): Unknowm method speech.onError
    
    
    opened by viralvaghela 1
  • How to implement this plugin with a text field and enable user to modify the text?

    How to implement this plugin with a text field and enable user to modify the text?

    Hi,

    Can anyone help me with this question? All the example I saw is to show a Text widget, but which kind of App need this? because if it's only a text and if the recording has any mistake, e.g. user say something wrong or has strong accent, then the text is not correct, and user can not change on the screen unless they record a new one, but that's not good user interface, right?

    I think it should be a TextField, I tried to implement this, but I can't do it, can anyone share with me how to make the text show on a text field?

    // Additional note: I later realized our phone already has a audio button on the bottom-right ride of the keyboard that can record voice/speech and show it as a text, so if we just have a text field in the app, user can still use speech for inputting text, and in this way, if any text is wrong, you can modify the text with keyboard, so can anyone tell me why we use this plugin? what are practical usage of this?

    Thank you!

    opened by lutang123 0
A flutter plugin to handle Android / iOS camera

?? Overview Flutter plugin to add Camera support inside your project. CamerAwesome include a lot of useful features like: ?? Live camera flip ( switch

Apparence.io 511 Jan 5, 2023
Flutter plugin for selecting multiple images from the Android and iOS image library

Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotating, cropping, adding sticker/filters.

Weta Vietnam 91 Dec 19, 2022
A Flutter media player plugin for iOS and android based on ijkplayer

Flutter media player plugin for android/iOS based on ijkplayer.

于飞白呀 1.4k Jan 4, 2023
Flutter plugin for use Video.js in flutter web

Flutter Video.js player Flutter plugin for use Video.js in flutter web Installation Add it to your package's pubspec.yaml file dependencies: video_j

null 15 Oct 17, 2022
This Flutter plugin created to show how to use OpenCV and ZXing C++ libraries natively in Flutter with Dart FFI using the camera stream

OpenCV and ZXing C++ libraries natively in Flutter with Dart FFI using the camera stream

Khoren Markosyan 17 Oct 21, 2022
Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications

?? assets_audio_player ?? Play music/audio stored in assets files (simultaneously) directly from Flutter (android / ios / web / macos). You can also u

Florent CHAMPIGNY 651 Dec 24, 2022
A flutter package for iOS and Android for applying filter to an image

Photo Filters package for flutter A flutter package for iOS and Android for applying filter to an image. A set of preset filters are also available. Y

Ansh rathod 1 Oct 26, 2021
A Flutter package for both android and iOS which provides Audio recorder

social_media_recorder A Flutter package for both android and iOS which provides

subhikhalifeh 16 Dec 29, 2022
Audio classification Tflite package for flutter (iOS & Android).

Audio classification Tflite package for flutter (iOS & Android). Can also support Google Teachable Machine models.

Michael Nguyen 47 Dec 1, 2022
Tiwee - An IPTV player developed for android/ios devices with flutter

Tiwee An IPTV player developed for android/ios devices with flutter you can watc

Hossein 58 Dec 27, 2022
Apps For streaming audio via url (Android, iOS & Web ). Developed with Dart & Flutter ❤

Flutter Sleep App (Dicoding Submission : Learn to Make Flutter Apps for Beginners) Stream Great collection of high-definition sounds that can be mixed

Utrodus Said Al Baqi 13 Nov 29, 2022
An ipod classic for iOS/Android, built with Flutter

Retro aims to bring back the iPod Classic experience to iOS and Android. I originally started working on it nearly 2 years ago and released it as a TestFlight beta (because Apple wouldn't allow it on the App Store) and have been maintaining it myself since.

Retro Music 69 Jan 3, 2023
Just_audio: a feature-rich audio player for Android, iOS, macOS and web

just_audio just_audio is a feature-rich audio player for Android, iOS, macOS and web. Mixing and matching audio plugins The flutter plugin ecosystem c

Ensar Yusuf Yılmaz 2 Jun 28, 2022
Automatically generates native code for adding splash screens in Android and iOS.

Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.

Jon Hanson 949 Jan 2, 2023
Simple plugin to implement Picture in Picture support for Android only.

flutter_pip Simple plugin to implement Picture in Picture support for Android only. Android Setup You need to declare that your app supports Picture i

null 0 Dec 22, 2021
Better video player for Flutter, with multiple configuration options. Solving typical use cases!

Better video player for Flutter, with multiple configuration options. Solving typical use cases!

Jakub 732 Jan 2, 2023
This is a flutter package of video player. it's a very simple and easy to use.

This is a flutter package of video player. it's a very simple and easy to use.

初冬 184 Nov 18, 2022
Use your Flutter knowledge to generate videos, animations and slideshows

Use your Flutter knowledge to generate videos, animations and slideshows! Automate your video production with server-side rendering. Footage is still

Aloïs Deniel 131 Dec 7, 2022