{"id":13801114,"url":"https://github.com/watson-developer-cloud/android-sdk","last_synced_at":"2025-09-14T21:22:52.272Z","repository":{"id":55473658,"uuid":"55543847","full_name":"watson-developer-cloud/android-sdk","owner":"watson-developer-cloud","description":":high_brightness: Android SDK to use the IBM Watson services.","archived":false,"fork":false,"pushed_at":"2021-01-04T18:34:40.000Z","size":13981,"stargazers_count":145,"open_issues_count":11,"forks_count":96,"subscribers_count":35,"default_branch":"master","last_synced_at":"2024-08-04T00:05:53.963Z","etag":null,"topics":["aar","android","android-sdk","ibm-cloud","watson-services"],"latest_commit_sha":null,"homepage":"http://watson-developer-cloud.github.io/android-sdk/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watson-developer-cloud.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-05T20:33:41.000Z","updated_at":"2024-05-28T01:50:56.000Z","dependencies_parsed_at":"2022-08-15T01:10:31.292Z","dependency_job_id":null,"html_url":"https://github.com/watson-developer-cloud/android-sdk","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fandroid-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fandroid-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fandroid-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fandroid-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watson-developer-cloud","download_url":"https://codeload.github.com/watson-developer-cloud/android-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223945870,"owners_count":17229726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aar","android","android-sdk","ibm-cloud","watson-services"],"created_at":"2024-08-04T00:01:19.630Z","updated_at":"2024-11-10T11:27:24.719Z","avatar_url":"https://github.com/watson-developer-cloud.png","language":"Java","funding_links":[],"categories":["Data \u0026 AI","Java"],"sub_categories":[],"readme":"# IBM Watson Developer Cloud Android SDK [![Build Status](https://travis-ci.org/watson-developer-cloud/android-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/android-sdk)\n\nAndroid client library to assist with using the [Watson][wdc] services, a collection of REST\nAPIs and SDKs that use cognitive computing to solve complex problems.\n\n## Table of Contents\n\n  * [Installation](#installation)\n    * [Gradle](#gradle)\n  * [Usage](#usage)\n  * [Service Credentials](#service-credentials)\n    * [Getting the Credentials](#getting-the-credentials)\n    * [Adding the Credentials](#adding-the-credentials)\n  * [Questions](#questions)\n  * [Examples](#examples)\n  * [Testing](#testing)\n  * [License](#license)\n  * [Contributing](#contributing)\n\n## Installation\n\n##### Gradle\n\n```gradle\n'com.ibm.watson.developer_cloud:android-sdk:0.6.0'\n```\n\n##### AAR\n\nDownload the aar [here][aar].\n\n-----\nThe minimum supported Android API level is 19. Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/android-sdk/tree/master/example).\n\n## Usage\n\nThe examples below assume that you already have service credentials. If not, you will have to create a service in [IBM Cloud][bluemix].\n\n## Service Credentials\n\n#### Getting the Credentials\n1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).\n1. Create an instance of the Watson service you want to use and get your credentials:\n    - Go to the [IBM Cloud catalog](https://console.bluemix.net/catalog/?category=ai) page and select the service you want.\n    - Log in to your IBM Cloud account.\n    - Click **Create**.\n    - Click **Show** to view the service credentials.\n    - Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.\n    - Copy the `url` value.\n\n#### Adding the Credentials\n\nOnce you've followed the instructions above to get credentials, they should be added to the `example/res/values/credentials.xml` file shown below.\n\n```xml\n\u003cresources\u003e\n  \u003c!-- Paste Language Translator information here --\u003e\n  \u003cstring name=\"visual_recognition_iam_apikey\"\u003e\u003c/string\u003e\n  \u003cstring name=\"visual_recognition_url\"\u003e\u003c/string\u003e\n\n  \u003c!-- Paste Speech to Text information here --\u003e\n  \u003cstring name=\"speech_text_iam_apikey\"\u003e\u003c/string\u003e\n  \u003cstring name=\"speech_text_url\"\u003e\u003c/string\u003e\n\n  \u003c!-- Paste Text to Speech information here --\u003e\n  \u003cstring name=\"text_speech_iam_apikey\"\u003e\u003c/string\u003e\n  \u003cstring name=\"text_speech_url\"\u003e\u003c/string\u003e\n\u003c/resources\u003e\n```\n\n## Questions\n\nIf you are having difficulties using the APIs or have a question about the IBM\nWatson Services, please ask a question on\n[dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson)\nor [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).\n\nYou can also check out the [wiki][wiki] for some additional information.\n\n## Examples\n\nThis SDK is built for use with the [Watson Java SDK][java-sdk].\n\nThe examples below are specific for Android as they use the Microphone and Speaker; for actual services refer to the [Java SDK][java-sdk]. You can use the provided example app as a model for your own Android app using Watson services.\n\n### MicrophoneHelper\n\nProvides simple microphone access within an activity.\n\n```java\nMicrophoneHelper microphoneHelper = new MicrophoneHelper(this);\n```\n\nThe 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.\n\n```java\n// record PCM data without encoding\nMicrophoneInputStream myInputStream = microphoneHelper.getInputStream(false);\n\n// record PCM data and encode it with the ogg codec\nMicrophoneInputStream myOggStream = microphoneHelper.getInputStream(true);\n```\n\nAn example using a Watson Developer Cloud service would look like\n\n```java\nspeechService.recognizeUsingWebSocket(new MicrophoneInputStream(),\ngetRecognizeOptions(), new BaseRecognizeCallback() {\n  @Override\n  public void onTranscription(SpeechResults speechResults){\n    String text = speechResults.getResults().get(0).getAlternatives().get(0).getTranscript();\n    System.out.println(text);\n  }\n\n  @Override\n  public void onError(Exception e) {\n  }\n\n  @Override public void onDisconnected() {\n  }\n\n});\n```\n\nBe sure to take a look at the example app to get a working example of putting these all together.\n\n### StreamPlayer\n\nProvides the ability to directly play an `InputStream`. **Note:** The `InputStream` must come from a PCM audio source. Examples include WAV files or Audio/L16.\n\n```java\nStreamPlayer player = new StreamPlayer();\nplayer.playStream(yourInputStream);\n```\n\nSince this SDK is intended to be used with the Watson APIs, a typical use case for the `StreamPlayer` class is for playing the output of a Watson Text to Speech call. In that case, you can specify the type of audio file you'd like to receive from the service to ensure it will be output properly by your Android device.\n\n```java\nSynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder()\n  .text(\"I love making Android apps\")\n  .accept(SynthesizeOptions.Accept.AUDIO_WAV) // specifying that we want a WAV file\n  .build();\nInputStream streamResult = textService.synthesize(synthesizeOptions).execute();\n\nStreamPlayer player = new StreamPlayer();\nplayer.playStream(streamResult); // should work like a charm\n```\n\nAnother content type that works from the Text to Speech APIs is the Audio/L16 type. For this you need to specify the sample rate, and you can do so with the alternate version of the `playStream()` method. The default sample rate on the single-argument version is 22050.\n\n```java\nSynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder()\n  .text(\"I love making Android apps\")\n  .accept(\"audio/l16;rate=8000\") // specifying our content type and sample rate\n  .build();\nInputStream streamResult = textService.synthesize(synthesizeOptions).execute();\n\nStreamPlayer player = new StreamPlayer();\nplayer.playStream(streamResult, 8000); // passing in the sample rate\n```\n\n### CameraHelper\n\nProvides simple camera access within an activity.\n\n```java\nCameraHelper cameraHelper = new CameraHelper(this);\ncameraHelper.dispatchTakePictureIntent();\n\n@Override\n  protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n    super.onActivityResult(requestCode, resultCode, data);\n\n    if (requestCode == CameraHelper.REQUEST_IMAGE_CAPTURE) {\n      System.out.println(cameraHelper.getFile(resultCode));\n    }\n  }\n```\n\n### GalleryHelper\n\nLike the CameraHelper, but allows for selection of images already on the device.\n\nTo open the gallery:\n\n```java\nGalleryHelper galleryHelper = new GalleryHelper(this);\ngalleryHelper.dispatchGalleryIntent();\n\n@Override\n  protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n    super.onActivityResult(requestCode, resultCode, data);\n\n    if (requestCode == GalleryHelper.PICK_IMAGE_REQUEST) {\n      System.out.println(galleryHelper.getFile(resultCode, data));\n    }\n  }\n```\n\n## Testing\n\nTesting in this SDK is accomplished with [Espresso](https://google.github.io/android-testing-support-library/docs/espresso/).\n\nTo run the tests, in Android Studio:\n\nWithin the example package, right-click the androidTest/java folder and click Run 'All Tests'.\n\n## Build + Test\n\nUse [Gradle][] (version 1.x) to build and test the project you can use\n\nGradle:\n\n  ```sh\n  $ cd android-sdk\n  $ gradle test # run tests\n  ```\n\n## Open Source @ IBM\n\nFind more open source projects on the [IBM Github Page](http://ibm.github.io/)\n\n## License\n\nThis library is licensed under Apache 2.0. Full license text is\navailable in [LICENSE](LICENSE).\n\n## Contributing\n\nSee [CONTRIBUTING.md](.github/CONTRIBUTING.md).\n\n[wdc]: https://www.ibm.com/watson/developer/\n[java-sdk]: https://github.com/watson-developer-cloud/java-sdk\n[bluemix]: https://console.bluemix.net\n[Gradle]: http://www.gradle.org/\n[OkHttp]: http://square.github.io/okhttp/\n[gson]: https://github.com/google/gson\n[releases]: https://github.com/watson-developer-cloud/android-sdk/releases\n[wiki]: https://github.com/watson-developer-cloud/android-sdk/wiki\n\n[aar]: https://github.com/watson-developer-cloud/android-sdk/releases/download/v0.6.0/library-release.aar\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fandroid-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatson-developer-cloud%2Fandroid-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fandroid-sdk/lists"}