Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

speech-android-sdk

DEPRECATED - Please use https://github.com/watson-developer-cloud/android-sdk

Subscribe to updates I use speech-android-sdk


Statistics on speech-android-sdk

Number of watchers on Github 58
Number of open issues 8
Average time to close an issue about 1 month
Main language Java
Average time to merge a PR about 17 hours
Open pull requests 2+
Closed pull requests 1+
Last commit over 2 years ago
Repo Created about 4 years ago
Repo Last Updated over 1 year ago
Size 36 MB
Organization / Authorwatson-developer-cloud
Latest Releasewatsonsdk.aar
Contributors5
Page Updated
Do you use speech-android-sdk? Leave a review!
View open issues (8)
View speech-android-sdk activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating speech-android-sdk for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Watson Speech Android SDK

The Watson Speech SDK for the Android platform enables an easy and lightweight interaction with the IBM's Watson Speech-To-Text (STT) and Text-To-Speech (TTS) services in Bluemix. The SDK includes support for recording and streaming audio in real time to the STT service while receiving a transcript of the audio as you speak. This project includes an example application that showcases the interaction with both the STT and TTS Watson services in the cloud.

The current version of the SDK uses a minSdkVersion of 9, while the example application uses a minSdkVersion of 16.

Table of Contents

Installation

Using the library

  1. Download the speech-android-wrapper.aar
  2. Once unzipped drag the speech-android-wrapper.aar file into your Android Studio project view under the libs folder.
  3. Go to build.gradle file of your app, then set the dependencies as below:
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile (name:'speech-android-wrapper',ext:'aar')
        compile 'com.android.support:appcompat-v7:22.0.0'
    }
    repositories{
        flatDir{
            dirs 'libs'
        }
    }
  1. Clean and run the Android Studio project

Getting credentials

  1. Create an account on Bluemix if you have not already.
  2. Follow instructions at Service credentials for Watson services to get service credentials.

A Quick Start Guide

To get started, you can also take a look at a quick start guide created by @KeyOnTech.

Speech To Text

Implement the ISpeechDelegate and SpeechRecorderDelegate in the MainActivity

These delegates implement the callbacks when a response from the server is received or when the recorder is sending back the audio data. SpeechRecorderDelegate is optional.

   public class MainActivity extends Activity implements ISpeechDelegate{}

Or with SpeechRecorderDelegate

   public class MainActivity extends Activity implements ISpeechDelegate, SpeechRecorderDelegate{}

Instantiate the SpeechToText instance

   SpeechToText.sharedInstance().initWithContext(new URI("wss://stream.watsonplatform.net/speech-to-text/api"), this.getApplicationContext(), new SpeechConfiguration());

Enabling audio compression

By default audio sent to the server is uncompressed PCM encoded data, compressed audio using the Opus codec can be enabled.

   SpeechToText.sharedInstance().initWithContext(this.getHost(STT_URL), this.getApplicationContext(), new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS));

Or this way:

    // Configuration
    SpeechConfiguration sConfig = new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS);
    // STT
    SpeechToText.sharedInstance().initWithContext(this.getHost(STT_URL), this.getApplicationContext(), sConfig);

Set the Credentials and the delegate

   SpeechToText.sharedInstance().setCredentials(this.USERNAME,this.PASSWORD);
   SpeechToText.sharedInstance().setDelegate(this);

Alternatively pass a token factory object to be used by the SDK to retrieve authentication tokens to authenticate against the STT service

   SpeechToText.sharedInstance().setTokenProvider(new MyTokenProvider(this.strSTTTokenFactoryURL));
   SpeechToText.sharedInstance().setDelegate(this);

Get a list of models supported by the service

   JSONObject models = getModels();

Get details of a particular model

   JSONObject model = getModelInfo("en-US_BroadbandModel");

Pick the model to be used

   SpeechToText.sharedInstance().setModel("en-US_BroadbandModel");

Start Audio Transcription

   SpeechToText.sharedInstance().recognize();

If you implemented SpeechRecorderDelegate, and needs to process the audio data which is recorded, you can use set the delegate.

   SpeechToText.sharedInstance().recognize();
   SpeechToText.sharedInstance().setRecorderDelegate(this);

Delegate methods to receive messages from the sdk

    public void onOpen() {
        // the  connection to the STT service is successfully opened
    }

    public void onError(String error) {
        // error interacting with the STT service
    }

    public void onClose(int code, String reason, boolean remote) {
        // the connection with the STT service was just closed
    }

    public void onMessage(String message) {
        // a message comes from the STT service with recognition results
    }

End Audio Transcription

   SpeechRecognition.sharedInstance().stopRecording();

Receive speech power levels during the recognize

The amplitude is calculated from the audio data buffer, and the volume (in dB) is calculated based on it.

    @Override
    public void onAmplitude(double amplitude, double volume) {
        // your code here
    }

Text To Speech

Instantiate the TextToSpeech instance

   TextToSpeech.sharedInstance().initWithContext(this.getHost(TTS_URL));

Set the Credentials

   TextToSpeech.sharedInstance().setCredentials(this.USERNAME,this.PASSWORD);

Alternatively pass a token factory object to be used by the SDK to retrieve authentication tokens to authenticate against the TTS service

   TextToSpeech.sharedInstance().setTokenProvider(new MyTokenProvider(this.strTTSTokenFactoryURL));

Get a list of voices supported by the service

   TextToSpeech.sharedInstance().voices();

Pick the voice to be used

   TextToSpeech.sharedInstance().setVoice("en-US_MichaelVoice");

Generate and play audio

  TextToSpeech.sharedInstance().synthesize(ttsText);

Common issues

speech-android-sdk open issues Ask a question     (View All Issues)
  • about 3 years com-sun-jna-android-arm-libjnidispatch-so-not-found-in-resource-path
  • about 3 years crash when microphone permissions are not granted
  • over 3 years android.media.AudioTrack: getMinBufferSize(): 1948401012 Hz is not a supported sample rate.
  • over 3 years stop currently playing audio of Text-to-Speech
  • over 3 years Deprecate speech-android-sdk
  • over 3 years Websocket ssl error
  • over 3 years New Project Quick Start Guide
  • over 3 years Quick Start Guide
  • almost 4 years Provide a sample implementation that extends Android's RecognitionService
speech-android-sdk open pull requests (View All Pulls)
  • Fix .aar filename and ISpeechDelegate name in Readme
  • Expose additional optional features in the config (ex: maxAlternatives)
speech-android-sdk list of languages used
Other projects in Java