Giter VIP home page Giter VIP logo

umair13adil / background_stt Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 10.0 16.49 MB

A flutter plugin to run always-on speech to text service in the background.

Home Page: https://pub.dev/packages/background_stt

License: Apache License 2.0

Kotlin 41.30% Java 33.27% Ruby 5.21% Swift 1.16% Objective-C 0.91% Dart 18.14%
speech-to-text stt flutter-plugin flutter-app android google-voice always-on texttospeech-android text-to-speech commands

background_stt's Introduction

background_stt

Speech-to-Text, Text-to-speech, Interactive Voice commands

[Android Support Only]

pub package

An flutter plugin that runs Speech-to-Text continously in background. This plugin operates in 2 modes:

1. STT Mode

Voice commands will be recognized in background and sent to Flutter app.

2. Confirmation Mode

Voice commands will be recognized and if confirmation was requested for the command, confirmation flow will begin. Once user has provided with "Positive" or "Negative" reply, confirmation mode will end delivering voice input results to flutter app.

Speech results will be delivered in real-time to the flutter app.

Demo

Install

In your pubspec.yaml

dependencies:
  background_stt: [LATEST_VERSION]
import 'package:background_stt/background_stt.dart';

How to use it?

Start Speech-to-Text Service


Note: Service will keep on running once it is started and can only be stopped by calling stop service method.

 var _service = BackgroundStt();

 _service.startSpeechListenService;
    _service.getSpeechResults().onData((data) {
      print("getSpeechResults: ${data.result} , ${data.isPartial}");
    });

Setup Intent for Simple Confirmation


This can be useful for simple decisions.

    _service.getSpeechResults().onData((data) {
          if (command == "start") {
          _service.confirmIntent(
              confirmationText: "Do you want to start?",
              positiveCommand: "yes",
              negativeCommand: "no");
        }
    });

  _service.getConfirmationResults().onData((data) {
      print(
          "getConfirmationResults: Confirmation Text: ${data.confirmationIntent} , "
          "User Replied: ${data.confirmedResult} , "
          "Is Confirmation Success?: ${data.isSuccess}");
    });

Setup Intent for Voice-Input Confirmation


This can be useful for taking voice input from user and then confirming that input from user by voice command verification.

    _service.getSpeechResults().onData((data) {
          if (command == "address") {
            _service.confirmIntent(
                confirmationText: "What is the address?",
                positiveCommand: "yes",
                negativeCommand: "no",
                voiceInputMessage: "Is the address correct?",
                voiceInput: true);
          }
    });

  _service.getConfirmationResults().onData((data) {
      print(
          "getConfirmationResults: Confirmation Text: ${data.confirmationIntent} , "
          "User Replied: ${data.confirmedResult} , "
          "Voice Input Message: ${data.voiceInput} , "
          "Is Confirmation Success?: ${data.isSuccess}");
    });

Cancel Confirmation in progress


  await _service.cancelConfirmation;

Stop Speech-to-Text Service


  _service.stopSpeechListenService;

Pause Speech-to-Text Listener


  await _service.pauseListening();

Resume Speech-to-Text Listener


  await _service.resumeListening();

Speak Text and Interupt Listener


If you want to queue voice messages, send queue value 'true':

  await _service.speak("Hello",true)

To interupt and speak current playing message, send queue value 'false':

  await _service.speak("Hello",false)

Set speaker pitch and speech rate:

  _service.setSpeaker(0.2, 0.5)

Author

background_stt plugin is developed by Umair Adil. You can email me at [email protected] for any queries.

background_stt's People

Contributors

redzumi avatar umair13adil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

background_stt's Issues

Migrate to null safety

Hi,
I find this package really helpful, kudos for creating this amazing package.

Please migrate to null safety as soon as possible.

With much thanks,
Lakshmi Narayanan S

No way to really stop listener (?)

It would be great if stopSpeechListenService actually stopped the service. Now it just stops giving you results, but you can se in the debug console that it's still listening and reacting to voice input.

Service com.umair.background_stt.SpeechListenService has leaked ServiceConnection

