DEPRECATED - An Android library module to Mozilla's Speech-To-Text services
Перейти к файлу
Alexandre Lissy ee3055678b Fix #41: Update to DeepSpeech v0.9 2020-11-20 16:27:38 -08:00
app Remove speechlibrary dependency from utils 2020-06-26 01:22:56 +02:00
gradle/wrapper bump to v 1.0.10 2020-02-24 11:23:39 -08:00
mozillaspeechlibrary Fix #41: Update to DeepSpeech v0.9 2020-11-20 16:27:38 -08:00
mozillaspeechutils Remove speechlibrary dependency from utils 2020-06-26 01:22:56 +02:00
.gitignore Added support for using GeckoWebExecutor when available 2020-02-27 20:44:30 -08:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file 2019-04-05 10:01:36 -07:00
README.md Maven and Readme updated 2020-06-04 07:07:37 -07:00
build.gradle Added support for using GeckoWebExecutor when available 2020-02-27 20:44:30 -08:00
gradle.properties Remove speechlibrary dependency from utils 2020-06-26 01:22:56 +02:00
gradlew Complete Implementation 2018-08-28 19:09:40 -07:00
gradlew.bat Complete Implementation 2018-08-28 19:09:40 -07:00
settings.gradle Refactor 2020-05-30 01:00:13 -07:00

README.md

androidspeech

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

Installation

dependencies { 
      implementation 'com.github.mozilla:mozillaspeechlibrary:2.0.0'
      implementation 'com.github.mozilla:mozillaspeechutils:2.0.0'      // Just in case you want to use the utils for downloading/unzipping
}

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:

SpeechResultCallback mVoiceSearchListener = new SpeechResultCallback() {

    @Override
    public void onStartListen() {
        // Handle when the api successfully opened the microphone and started listening
    }

    @Override
    public void onMicActivity(double fftsum) {
        // Captures the activity from the microphone
    }

    @Override
    public void onDecoding() {
        // Handle when the speech object changes to decoding state
    }

    @Override
    public void onSTTResult(@Nullable STTResult result) {
        // When the api finished processing and returned a hypothesis
    }

    @Override
    public void onNoVoice() {
        // Handle when the api didn't detect any voice
    }

    @Override
    public void onError(@SpeechResultCallback.ErrorType int errorType, @Nullable String error) {
        // Handle when any error occurred

    }
};

Create an instance of the Speech Service:

    mSpeechService = new SpeechService(this);

Start a request:

    SpeechServiceSettings.Builder builder = new SpeechServiceSettings.Builder()
        .withLanguage("en-US")
        .withStoreSamples(true)
        .withStoreTranscriptions(true)
        .withProductTag("product-tag")
        .withUseDeepSpeech(true)            // If using DeepSpeech
        .withModelPath("path/to/model");    // If using DeepSpeech
    mSpeechService.start(builder.build(), mVoiceSearchListener);

In the case you want to cancel a progressing operation:

    mSpeechService.stop();

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.