GithubHelp home page GithubHelp logo

eis6aer / android-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from watson-developer-cloud/android-sdk

0.0 1.0 0.0 13.07 MB

:high_brightness: Android SDK to use the IBM Watson services.

Home Page: http://watson-developer-cloud.github.io/android-sdk/

License: Apache License 2.0

Shell 2.00% Java 98.00%

android-sdk's Introduction

IBM Watson Developer Cloud Android SDK Build Status

Android client library to assist with using the Watson services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.

Table of Contents

Installation

Gradle
'com.ibm.watson.developer_cloud:android-sdk:0.4.3'
AAR

Download the aar here.


The minimum supported Android API level is 19. Now, you are ready to see some examples.

Usage

The examples below assume that you already have service credentials. If not, you will have to create a service in IBM Cloud.

Service Credentials

Getting the Credentials

You will need the username and password (api_key for Visual Recognition) credentials, as well as the url for each service. Service credentials are different from your IBM Cloud account username and password.

To get your service credentials, follow these steps:

  1. Log in to IBM Cloud at https://console.bluemix.net.

  2. Create an instance of the service:

    1. In the IBM Cloud Catalog, select the service you want to use.
    2. Under Add Service, type a unique name for the service instance in the Service name field. For example, type my-service-name. Leave the default values for the other options.
    3. Click Create.
  3. Copy your credentials:

    1. On the left side of the page, click Service Credentials to view your service credentials.
    2. Copy username, password(api_key for Visual Recognition), and url.

Adding the Credentials

The credentials should be added to the example/res/values/credentials.xml file shown below.

<resources>
  <!-- Paste Language Translator information here -->
  <string name="language_translator_username"></string>
  <string name="language_translator_password"></string>
  <string name="language_translator_url"></string>

  <!-- Paste Speech to Text information here -->
  <string name="speech_text_username"></string>
  <string name="speech_text_password"></string>
  <string name="speech_text_url"></string>

  <!-- Paste Text to Speech information here -->
  <string name="text_speech_username"></string>
  <string name="text_speech_password"></string>
  <string name="text_speech_url"></string>
</resources>

Questions

If you are having difficulties using the APIs or have a question about the IBM Watson Services, please ask a question on dW Answers or Stack Overflow.

You can also check out the wiki for some additional information.

Examples

This SDK is built for use with the java-sdk.

The examples below are specific for Android as they use the Microphone and Speaker; for actual services refer to the java-sdk. Be sure to use the provided example app as a model for your own Android app using Watson services.

MicrophoneHelper

Provides simple microphone access within an activity.

MicrophoneHelper microphoneHelper = new MicrophoneHelper(this);

The MicrophoneHelper object allows you to create new MicrophoneInputStream objects and close them. The MicrophoneInputStream class is a convenience class for creating an InputStream from device microphone. You can record raw PCM data or data encoded using the ogg codec.

// record PCM data without encoding
MicrophoneInputStream myInputStream = microphoneHelper.getInputStream(false);

// record PCM data and encode it with the ogg codec
MicrophoneInputStream myOggStream = microphoneHelper.getInputStream(true);

An example using a Watson Developer Cloud service would look like

speechService.recognizeUsingWebSocket(new MicrophoneInputStream(),
getRecognizeOptions(), new BaseRecognizeCallback() {
  @Override
  public void onTranscription(SpeechResults speechResults){
    String text = speechResults.getResults().get(0).getAlternatives().get(0).getTranscript();
    System.out.println(text);
  }

  @Override
  public void onError(Exception e) {
  }

  @Override public void onDisconnected() {
  }

});

Be sure to take a look at the example app to get a working example of putting these all together.

StreamPlayer

Provides the ability to directly play an InputStream

StreamPlayer player = new StreamPlayer();
player.playStream(yourInputStream);

CameraHelper

Provides simple camera access within an activity.

CameraHelper cameraHelper = new CameraHelper(this);
cameraHelper.dispatchTakePictureIntent();

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CameraHelper.REQUEST_IMAGE_CAPTURE) {
      System.out.println(cameraHelper.getFile(resultCode));
    }
  }

GalleryHelper

Like the CameraHelper, but allows for selection of images already on the device.

To open the gallery:

GalleryHelper galleryHelper = new GalleryHelper(this);
galleryHelper.dispatchGalleryIntent();

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == GalleryHelper.PICK_IMAGE_REQUEST) {
      System.out.println(galleryHelper.getFile(resultCode, data));
    }
  }

Testing

Testing in this SDK is accomplished with Espresso.

To run the tests, in Android Studio:

Within the example package, right-click the androidTest/java folder and click Run 'All Tests'.

Build + Test

Use Gradle (version 1.x) to build and test the project you can use

Gradle:

$ cd android-sdk
$ gradle test # run tests

Open Source @ IBM

Find more open source projects on the IBM Github Page

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

android-sdk's People

Contributors

blakesteve avatar ekeitho avatar germanattanasio avatar hendrawd avatar hsaylor avatar jpetitto avatar lpatino10 avatar schrej avatar sirspidey avatar vherrin avatar

Watchers

 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.