E/ActivityThread(25328): Service com.umair.background_stt.SpeechListenService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@3dc9be0 that was originally bound here
E/ActivityThread(25328): android.app.ServiceConnectionLeaked: Service com.umair.background_stt.SpeechListenService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@3dc9be0 that was originally bound here
E/ActivityThread(25328): at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:2050)
E/ActivityThread(25328): at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1922)
E/ActivityThread(25328): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1901)
E/ActivityThread(25328): at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1849)
E/ActivityThread(25328): at android.app.ContextImpl.bindService(ContextImpl.java:1778)
E/ActivityThread(25328): at android.content.ContextWrapper.bindService(ContextWrapper.java:705)
E/ActivityThread(25328): at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:821)
E/ActivityThread(25328): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:791)
E/ActivityThread(25328): at android.speech.tts.TextToSpeech.(TextToSpeech.java:744)
E/ActivityThread(25328): at android.speech.tts.TextToSpeech.(TextToSpeech.java:723)
E/ActivityThread(25328): at android.speech.tts.TextToSpeech.(TextToSpeech.java:707)
E/ActivityThread(25328): at com.umair.background_stt.speech.TextToSpeechFeedbackProvider.setUpTextToSpeech(TextToSpeechFeedbackProvider.kt:45)
E/ActivityThread(25328): at com.umair.background_stt.speech.TextToSpeechFeedbackProvider.(TextToSpeechFeedbackProvider.kt:41)
E/ActivityThread(25328): at com.umair.background_stt.SpeechListenService.onCreate(SpeechListenService.kt:128)
E/ActivityThread(25328): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4814)
E/ActivityThread(25328): at android.app.ActivityThread.access$3000(ActivityThread.java:259)
E/ActivityThread(25328): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2475)
E/ActivityThread(25328): at android.os.Handler.dispatchMessage(Handler.java:110)
E/ActivityThread(25328): at android.os.Looper.loop(Looper.java:219)
E/ActivityThread(25328): at android.app.ActivityThread.main(ActivityThread.java:8673)
E/ActivityThread(25328): at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread(25328): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
E/ActivityThread(25328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

It listening itself

if a TTS service is also used, for a dialogue of questions and answers, I have noticed that sometimes the STT listens to itself, despite the fact that the 'pauseListening()' and 'resumeListening()' functions are used.
Do you have any solutions?
Many Thanks
Christian

Android App on Chromebook fails to recognize speech

I have my Flutter app with background_stt working great across many version of Android devices.
BUT, on a Chromebook, which otherwise runs my Android app flawlessly, fails to recognize speech.
Is there any trick you can advise I try on a Chromebook (latest version) to make background_stt work?
Thanks.

Building example app failed

Hi!
Tried to build your example app from https://pub.dev/packages/background_stt/example with latest flutter (3.0.2), latest Android SDK, but it failed:

Running Gradle task 'assembleDebug'...
e: C:\flutter.pub-cache\hosted\pub.dartlang.org\background_stt-1.0.6\android\src\main\kotlin\com\umair\background_stt\BackgroundSttPlugin.kt: (25, 1): Class 'BackgroundSttPlugin' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
e: C:\flutter.pub-cache\hosted\pub.dartlang.org\background_stt-1.0.6\android\src\main\kotlin\com\umair\background_stt\BackgroundSttPlugin.kt: (48, 32): Type mismatch: inferred type is Activity? but Context was expected
e: C:\flutter.pub-cache\hosted\pub.dartlang.org\background_stt-1.0.6\android\src\main\kotlin\com\umair\background_stt\BackgroundSttPlugin.kt: (247, 5): 'onRequestPermissionsResult' overrides nothing

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':background_stt:compileDebugKotlin'.

Compilation error. See log for more details

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 9s
Exception: Gradle task assembleDebug failed with exit code 1

Latest flutter (3.0.2), latest Android SDK

Any ideas?

Null Safety

Could you please migrate your project to null safety, thanks in advance.

Use offline

Hello, the component requires an internet connection, there is a way to use offline

How to change default locale ?

Please, did you put any method to change the locale ? There is no allusion on locale on documentation. Thanks in advance.

stopSpeechListenService error

when the current screen of the service is closed and _service.stopSpeechListenService is called an error occurs:
Service com.umair.background_stt.SpeechListenService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@73b7877 that was originally bound here
E / ActivityThread (26446): android.app.ServiceConnectionLeaked: Service com.umair.background_stt.SpeechListenService has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@73b7877 that was originally bound here

Gradle Plugin Version

FAILURE: Build failed with an exception.

  • What went wrong:
    The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
    The following dependencies do not satisfy the required version:
    project ':background_stt' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.