Giter Site home page Giter Site logo

lego-sharat / androidspeech Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mozilla/androidspeech

0.0 1.0 0.0 201 KB

An Android library module to Mozilla's Speech-To-Text services

Java 15.33% Makefile 1.32% C 80.52% C++ 0.73% Objective-C 2.10%

androidspeech's Introduction

androidspeech

This is an Android library containing an API to Mozilla's speech recognition services.

Installation

dependencies { 
      implementation 'com.github.mozilla:mozillaspeechlibrary:1.0.6'
}

Demo app

Just run the demo application inside the folder app

Usage

The API encapsulates the microphone capture, audio encoding, voice activity detection and network communication. So for this reason its integration is very simple: just call start() and handle the events in your frontend.

First define a listener to capture the events:

ISpeechRecognitionListener mVoiceSearchListener = new ISpeechRecognitionListener() {
      public void onSpeechStatusChanged(final MozillaSpeechService.SpeechState aState, final Object aPayload){
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  switch (aState) {
                      case DECODING:
                          // Handle when the speech object changes to decoding state
                          break;
                      case MIC_ACTIVITY:
                          // Captures the activity from the microphone
                          double db = (double)aPayload * -1;
                          break;
                      case STT_RESULT:
                          // When the api finished processing and returned a hypothesis 
                          string transcription = ((STTResult)aPayload).mTranscription;
                          float confidence = ((STTResult)aPayload).mConfidence;
                          break;
                      case START_LISTEN:
                          // Handle when the api successfully opened the microphone and started listening
                          break;
                      case NO_VOICE:
                          // Handle when the api didn't detect any voice
                          break;
                      case CANCELED:
                          // Handle when a cancelation was fully executed
                          break;
                      case ERROR:
                          // Handle when any error occurred
                          string error = aPayload;
                          break;
                      default:
                          break;
                  }
              }
          });
      }
  };

Then start it:

        mMozillaSpeechService = MozillaSpeechService.getInstance();
        mMozillaSpeechService.setLanguage("en-US");
        mMozillaSpeechService.addListener(mVoiceSearchListener);
        mMozillaSpeechService.start(getApplicationContext());

In the case you want to cancel a progressing operation:

        mMozillaSpeechService.cancel();

To remove a listener:

        mMozillaSpeechService.removeListener(aListener);

Note: Your app will need RECORD_AUDIO, WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions to be set in AndroidManifest.xml manifest and requested at runtime.

androidspeech's People

Contributors

andrenatal avatar benfrancis avatar keianhzo avatar mrstegeman avatar mozilla-github-standards avatar

Watchers

Sharat Chandra avatar

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.