speech_to_text 2.1.0 copy "speech_to_text: ^2.1.0" to clipboard
speech_to_text: ^2.1.0 copied to clipboard

outdated

A Flutter plugin that exposes device specific speech to text recognition capability.

speech_to_text #

pub package build status

A library that exposes device specific speech recognition capability.

This plugin contains a set of classes that make it easy to use the speech recognition capabilities of the mobile device in Flutter. It supports both Android and iOS. The target use cases for this library are commands and short phrases, not continuous spoken conversion or always on listening.

Recent Updates #

The 2.0.0 version uses the new Flutter 1.12.x plugin APIs, although it may work with older with older versions of Flutter it is not guaranteed. It also blocks duplicate notifications on some Android versions, if you feel you have missed an onResult notification please post an issue. See the change log for more details.

The 1.0.0 version adds the ability to automatically cancel listening on a permanent error. This is a new parameter on the listen method, defaulted to false for backward compatibility. It also adds the ability to control whether partial and complete or only complete results are sent during listening.

Note: Feedback from any test devices is welcome.

Using #

To recognize text from the microphone import the package and call the plugin, like so:

import 'package:speech_to_text/speech_to_text.dart' as stt;

    stt.SpeechToText speech = stt.SpeechToText();
    bool available = await speech.initialize( onStatus: statusListener, onError: errorListener );
    if ( available ) {
        speech.listen( onResult: resultListener );
    }
    else {
        print("The user has denied the use of speech recognition.");
    }
    // some time later...
    speech.stop()

Permissions #

Applications using this plugin require user permissions.

iOS #

Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSSpeechRecognitionUsageDescription - describe why your app uses speech recognition. This is called Privacy - Speech Recognition Usage Description in the visual editor.
  • NSMicrophoneUsageDescription - describe why your app needs access to the microphone. This is called Privacy - Microphone Usage Description in the visual editor.

Android #

Add the record audio permission to your AndroidManifest.xml file, located in <project root>/android/app/src/main/AndroidManifest.xml.

  • android.permission.RECORD_AUDIO - this permission is required for microphone access.
  • android.permission.INTERNET - this permission is required because speech recognition may use remote services.

Adding Sounds for iOS (optional) #

Android automatically plays system sounds when speech listening starts or stops but iOS does not. This plugin supports playing sounds to indicate listening status on iOS if sound files are available as assets in the application. To enable sounds in an application using this plugin add the sound files to the project and reference them in the assets section of the application pubspec.yaml. The location and filenames of the sound files must exactly match what is shown below or they will not be found. The example application for the plugin shows the usage.

  assets:
  - assets/sounds/speech_to_text_listening.m4r
  - assets/sounds/speech_to_text_cancel.m4r
  - assets/sounds/speech_to_text_stop.m4r
  • speech_to_text_listening.m4r - played when the listen method is called.
  • speech_to_text_cancel.m4r - played when the cancel method is called.
  • speech_to_text_stop.m4r - played when the stop method is called.

Troubleshooting #

Not working on a particular Android device #

The symptom for this issue is that the initialize method will always fail. If you turn on debug logging using the debugLogging: true flag on the initialize method you'll see 'Speech recognition unavailable' in the Android log. There's a lengthy issue discussion here https://github.com/csdcorp/speech_to_text/issues/36 about this. The issue seems to be that the recognizer is now always automatically enabled on the device. Two key things helped resolve the issue in this case at least.

First

  1. Go to Google Play
  2. Search for 'Google'
  3. You should find this app: https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox If 'Disabled' enable it

This is the SO post that helped: https://stackoverflow.com/questions/28769320/how-to-check-wether-speech-recognition-is-available-or-not

Second

Ensure the app has the required permissions. The symptom for this that you get a permanent error notification 'error_audio_error` when starting a listen session. Here's a Stack Overflow post that addresses that https://stackoverflow.com/questions/46376193/android-speechrecognizer-audio-recording-error Here's the important excerpt:

You should go to system setting, Apps, Google app, then enable its permission of microphone.

1346
likes
0
pub points
99%
popularity

Publisher

verified publishercsdcorp.com

A Flutter plugin that exposes device specific speech to text recognition capability.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, json_annotation

More

Packages that depend on speech_to_text