├── .gitignore
├── .project
├── CONTRIBUTIONS.txt
├── LICENSE.txt
├── README.md
├── build.gradle
├── examples
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── font
│ │ ├── LICENSE.txt
│ │ ├── NotoSans-Bold.ttf
│ │ ├── NotoSans-BoldItalic.ttf
│ │ ├── NotoSans-Italic.ttf
│ │ ├── NotoSans-Regular.ttf
│ │ ├── Roboto-Black.ttf
│ │ ├── Roboto-BlackItalic.ttf
│ │ ├── Roboto-Bold.ttf
│ │ ├── Roboto-BoldItalic.ttf
│ │ ├── Roboto-Italic.ttf
│ │ ├── Roboto-Light.ttf
│ │ ├── Roboto-LightItalic.ttf
│ │ ├── Roboto-Medium.ttf
│ │ ├── Roboto-MediumItalic.ttf
│ │ ├── Roboto-Regular.ttf
│ │ ├── Roboto-Thin.ttf
│ │ ├── Roboto-ThinItalic.ttf
│ │ ├── RobotoCondensed-Bold.ttf
│ │ ├── RobotoCondensed-BoldItalic.ttf
│ │ ├── RobotoCondensed-Italic.ttf
│ │ ├── RobotoCondensed-Light.ttf
│ │ ├── RobotoCondensed-LightItalic.ttf
│ │ └── RobotoCondensed-Regular.ttf
│ ├── ic_launcher_ibm-web.png
│ ├── java
│ └── com
│ │ └── ibm
│ │ └── watson
│ │ └── developer_cloud
│ │ └── android
│ │ └── examples
│ │ ├── CustomTypefaceSpan.java
│ │ └── MainActivity.java
│ ├── res
│ ├── drawable-hdpi
│ │ └── spinner_bg.xml
│ ├── drawable-xhdpi
│ │ └── button_record_stop.xml
│ ├── drawable
│ │ ├── back.xml
│ │ ├── button_record_start.xml
│ │ ├── button_speak.xml
│ │ ├── tab_bar_background.xml
│ │ └── tab_text.xml
│ ├── layout
│ │ ├── activity_tab_text.xml
│ │ ├── tab_stt.xml
│ │ └── tab_tts.xml
│ ├── menu
│ │ └── main.xml
│ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ ├── colors.xml
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ ├── spinner_arrow-web.png
│ └── toremove-web.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── speech-android-wrapper
├── build.gradle
├── libs
├── commons-io-2.4.jar
├── java_websocket.jar
└── jna.jar
├── lint.xml
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── ibm
│ └── watson
│ └── developer_cloud
│ └── android
│ ├── speech_common
│ └── v1
│ │ └── TokenProvider.java
│ ├── speech_to_text
│ └── v1
│ │ ├── ISpeechDelegate.java
│ │ ├── SpeechToText.java
│ │ ├── WatsonSDK.java
│ │ ├── audio
│ │ ├── AudioCaptureThread.java
│ │ ├── AudioFileWriter.java
│ │ ├── IAudioConsumer.java
│ │ ├── IChunkUploader.java
│ │ ├── ISpeechEncoder.java
│ │ ├── OggCrc.java
│ │ ├── OggOpusEnc.java
│ │ ├── PcmWaveWriter.java
│ │ ├── RawEnc.java
│ │ ├── RawWriter.java
│ │ └── WebSocketUploader.java
│ │ ├── dto
│ │ └── SpeechConfiguration.java
│ │ └── opus
│ │ ├── JNAOpus.java
│ │ ├── OggOpus.java
│ │ └── OpusWriter.java
│ └── text_to_speech
│ └── v1
│ ├── TTSUtility.java
│ └── TextToSpeech.java
├── jniLibs
├── arm64-v8a
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
├── armeabi-v7a
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
├── armeabi
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
├── mips
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
├── mips64
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
├── x86
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
└── x86_64
│ ├── libjnidispatch.so
│ ├── libogg.so
│ ├── liboggopus.so
│ ├── libopus.so
│ ├── libspeex.so
│ └── libspeexdsp.so
└── res
├── drawable-hdpi
└── ic_launcher.png
├── drawable-mdpi
└── ic_launcher.png
├── drawable-xhdpi
└── ic_launcher.png
├── mipmap-hdpi
└── ic_launcher.png
├── mipmap-mdpi
└── ic_launcher.png
├── mipmap-xhdpi
└── ic_launcher.png
├── mipmap-xxhdpi
└── ic_launcher.png
├── mipmap-xxxhdpi
└── ic_launcher.png
├── values-v11
└── styles.xml
├── values-v14
└── styles.xml
└── values
└── styles.xml
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # OSX Finder stuff
3 | .DS_Store
4 |
5 | # Build destinations
6 | /build
7 | /examples/build
8 | /speech-android-wrapper/build
9 |
10 | # Built application files
11 | *.apk
12 | *.ap_
13 |
14 | # Files for the ART/Dalvik VM
15 | *.dex
16 |
17 | # Java class files
18 | *.class
19 |
20 | # Generated files
21 | bin/
22 | gen/
23 | out/
24 |
25 | # Gradle files
26 | .gradle/
27 | build/
28 |
29 | # Local configuration file (sdk path, etc)
30 | local.properties
31 |
32 | # Proguard folder generated by Eclipse
33 | proguard/
34 |
35 | # Log Files
36 | *.log
37 |
38 | # Android Studio Navigation editor temp files
39 | .navigation/
40 |
41 | # Android Studio captures folder
42 | captures/
43 |
44 | # IDEA/Android Studio project files, because
45 | # the project can be imported from settings.gradle
46 | .idea
47 | *.iml
48 |
49 | # Old-style IDEA project files
50 | *.ipr
51 | *.iws
52 |
53 | # Local IDEA workspace
54 | .idea/workspace.xml
55 | #.idea/libraries
56 |
57 | # Keystore files
58 | *.jks
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Watson Speech SDK
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CONTRIBUTIONS.txt:
--------------------------------------------------------------------------------
1 | Developer's Certificate of Origin 1.1
2 |
3 | By making a contribution to this project, I certify that:
4 |
5 | (a) The contribution was created in whole or in part by me and I
6 | have the right to submit it under the open source license
7 | indicated in the file; or
8 |
9 | (b) The contribution is based upon previous work that, to the best
10 | of my knowledge, is covered under an appropriate open source
11 | license and I have the right under that license to submit that
12 | work with modifications, whether created in whole or in part
13 | by me, under the same open source license (unless I am
14 | permitted to submit under a different license), as indicated
15 | in the file; or
16 |
17 | (c) The contribution was provided directly to me by some other
18 | person who certified (a), (b) or (c) and I have not modified
19 | it.
20 |
21 | (d) I understand and agree that this project and the contribution
22 | are public and that a record of the contribution (including all
23 | personal information I submit with it, including my sign-off) is
24 | maintained indefinitely and may be redistributed consistent with
25 | this project or the open source license(s) involved.
26 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Watson Speech Android SDK
2 | =====================
3 |
4 | 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.
5 |
6 | The current version of the SDK uses a minSdkVersion of 9, while the example application uses a minSdkVersion of 16.
7 |
8 |
9 | Table of Contents
10 | -----------------
11 | * [Watson Developer Cloud Speech APIs][wdc]
12 |
13 | * [Installation](#installation)
14 |
15 | * [Getting Credentials](#getting-credentials)
16 |
17 | * [A Quick Start Guide](#a-quick-start-guide)
18 |
19 | * [Speech To Text](#speech-to-text)
20 | * [Implement the delegates](#implement-the-speechdelegate-and-speechrecorderdelegate-in-the-mainactivity)
21 | * [Instantiate the SpeechToText instance](#instantiate-the-speechtotext-instance)
22 | * [List supported models](#get-a-list-of-models-supported-by-the-service)
23 | * [Get model details](#get-details-of-a-particular-model)
24 | * [Start Audio Transcription](#start-audio-transcription)
25 | * [End Audio Transcription](#end-audio-transcription)
26 | * [Speech power levels](#receive-speech-power-levels-during-the-recognize)
27 |
28 | * [Text To Speech](#text-to-speech)
29 | * [Instantiate the TextToSpeech instance](#instantiate-the-texttospeech-instance)
30 | * [List supported voices](#get-a-list-of-voices-supported-by-the-service)
31 | * [Generate and play audio](#generate-and-play-audio)
32 |
33 |
34 | Installation
35 | ------------
36 |
37 | **Using the library**
38 |
39 | 1. Download the [speech-android-wrapper.aar](https://github.com/watson-developer-cloud/speech-android-sdk/releases/download/watsonsdk.aar/speech-android-wrapper.aar)
40 | 2. Once unzipped drag the speech-android-wrapper.aar file into your Android Studio project view under the libs folder.
41 | 3. Go to build.gradle file of your app, then set the dependencies as below:
42 |
43 | ```
44 | dependencies {
45 | compile fileTree(dir: 'libs', include: ['*.jar'])
46 | compile (name:'speech-android-wrapper',ext:'aar')
47 | compile 'com.android.support:appcompat-v7:22.0.0'
48 | }
49 | repositories{
50 | flatDir{
51 | dirs 'libs'
52 | }
53 | }
54 | ```
55 |
56 | 4. Clean and run the Android Studio project
57 |
58 |
59 | Getting credentials
60 | --------------------
61 |
62 | 1. Create an account on [Bluemix](https://console.ng.bluemix.net) if you have not already.
63 | 2. Follow instructions at [Service credentials for Watson services](https://www.ibm.com/watson/developercloud/doc/common/getting-started-credentials.html) to get service credentials.
64 |
65 | A Quick Start Guide
66 | --------------------
67 |
68 | To get started, you can also take a look at a [quick start guide](https://github.com/watson-developer-cloud/speech-android-sdk/issues/7#issue-130902950) created by [@KeyOnTech](https://github.com/KeyOnTech).
69 |
70 | Speech To Text
71 | ===============
72 |
73 | Implement the ISpeechDelegate and SpeechRecorderDelegate in the MainActivity
74 | --------------------------------------------------------------------------
75 |
76 | 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.
77 |
78 | ```
79 | public class MainActivity extends Activity implements ISpeechDelegate{}
80 | ```
81 |
82 | Or with SpeechRecorderDelegate
83 |
84 | ```
85 | public class MainActivity extends Activity implements ISpeechDelegate, SpeechRecorderDelegate{}
86 | ```
87 |
88 | Instantiate the SpeechToText instance
89 | -------------------------------------
90 |
91 | ```
92 | SpeechToText.sharedInstance().initWithContext(new URI("wss://stream.watsonplatform.net/speech-to-text/api"), this.getApplicationContext(), new SpeechConfiguration());
93 | ```
94 |
95 | **Enabling audio compression**
96 |
97 | By default audio sent to the server is uncompressed PCM encoded data, compressed audio using the Opus codec can be enabled.
98 | ```
99 | SpeechToText.sharedInstance().initWithContext(this.getHost(STT_URL), this.getApplicationContext(), new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS));
100 | ```
101 | Or this way:
102 | ```
103 | // Configuration
104 | SpeechConfiguration sConfig = new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS);
105 | // STT
106 | SpeechToText.sharedInstance().initWithContext(this.getHost(STT_URL), this.getApplicationContext(), sConfig);
107 | ```
108 |
109 | **Set the Credentials and the delegate**
110 |
111 | ```
112 | SpeechToText.sharedInstance().setCredentials(this.USERNAME,this.PASSWORD);
113 | SpeechToText.sharedInstance().setDelegate(this);
114 | ```
115 |
116 | **Alternatively pass a token factory object to be used by the SDK to retrieve authentication tokens to authenticate against the STT service**
117 |
118 | ```
119 | SpeechToText.sharedInstance().setTokenProvider(new MyTokenProvider(this.strSTTTokenFactoryURL));
120 | SpeechToText.sharedInstance().setDelegate(this);
121 | ```
122 |
123 | Get a list of models supported by the service
124 | ------------------------------
125 |
126 | ```
127 | JSONObject models = getModels();
128 | ```
129 |
130 | Get details of a particular model
131 | ------------------------------
132 |
133 | ```
134 | JSONObject model = getModelInfo("en-US_BroadbandModel");
135 | ```
136 |
137 | Pick the model to be used
138 | ------------------------
139 |
140 | ```
141 | SpeechToText.sharedInstance().setModel("en-US_BroadbandModel");
142 | ```
143 |
144 | Start Audio Transcription
145 | ------------------------------
146 |
147 | ```
148 | SpeechToText.sharedInstance().recognize();
149 | ```
150 |
151 | If you implemented SpeechRecorderDelegate, and needs to process the audio data which is recorded, you can use set the delegate.
152 | ```
153 | SpeechToText.sharedInstance().recognize();
154 | SpeechToText.sharedInstance().setRecorderDelegate(this);
155 | ```
156 |
157 | **Delegate methods to receive messages from the sdk**
158 |
159 | ```
160 | public void onOpen() {
161 | // the connection to the STT service is successfully opened
162 | }
163 |
164 | public void onError(String error) {
165 | // error interacting with the STT service
166 | }
167 |
168 | public void onClose(int code, String reason, boolean remote) {
169 | // the connection with the STT service was just closed
170 | }
171 |
172 | public void onMessage(String message) {
173 | // a message comes from the STT service with recognition results
174 | }
175 | ```
176 |
177 | End Audio Transcription
178 | ------------------------------
179 |
180 | ```
181 | SpeechRecognition.sharedInstance().stopRecording();
182 | ```
183 |
184 | Receive speech power levels during the recognize
185 | ------------------------------
186 | The amplitude is calculated from the audio data buffer, and the volume (in dB) is calculated based on it.
187 |
188 | ```
189 | @Override
190 | public void onAmplitude(double amplitude, double volume) {
191 | // your code here
192 | }
193 | ```
194 |
195 |
196 | Text To Speech
197 | ==============
198 |
199 | Instantiate the TextToSpeech instance
200 | ------------------------------
201 |
202 | ```
203 | TextToSpeech.sharedInstance().initWithContext(this.getHost(TTS_URL));
204 | ```
205 |
206 | **Set the Credentials**
207 |
208 | ```
209 | TextToSpeech.sharedInstance().setCredentials(this.USERNAME,this.PASSWORD);
210 | ```
211 |
212 | **Alternatively pass a token factory object to be used by the SDK to retrieve authentication tokens to authenticate against the TTS service**
213 |
214 | ```
215 | TextToSpeech.sharedInstance().setTokenProvider(new MyTokenProvider(this.strTTSTokenFactoryURL));
216 | ```
217 |
218 | Get a list of voices supported by the service
219 | ------------------------------
220 |
221 | ```
222 | TextToSpeech.sharedInstance().voices();
223 | ```
224 |
225 | Pick the voice to be used
226 | ---------------------------------------------------
227 |
228 | ```
229 | TextToSpeech.sharedInstance().setVoice("en-US_MichaelVoice");
230 | ```
231 |
232 | Generate and play audio
233 | ------------------------------
234 |
235 | ```
236 | TextToSpeech.sharedInstance().synthesize(ttsText);
237 | ```
238 |
239 | Common issues
240 | -------------
241 |
242 |
243 | [wdc]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/apis/#!/speech-to-text
244 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/examples/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 | defaultConfig {
7 | applicationId "com.ibm.watson.developer_cloud.android.examples"
8 | minSdkVersion 16
9 | targetSdkVersion 21
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile project(':speech-android-wrapper')
24 | compile 'com.android.support:appcompat-v7:22.0.0'
25 | }
26 |
--------------------------------------------------------------------------------
/examples/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/examples/src/main/assets/font/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/examples/src/main/assets/font/NotoSans-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/NotoSans-Bold.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/NotoSans-BoldItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/NotoSans-BoldItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/NotoSans-Italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/NotoSans-Italic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/NotoSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/NotoSans-Regular.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Black.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Black.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-BlackItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-BlackItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Bold.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-BoldItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-BoldItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Italic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Light.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-LightItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-LightItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Medium.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-MediumItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-MediumItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-Thin.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-Thin.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/Roboto-ThinItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/Roboto-ThinItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-Bold.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-BoldItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-BoldItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-Italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-Italic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-Light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-Light.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-LightItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-LightItalic.ttf
--------------------------------------------------------------------------------
/examples/src/main/assets/font/RobotoCondensed-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/assets/font/RobotoCondensed-Regular.ttf
--------------------------------------------------------------------------------
/examples/src/main/ic_launcher_ibm-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/ic_launcher_ibm-web.png
--------------------------------------------------------------------------------
/examples/src/main/java/com/ibm/watson/developer_cloud/android/examples/CustomTypefaceSpan.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 |
18 | package com.ibm.watson.developer_cloud.android.examples;
19 |
20 | import android.graphics.Paint;
21 | import android.graphics.Typeface;
22 | import android.text.TextPaint;
23 | import android.text.style.TypefaceSpan;
24 |
25 | public class CustomTypefaceSpan extends TypefaceSpan {
26 |
27 | private final Typeface newType;
28 |
29 | public CustomTypefaceSpan(String family, Typeface type) {
30 | super(family);
31 | newType = type;
32 | }
33 |
34 | @Override
35 | public void updateDrawState(TextPaint ds) {
36 | applyCustomTypeFace(ds, newType);
37 | }
38 |
39 | @Override
40 | public void updateMeasureState(TextPaint paint) {
41 | applyCustomTypeFace(paint, newType);
42 | }
43 |
44 | private static void applyCustomTypeFace(Paint paint, Typeface tf) {
45 | int oldStyle;
46 | Typeface old = paint.getTypeface();
47 | if (old == null) {
48 | oldStyle = 0;
49 | } else {
50 | oldStyle = old.getStyle();
51 | }
52 |
53 | int fake = oldStyle & ~tf.getStyle();
54 | if ((fake & Typeface.BOLD) != 0) {
55 | paint.setFakeBoldText(true);
56 | }
57 |
58 | if ((fake & Typeface.ITALIC) != 0) {
59 | paint.setTextSkewX(-0.25f);
60 | }
61 |
62 | paint.setTypeface(tf);
63 | }
64 | }
--------------------------------------------------------------------------------
/examples/src/main/res/drawable-hdpi/spinner_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
-
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable-xhdpi/button_record_stop.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
10 |
13 |
15 |
20 |
21 |
22 |
23 | -
24 |
25 |
29 |
32 |
34 |
39 |
40 |
41 | -
42 |
43 |
47 |
50 |
52 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable/back.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
9 |
10 |
13 |
14 |
15 |
20 |
21 |
22 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable/button_record_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
10 |
13 |
15 |
20 |
21 |
22 |
23 | -
24 |
25 |
29 |
32 |
34 |
39 |
40 |
41 | -
42 |
43 |
47 |
50 |
52 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable/button_speak.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
10 |
13 |
15 |
20 |
21 |
22 |
23 | -
24 |
25 |
29 |
32 |
34 |
39 |
40 |
41 | -
42 |
43 |
47 |
50 |
52 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable/tab_bar_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
-
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | -
16 |
17 |
18 |
-
19 |
20 |
21 |
22 |
23 |
24 | -
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/examples/src/main/res/drawable/tab_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
9 |
--------------------------------------------------------------------------------
/examples/src/main/res/layout/activity_tab_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/src/main/res/layout/tab_stt.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
27 |
28 |
38 |
39 |
53 |
54 |
66 |
67 |
78 |
79 |
--------------------------------------------------------------------------------
/examples/src/main/res/layout/tab_tts.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
27 |
28 |
38 |
39 |
51 |
52 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/examples/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/examples/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/examples/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/src/main/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/examples/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/src/main/res/values-v14/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #325C80
4 | #121212
5 |
--------------------------------------------------------------------------------
/examples/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
13 |
14 |
17 |
18 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/examples/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/examples/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | IBM Watson Speech SDK
4 | Settings
5 | start recording
6 |
7 | IBM Speech to Text
8 | To get started choose an audio model based on the language you will be speaking. Then press Record to transcribe audio.
9 | IBM Text to Speech
10 | To get started choose a voice that matches the language of the text you will enter below. Enter text and press Speak to hear the results.
11 |
12 |
13 | en-US_BroadbandModel
14 | en-US_MichaelVoice
15 |
16 |
17 | <username>
18 | <password>
19 |
20 |
21 | <username>
22 | <password>
23 |
24 |
25 | <username>
26 | <password>
27 |
28 | <token-factory-url>
29 |
30 |
31 | Conscious of its spiritual and moral heritage, the Union is founded on the indivisible, universal values of human dignity, freedom, equality and solidarity; it is based on the principles of democracy and the rule of law. It places the individual at the heart of its activities, by establishing the citizenship of the Union and by creating an area of freedom, security and justice.
32 | Consciente de su patrimonio espiritual y moral, la Unión está fundada sobre los valores indivisibles y universales de la dignidad humana, la libertad, la igualdad y la solidaridad, y se basa en los principios de la democracia y el Estado de Derecho. Al instituir la ciudadanía de la Unión y crear un espacio de libertad, seguridad y justicia, sitúa a la persona en el centro de su actuación.
33 | Consciente de son patrimoine spirituel et moral, l\'Union se fonde sur les valeurs indivisibles et universelles de dignité humaine, de liberté, d\'égalité et de solidarité; elle repose sur le principe de la démocratie et le principe de l\'État de droit. Elle place la personne au coeur de son action en instituant la citoyenneté de l\'Union et en créant un espace de liberté, de sécurité et de justice.
34 | Consapevole del suo patrimonio spirituale e morale, l\'Unione si fonda sui valori indivisibili e universali della dignità umana, della libertà, dell\'uguaglianza e della solidarietà; essa si basa sul principio della democrazia e sul principio dello Stato di diritto. Pone la persona al centro della sua azione istituendo la cittadinanza dell\'Unione e creando uno spazio di libertà, sicurezza e giustizia.
35 | In dem Bewusstsein ihres geistig-religiösen und sittlichen Erbes gründet sich die Union auf die unteilbaren und universellen Werte der Würde des Menschen, der Freiheit, der Gleichheit und der Solidarität. Sie beruht auf den Grundsätzen der Demokratie und der Rechtsstaatlichkeit. Sie stellt den Menschen in den Mittelpunkt ihres Handelns, indem sie die Unionsbürgerschaft und einen Raum der Freiheit, der Sicherheit und des Rechts begründet.
36 | 精神的、そして道徳的な遺産を意識的に受け継いで、人間の尊厳、自由、平等、連帯の不可分で普遍的な価値を大前提として連合は設立される。すなわち、連合は民主主義と法治の原則に立脚する。連合は市民権を確立し、自由と安全、正義が確保された地域を創造することによって、その組織活動の中心に個人を置く。
37 |
38 |
--------------------------------------------------------------------------------
/examples/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
15 |
16 |
17 |
21 |
22 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/examples/src/main/spinner_arrow-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/spinner_arrow-web.png
--------------------------------------------------------------------------------
/examples/src/main/toremove-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/examples/src/main/toremove-web.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 06 17:14:14 JST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':speech-android-wrapper'
2 | include ':examples'
3 |
--------------------------------------------------------------------------------
/speech-android-wrapper/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion '22.0.1'
6 | defaultConfig {
7 | minSdkVersion 9
8 | targetSdkVersion 16
9 | }
10 | buildTypes {
11 | release {
12 | minifyEnabled false
13 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
14 | }
15 | }
16 | productFlavors {
17 | }
18 | }
19 |
20 | dependencies {
21 | compile files('libs/java_websocket.jar')
22 | compile files('libs/commons-io-2.4.jar')
23 | compile files('libs/jna.jar')
24 | }
25 |
--------------------------------------------------------------------------------
/speech-android-wrapper/libs/commons-io-2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/libs/commons-io-2.4.jar
--------------------------------------------------------------------------------
/speech-android-wrapper/libs/java_websocket.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/libs/java_websocket.jar
--------------------------------------------------------------------------------
/speech-android-wrapper/libs/jna.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/libs/jna.jar
--------------------------------------------------------------------------------
/speech-android-wrapper/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_common/v1/TokenProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_common.v1;
18 |
19 | /**
20 | * Created by daniel bolanos on 8/19/15.
21 | */
22 | public interface TokenProvider {
23 | public String getToken();
24 | }
25 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/ISpeechDelegate.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1;
18 |
19 | public interface ISpeechDelegate {
20 |
21 | /**
22 | * called once the connection with the STT service has been established
23 | */
24 | void onOpen();
25 |
26 | /**
27 | * called if there is an error using the STT service
28 | */
29 | void onError(String error);
30 |
31 | /**
32 | * called once the connection with the STT service has been terminated
33 | */
34 | void onClose(int code, String reason, boolean remote);
35 |
36 | /**
37 | * called every time a data message comes from the STT service
38 | */
39 | void onMessage(String message);
40 |
41 | /**
42 | * Receive the data of amplitude and volume
43 | */
44 | void onAmplitude(double amplitude, double volume);
45 | }
46 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/SpeechToText.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1;
18 |
19 | import java.net.URI;
20 | import java.net.URISyntaxException;
21 | import java.nio.charset.Charset;
22 | import java.util.HashMap;
23 |
24 | import org.java_websocket.util.Base64;
25 |
26 | import android.content.Context;
27 | import android.util.Log;
28 |
29 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.IAudioConsumer;
30 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.AudioCaptureThread;
31 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.dto.SpeechConfiguration;
32 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.WebSocketUploader;
33 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.IChunkUploader;
34 | import com.ibm.watson.developer_cloud.android.speech_common.v1.TokenProvider;
35 |
36 | // HTTP library
37 | import org.apache.http.HttpResponse;
38 | import org.apache.http.auth.UsernamePasswordCredentials;
39 | import org.apache.http.client.HttpClient;
40 | import org.apache.http.client.methods.HttpGet;
41 | import org.apache.http.impl.auth.BasicScheme;
42 | import org.apache.http.impl.client.DefaultHttpClient;
43 |
44 | import org.json.JSONException;
45 | import org.json.JSONObject;
46 |
47 | import java.io.BufferedReader;
48 | import java.io.IOException;
49 | import java.io.InputStream;
50 | import java.io.InputStreamReader;
51 |
52 | /**
53 | * Speech Recognition Class for SDK functions
54 | * @author Viney Ugave (vaugave@us.ibm.com)
55 | */
56 | public class SpeechToText {
57 |
58 | protected static final String TAG = "SpeechToText";
59 | //private String transcript;
60 | private Context appCtx;
61 | private SpeechConfiguration sConfig;
62 | private AudioCaptureThread audioCaptureThread = null;
63 | private IChunkUploader uploader = null;
64 | private ISpeechDelegate delegate = null;
65 | private String username;
66 | private String password;
67 | private String model;
68 | private TokenProvider tokenProvider = null;
69 | private URI hostURL;
70 | /** UPLOADING TIIMEOUT */
71 | //private int UPLOADING_TIMEOUT = 5000; // default duration of closing connection
72 |
73 | /**
74 | * Constructor
75 | */
76 | public SpeechToText() {
77 | this.sConfig = null;
78 | }
79 |
80 | /**
81 | * Speech Recognition Shared Instance
82 | */
83 | private static SpeechToText _instance = null;
84 |
85 | public static SpeechToText sharedInstance(){
86 | if(_instance == null){
87 | synchronized(SpeechToText.class){
88 | _instance = new SpeechToText();
89 | }
90 | }
91 | return _instance;
92 | }
93 |
94 | /**
95 | * Init the shared instance with the context
96 | * @param uri
97 | * @param ctx
98 | * @param sc
99 | */
100 | public void initWithContext(URI uri, Context ctx, SpeechConfiguration sc){
101 | this.setHostURL(uri);
102 | this.appCtx = ctx;
103 | this.sConfig = sc;
104 | }
105 |
106 | /**
107 | * Audio consumer
108 | */
109 | private class STTIAudioConsumer implements IAudioConsumer {
110 | private IChunkUploader mUploader = null;
111 |
112 | public STTIAudioConsumer(IChunkUploader uploader) {
113 | mUploader = uploader;
114 | }
115 |
116 | public void consume(byte [] data) {
117 | mUploader.onHasData(data);
118 | }
119 |
120 | @Override
121 | public void onAmplitude(double amplitude, double volume) {
122 | if(delegate != null){
123 | delegate.onAmplitude(amplitude, volume);
124 | }
125 | }
126 | }
127 |
128 | /**
129 | * Start recording
130 | */
131 | private void startRecording() {
132 | uploader.prepare();
133 | STTIAudioConsumer audioConsumer = new STTIAudioConsumer(uploader);
134 |
135 | audioCaptureThread = new AudioCaptureThread(SpeechConfiguration.SAMPLE_RATE, audioConsumer);
136 | audioCaptureThread.start();
137 | }
138 |
139 | /**
140 | * Start recording audio
141 | */
142 | public void recognize() {
143 | Log.d(TAG, "recognize");
144 | try {
145 | HashMap header = new HashMap();
146 | header.put("Content-Type", sConfig.audioFormat);
147 |
148 | if(sConfig.isAuthNeeded) {
149 | if (this.tokenProvider != null) {
150 | header.put("X-Watson-Authorization-Token", this.tokenProvider.getToken());
151 | Log.d(TAG, "ws connecting with token based authentication");
152 | } else {
153 | String auth = "Basic " + Base64.encodeBytes((this.username + ":" + this.password).getBytes(Charset.forName("UTF-8")));
154 | header.put("Authorization", auth);
155 | Log.d(TAG, "ws connecting with Basic Authentication");
156 | }
157 | }
158 |
159 | if (sConfig.learningOptOut) {
160 | header.put("X-Watson-Learning-OptOut", "true");
161 | Log.d(TAG, "ws setting X-Watson-Learning-OptOut");
162 | }
163 |
164 | String wsURL = getHostURL().toString() + "/v1/recognize" + (this.model != null ? ("?model=" + this.model) : "");
165 |
166 | uploader = new WebSocketUploader(wsURL, header, sConfig);
167 | uploader.setDelegate(this.delegate);
168 | this.startRecording();
169 | } catch (URISyntaxException e) {
170 | e.printStackTrace();
171 | }
172 | }
173 |
174 | /**
175 | * Stop audio recording
176 | */
177 | public void stopRecording(){
178 | if(audioCaptureThread != null)
179 | audioCaptureThread.end();
180 | }
181 |
182 | /**
183 | * Stop recognition
184 | */
185 | public void stopRecognition() {
186 | this.stopRecording();
187 | if(uploader != null) {
188 | uploader.stop();
189 | uploader.close();
190 | }
191 | }
192 |
193 | /**
194 | * Build authentication header
195 | * @param httpGet
196 | */
197 | private void buildAuthenticationHeader(HttpGet httpGet) {
198 | // use token based authentication if possible, otherwise Basic Authentication will be used
199 | if (this.tokenProvider != null) {
200 | Log.d(TAG, "using token based authentication");
201 | httpGet.setHeader("X-Watson-Authorization-Token",this.tokenProvider.getToken());
202 | } else {
203 | Log.d(TAG, "using basic authentication");
204 | httpGet.setHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(this.username, this.password), "UTF-8",false));
205 | }
206 | }
207 |
208 | /**
209 | * Get the list of models for the speech to text service
210 | * @return
211 | */
212 | public JSONObject getModels() {
213 | JSONObject object = null;
214 |
215 | try {
216 | Log.d(TAG, "starting getModels");
217 | HttpClient httpClient = new DefaultHttpClient();
218 | String strHTTPURL = this.hostURL.toString().replace("wss","https").replace("ws", "http");
219 | HttpGet httpGet = new HttpGet(strHTTPURL+"/v1/models");
220 | this.buildAuthenticationHeader(httpGet);
221 | httpGet.setHeader("accept","application/json");
222 | HttpResponse executed = httpClient.execute(httpGet);
223 | InputStream is=executed.getEntity().getContent();
224 |
225 | // get the JSON object containing the models from the InputStream
226 | BufferedReader streamReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
227 | StringBuilder responseStrBuilder = new StringBuilder();
228 | String inputStr;
229 | while ((inputStr = streamReader.readLine()) != null)
230 | responseStrBuilder.append(inputStr);
231 | Log.d(TAG, "response: " + responseStrBuilder.toString());
232 | object = new JSONObject(responseStrBuilder.toString());
233 | Log.d(TAG, object.toString());
234 | } catch (IOException | JSONException e) {
235 | e.printStackTrace();
236 | }
237 | return object;
238 | }
239 |
240 | /**
241 | * Get information about the model
242 | * @param strModel
243 | * @return
244 | */
245 | public JSONObject getModelInfo(String strModel) {
246 | JSONObject object = null;
247 |
248 | try {
249 | HttpClient httpClient = new DefaultHttpClient();
250 | String strHTTPURL = this.hostURL.toString().replace("wss", "https").replace("ws", "http");
251 | HttpGet httpGet = new HttpGet(strHTTPURL+"/v1/models/en-US_NarrowbandModel");
252 | this.buildAuthenticationHeader(httpGet);
253 | httpGet.setHeader("accept","application/json");
254 | HttpResponse executed = httpClient.execute(httpGet);
255 | InputStream is=executed.getEntity().getContent();
256 |
257 | // get the JSON object containing the models from the InputStream
258 | BufferedReader streamReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
259 | StringBuilder responseStrBuilder = new StringBuilder();
260 | String inputStr;
261 | while ((inputStr = streamReader.readLine()) != null)
262 | responseStrBuilder.append(inputStr);
263 | object = new JSONObject(responseStrBuilder.toString());
264 | Log.d(TAG, object.toString());
265 |
266 | } catch (IOException | JSONException e) {
267 | e.printStackTrace();
268 | }
269 | return object;
270 | }
271 |
272 | /**
273 | * @return the hostURL
274 | */
275 | public URI getHostURL() {
276 | return hostURL;
277 | }
278 | /**
279 | * @param hostURL the hostURL to set
280 | */
281 | public void setHostURL(URI hostURL) {
282 | this.hostURL = hostURL;
283 | }
284 | /**
285 | * @return the delegate
286 | */
287 | public ISpeechDelegate getDelegate() {
288 | return delegate;
289 | }
290 | /**
291 | * @param val the delegate to set
292 | */
293 | public void setDelegate(ISpeechDelegate val) {
294 | this.delegate = val;
295 | }
296 | /**
297 | * Set API credentials
298 | * @param username
299 | */
300 | public void setCredentials(String username, String password) {
301 | this.username = username;
302 | this.password = password;
303 | }
304 | /**
305 | * Set token provider (for token based authentication)
306 | */
307 | public void setTokenProvider(TokenProvider tokenProvider) { this.tokenProvider = tokenProvider; }
308 | /**
309 | * Set STT model
310 | */
311 | public void setModel(String model) {
312 | this.model = model;
313 | }
314 | }
315 |
316 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/WatsonSDK.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1;
18 |
19 | import android.app.Application;
20 |
21 | public class WatsonSDK extends Application {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/AudioCaptureThread.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import java.lang.Thread;
20 | import android.util.Log;
21 | import android.media.AudioRecord;
22 | import android.media.*;
23 | import android.media.MediaRecorder.AudioSource;
24 |
25 | import java.nio.ByteBuffer;
26 | import java.nio.ByteOrder;
27 |
28 | /**
29 | * @author Daniel Bolanos dbolano@us.ibm.com
30 | * description: this thread captures audio from the phone's microphone, whenever the buffer
31 | *
32 | */
33 | public class AudioCaptureThread extends Thread {
34 |
35 | private static final String TAG = "AudioCaptureThread";
36 | private boolean mStop = false;
37 | private boolean mStopped = false;
38 | private int mSamplingRate = -1;
39 | private IAudioConsumer mIAudioConsumer = null;
40 |
41 | // the thread receives high priority because it needs to do real time audio capture
42 | // THREAD_PRIORITY_URGENT_AUDIO = "Standard priority of the most important audio threads"
43 | public AudioCaptureThread(int iSamplingRate, IAudioConsumer IAudioConsumer) {
44 | android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
45 | mSamplingRate = iSamplingRate;
46 | mIAudioConsumer = IAudioConsumer;
47 | }
48 |
49 | // once the thread is started it runs nonstop until it is stopped from the outside
50 | @Override
51 | public void run() {
52 | AudioRecord recorder = null;
53 |
54 | try {
55 | int iN = Math.max(mSamplingRate/2,AudioRecord.getMinBufferSize(mSamplingRate,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT));
56 | short[] buffer = new short[iN]; // ASR latency depends on the length of this buffer, a short buffer is good for latency
57 | // because the ASR will process the speech sooner, however it will introduce some network overhead because each packet comes
58 | // with a fixed amount of protocol-data), also I have noticed that some servers cannot handle too many small packages
59 |
60 | // initialize the recorder (buffer size will be at least 1/4th of a second)
61 | recorder = new AudioRecord(AudioSource.MIC, mSamplingRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, iN);
62 | recorder.startRecording();
63 | Log.d(TAG, "recording started!");
64 | while(!mStop) {
65 |
66 | int r = recorder.read(buffer,0,buffer.length);
67 | long v = 0;
68 | for (int i = 0; i < r; i++) {
69 | v += buffer[i] * buffer[i];
70 | }
71 | double amplitude = v / (double) r;
72 | double volume = 0;
73 | if(amplitude > 0)
74 | volume = 10 * Math.log10(amplitude);
75 | mIAudioConsumer.onAmplitude(amplitude, volume);
76 |
77 | // convert to an array of bytes and send it to the server
78 | ByteBuffer bufferBytes = ByteBuffer.allocate(r*2);
79 | bufferBytes.order(ByteOrder.LITTLE_ENDIAN);
80 | bufferBytes.asShortBuffer().put(buffer,0,r);
81 | byte[] bytes = bufferBytes.array();
82 | int length = bytes.length;
83 | mIAudioConsumer.consume(bytes);
84 | }
85 | }
86 | catch(Throwable x) {
87 | Log.e(TAG, "Error reading voice audio", x);
88 | }
89 | // release resources
90 | finally {
91 | if (recorder != null) {
92 | recorder.stop();
93 | recorder.release();
94 | }
95 | mStopped = true;
96 | Log.d(TAG, "recording stopped!");
97 | }
98 | }
99 |
100 | // this function is intended to be called from outside the thread in order to stop the thread
101 | public void end() {
102 | mStop = true;
103 | // waiting loop, it waits until the thread actually finishes
104 | while(!mStopped) {
105 | try {
106 | Thread.sleep(10);
107 | } catch (InterruptedException e) {
108 | e.printStackTrace();
109 | }
110 | };
111 | }
112 | }
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/AudioFileWriter.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * *
3 | * Copyright (c) 1999-2004 Wimba S.A., All Rights Reserved. *
4 | * *
5 | * COPYRIGHT: *
6 | * This software is the property of Wimba S.A. *
7 | * This software is redistributed under the Xiph.org variant of *
8 | * the BSD license. *
9 | * Redistribution and use in source and binary forms, with or without *
10 | * modification, are permitted provided that the following conditions *
11 | * are met: *
12 | * - Redistributions of source code must retain the above copyright *
13 | * notice, this list of conditions and the following disclaimer. *
14 | * - Redistributions in binary form must reproduce the above copyright *
15 | * notice, this list of conditions and the following disclaimer in the *
16 | * documentation and/or other materials provided with the distribution. *
17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of *
18 | * its contributors may be used to endorse or promote products derived *
19 | * from this software without specific prior written permission. *
20 | * *
21 | * WARRANTIES: *
22 | * This software is made available by the authors in the hope *
23 | * that it will be useful, but without any warranty. *
24 | * Wimba S.A. is not liable for any consequence related to the *
25 | * use of the provided software. *
26 | * *
27 | * Class: AudioFileWriter.java *
28 | * *
29 | * Author: Marc GIMPEL *
30 | * *
31 | * Date: 6th January 2004 *
32 | * *
33 | ******************************************************************************/
34 |
35 | /* $Id: AudioFileWriter.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */
36 |
37 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
38 |
39 | import java.io.DataOutput;
40 | import java.io.File;
41 | import java.io.IOException;
42 | import java.io.OutputStream;
43 |
44 | /**
45 | * Abstract Class that defines an Audio File Writer.
46 | *
47 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
48 | * @version $Revision: 1.2 $
49 | */
50 | public abstract class AudioFileWriter{
51 | /**
52 | * Closes the output file.
53 | * @exception IOException if there was an exception closing the Audio Writer.
54 | */
55 | public abstract void close() throws IOException;
56 |
57 | /**
58 | * Open the output file.
59 | * @param file - file to open.
60 | * @exception IOException if there was an exception opening the Audio Writer.
61 | */
62 | public abstract void open(File file) throws IOException;
63 |
64 | /**
65 | * Open the output file.
66 | * @param filename - file to open.
67 | * @exception IOException if there was an exception opening the Audio Writer.
68 | */
69 | public abstract void open(String filename) throws IOException;
70 |
71 | /**
72 | * Writes the header pages that start the Ogg Opus file.
73 | * Prepares file for data to be written.
74 | * @param comment description to be included in the header.
75 | * @exception IOException
76 | */
77 | public abstract void writeHeader(String comment) throws IOException;
78 |
79 | /**
80 | * Writes a packet of audio.
81 | * @param data audio data
82 | * @param offset the offset from which to start reading the data.
83 | * @param len the length of data to read.
84 | * @exception IOException
85 | */
86 | public abstract void writePacket(byte[] data, int offset, int len) throws IOException;
87 |
88 | /**
89 | * Writes an Ogg Page Header to the given byte array.
90 | * @param buf the buffer to write to.
91 | * @param offset the from which to start writing.
92 | * @param headerType the header type flag
93 | * (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
94 | * @param granulepos the absolute granule position.
95 | * @param streamSerialNumber
96 | * @param pageCount
97 | * @param packetCount
98 | * @param packetSizes
99 | * @return the amount of data written to the buffer.
100 | */
101 | public static int writeOggPageHeader(byte[] buf, int offset, int headerType,
102 | long granulepos, int streamSerialNumber,
103 | int pageCount, int packetCount,
104 | byte[] packetSizes)
105 | {
106 | writeString(buf, offset, "OggS"); // 0 - 3: capture_pattern
107 | buf[offset+4] = 0; // 4: stream_structure_version
108 | buf[offset+5] = (byte) headerType; // 5: header_type_flag
109 | writeLong(buf, offset+6, granulepos); // 6 - 13: absolute granule position
110 | writeInt(buf, offset+14, streamSerialNumber); // 14 - 17: stream serial number
111 | writeInt(buf, offset+18, pageCount); // 18 - 21: page sequence no
112 | writeInt(buf, offset+22, 0); // 22 - 25: page checksum
113 | buf[offset+26] = (byte) packetCount; // 26: page_segments
114 | System.arraycopy(packetSizes, 0, // 27 - x: segment_table
115 | buf, offset + 27, packetCount);
116 | return packetCount+27;
117 | }
118 |
119 | /**
120 | * Builds and returns an Ogg Page Header.
121 | * @param headerType the header type flag
122 | * (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
123 | * @param granulepos the absolute granule position.
124 | * @param streamSerialNumber
125 | * @param pageCount
126 | * @param packetCount
127 | * @param packetSizes
128 | * @return an Ogg Page Header.
129 | */
130 | public static byte[] buildOggPageHeader(int headerType, long granulepos,
131 | int streamSerialNumber, int pageCount,
132 | int packetCount, byte[] packetSizes)
133 | {
134 | byte[] data = new byte[packetCount+27];
135 | writeOggPageHeader(data, 0, headerType, granulepos, streamSerialNumber,
136 | pageCount, packetCount, packetSizes);
137 | return data;
138 | }
139 |
140 | /**
141 | * Builds a Opus Header.
142 | *
143 | * @param sampleRate
144 | * @return Opus Header data
145 | */
146 | public static byte[] buildOpusHeader(int sampleRate) {
147 | byte[] data = new byte[19];
148 | writeOpusHeader(data, 0, sampleRate);
149 | return data;
150 | }
151 |
152 | /**
153 | * Write Opus header
154 | *
155 | * @param buf
156 | * @param offset
157 | * @param sampleRate
158 | *
159 | * @link https://tools.ietf.org/html/draft-ietf-codec-oggopus-08#section-5.1
160 | */
161 | public static void writeOpusHeader(byte[] buf, int offset, int sampleRate) {
162 | // Magic Signature
163 | writeString(buf, offset, "OpusHead");
164 | buf[offset + 8] = 1; // Version, MUST The version number MUST always be '1' for this version of the encapsulation specification.
165 | buf[offset + 9] = 1; // Output Channel Count
166 | writeShort(buf, offset + 10, 0); // Pre-skip
167 | writeInt(buf, offset + 12, sampleRate); // Input Sample Rate (Hz)
168 | writeShort(buf, offset + 16, 0); // Output Gain (Q7.8 in dB), +/- 128 dB
169 | buf[offset + 18] = 0; // Mapping Family (For channel mapping family 0, this value defaults to C-1 (i.e., 0 for mono and 1 for stereo), and is not coded.)
170 | }
171 |
172 | /**
173 | * Writes a Opus Comment to the given byte array.
174 | *
175 | * @param buf
176 | * the buffer to write to.
177 | * @param offset
178 | * the from which to start writing.
179 | * @param comment
180 | * the comment.
181 | * @return the amount of data written to the buffer.
182 | */
183 | public static void writeOpusComment(byte[] buf, int offset, String comment) {
184 | // Magic Signature
185 | writeString(buf, offset, "OpusTags");
186 | String vendorString = "IBM";
187 | writeInt(buf, offset + 8, vendorString.length()); // Vendor String Length
188 | writeString(buf, offset + 12, vendorString); // Vendor String
189 | writeInt(buf, offset + 20, 1); // User Comment List Length
190 | writeInt(buf, offset + 24, comment.length()); // User Comment #0 String Length
191 | writeString(buf, offset + 28, comment); // User Comment #0 String
192 | }
193 |
194 | /**
195 | * Builds and returns a Opus Comment.
196 | *
197 | * @param comment
198 | * the comment.
199 | * @return a Opus Comment.
200 | */
201 | public static byte[] buildOpusComment(String comment) {
202 | byte[] data = new byte[28+comment.length()];
203 | writeOpusComment(data, 0, comment);
204 | return data;
205 | }
206 |
207 | /**
208 | * Writes a Little-endian short.
209 | * @param out the data output to write to.
210 | * @param v value to write.
211 | * @exception IOException
212 | */
213 | public static void writeShort(DataOutput out, short v)
214 | throws IOException
215 | {
216 | out.writeByte((0xff & v));
217 | out.writeByte((0xff & (v >>> 8)));
218 | }
219 |
220 | /**
221 | * Writes a Little-endian int.
222 | * @param out the data output to write to.
223 | * @param v value to write.
224 | * @exception IOException
225 | */
226 | public static void writeInt(DataOutput out, int v)
227 | throws IOException
228 | {
229 | out.writeByte(0xff & v);
230 | out.writeByte(0xff & (v >>> 8));
231 | out.writeByte(0xff & (v >>> 16));
232 | out.writeByte(0xff & (v >>> 24));
233 | }
234 |
235 | /**
236 | * Writes a Little-endian short.
237 | * @param os - the output stream to write to.
238 | * @param v - the value to write.
239 | * @exception IOException
240 | */
241 | public static void writeShort(OutputStream os, short v)
242 | throws IOException
243 | {
244 | os.write((0xff & v));
245 | os.write((0xff & (v >>> 8)));
246 | }
247 |
248 | /**
249 | * Writes a Little-endian int.
250 | * @param os - the output stream to write to.
251 | * @param v - the value to write.
252 | * @exception IOException
253 | */
254 | public static void writeInt(OutputStream os, int v)
255 | throws IOException
256 | {
257 | os.write(0xff & v);
258 | os.write(0xff & (v >>> 8));
259 | os.write(0xff & (v >>> 16));
260 | os.write(0xff & (v >>> 24));
261 | }
262 |
263 | /**
264 | * Writes a Little-endian long.
265 | * @param os - the output stream to write to.
266 | * @param v - the value to write.
267 | * @exception IOException
268 | */
269 | public static void writeLong(OutputStream os, long v)
270 | throws IOException
271 | {
272 | os.write((int)(0xff & v));
273 | os.write((int)(0xff & (v >>> 8)));
274 | os.write((int)(0xff & (v >>> 16)));
275 | os.write((int)(0xff & (v >>> 24)));
276 | os.write((int)(0xff & (v >>> 32)));
277 | os.write((int)(0xff & (v >>> 40)));
278 | os.write((int)(0xff & (v >>> 48)));
279 | os.write((int) (0xff & (v >>> 56)));
280 | }
281 |
282 | /**
283 | * Writes a Little-endian short.
284 | * @param data the array into which the data should be written.
285 | * @param offset the offset from which to start writing in the array.
286 | * @param v the value to write.
287 | */
288 | public static void writeShort(byte[] data, int offset, int v)
289 | {
290 | data[offset] = (byte) (0xff & v);
291 | data[offset+1] = (byte) (0xff & (v >>> 8));
292 | }
293 |
294 | /**
295 | * Writes a Little-endian int.
296 | * @param data the array into which the data should be written.
297 | * @param offset the offset from which to start writing in the array.
298 | * @param v the value to write.
299 | */
300 | public static void writeInt(byte[] data, int offset, int v)
301 | {
302 | data[offset] = (byte) (0xff & v);
303 | data[offset+1] = (byte) (0xff & (v >>> 8));
304 | data[offset+2] = (byte) (0xff & (v >>> 16));
305 | data[offset+3] = (byte) (0xff & (v >>> 24));
306 | }
307 |
308 | /**
309 | * Writes a Little-endian long.
310 | * @param data the array into which the data should be written.
311 | * @param offset the offset from which to start writing in the array.
312 | * @param v the value to write.
313 | */
314 | public static void writeLong(byte[] data, int offset, long v)
315 | {
316 | data[offset] = (byte) (0xff & v);
317 | data[offset+1] = (byte) (0xff & (v >>> 8));
318 | data[offset+2] = (byte) (0xff & (v >>> 16));
319 | data[offset+3] = (byte) (0xff & (v >>> 24));
320 | data[offset+4] = (byte) (0xff & (v >>> 32));
321 | data[offset+5] = (byte) (0xff & (v >>> 40));
322 | data[offset+6] = (byte) (0xff & (v >>> 48));
323 | data[offset+7] = (byte) (0xff & (v >>> 56));
324 | }
325 |
326 | /**
327 | * Writes a String.
328 | * @param data the array into which the data should be written.
329 | * @param offset the offset from which to start writing in the array.
330 | * @param v the value to write.
331 | */
332 | public static void writeString(byte[] data, int offset, String v)
333 | {
334 | byte[] str = v.getBytes();
335 | System.arraycopy(str, 0, data, offset, str.length);
336 | }
337 | }
338 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/IAudioConsumer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | /**
20 | * Created by daniel bolanos on 8/24/15.
21 | */
22 | public interface IAudioConsumer {
23 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
24 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
25 | // function that consumes the audio data
26 | public void consume(byte [] data);
27 | public void onAmplitude(double amplitude, double volume);
28 | }
29 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/IChunkUploader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.ISpeechDelegate;
20 |
21 | /**
22 | * The uploader interface.
23 | */
24 | public interface IChunkUploader {
25 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
26 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
27 | /**
28 | * On has data.
29 | *
30 | * @param buffer the buffer
31 | */
32 | int onHasData(byte[] buffer);
33 | /**
34 | * Checks if uploader has been prepared.
35 | *
36 | * @return true, if uploader is prepared
37 | */
38 | boolean isUploadPrepared();
39 | /**
40 | * Upload data
41 | * @param data
42 | */
43 | void upload(byte[] data);
44 | /**
45 | * Stop uploading
46 | */
47 | void stop();
48 | /**
49 | * Start thread to construct an upload http connection to back end server.
50 | */
51 | void prepare();
52 |
53 | /**
54 | * Set Delegate
55 | *
56 | * @param delegate
57 | */
58 | void setDelegate(ISpeechDelegate delegate);
59 | /**
60 | * Close connection.
61 | */
62 | void close();
63 | }
64 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/ISpeechEncoder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * Encoder interface.
23 | */
24 | public interface ISpeechEncoder {
25 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
26 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
27 | /**
28 | * Init encoder with the WebSocket client
29 | * @param uploader
30 | * @throws IOException
31 | */
32 | void initEncoderWithUploader(IChunkUploader uploader) throws IOException;
33 | /**
34 | * In compression mode, encode audio data (to SPX) before write to ouput stream.
35 | * In non-compression mode, write directly raw audio data to ouput stream.
36 | *
37 | * @param b audio data will be written
38 | * @throws IOException Signals that an I/O exception has occurred.
39 | */
40 | int encodeAndWrite(byte[] b) throws IOException ;
41 | /**
42 | * Get compression audio time in compression mode.
43 | * @return the time for compression audio.
44 | */
45 | void onStart();
46 | /**
47 | * Close output stream.
48 | */
49 | void close();
50 | }
51 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/OggCrc.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * *
3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. *
4 | * *
5 | * COPYRIGHT: *
6 | * This software is the property of Wimba S.A. *
7 | * This software is redistributed under the Xiph.org variant of *
8 | * the BSD license. *
9 | * Redistribution and use in source and binary forms, with or without *
10 | * modification, are permitted provided that the following conditions *
11 | * are met: *
12 | * - Redistributions of source code must retain the above copyright *
13 | * notice, this list of conditions and the following disclaimer. *
14 | * - Redistributions in binary form must reproduce the above copyright *
15 | * notice, this list of conditions and the following disclaimer in the *
16 | * documentation and/or other materials provided with the distribution. *
17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of *
18 | * its contributors may be used to endorse or promote products derived *
19 | * from this software without specific prior written permission. *
20 | * *
21 | * WARRANTIES: *
22 | * This software is made available by the authors in the hope *
23 | * that it will be useful, but without any warranty. *
24 | * Wimba S.A. is not liable for any consequence related to the *
25 | * use of the provided software. *
26 | * *
27 | * Class: OggCrc.java *
28 | * *
29 | * Author: Marc GIMPEL *
30 | * Based on code by: Ross WILLIAMS *
31 | * *
32 | * Date: 20th April 2003 *
33 | * *
34 | ******************************************************************************/
35 |
36 | /* $Id: OggCrc.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */
37 |
38 | /********************************************************************
39 | * *
40 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
41 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
42 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
43 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
44 | * *
45 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
46 | * by the Xiph.Org Foundation http://www.xiph.org/ *
47 | * *
48 | ********************************************************************
49 |
50 | function: code raw [Vorbis] packets into framed OggSquish stream and
51 | decode Ogg streams back into raw packets
52 | last mod: $Id: OggCrc.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $
53 |
54 | note: The CRC code is directly derived from public domain code by
55 | Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
56 | for details.
57 |
58 | ********************************************************************/
59 |
60 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
61 |
62 | /**
63 | * Calculates the CRC checksum for Ogg packets.
64 | *
65 | * Ogg uses the same generator polynomial as ethernet, although with an
66 | * unreflected alg and an init/final of 0, not 0xffffffff.
67 | *
68 | * @author Jim Lawrence, helloNetwork.com
69 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
70 | * @version $Revision: 1.2 $
71 | */
72 | public class OggCrc
73 | {
74 | // TODO - implement java.util.zip.Checksum
75 |
76 | /**
77 | * CRC checksum lookup table
78 | */
79 | private static int[] crc_lookup;
80 |
81 | static {
82 | crc_lookup = new int[256];
83 | for (int i=0; i>>24)&0xff)^(data[offset]&0xff)];
120 | }
121 | return crc;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/OggOpusEnc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.dto.SpeechConfiguration;
20 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.opus.JNAOpus;
21 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.opus.OpusWriter;
22 | import com.sun.jna.ptr.PointerByReference;
23 |
24 | import java.io.ByteArrayInputStream;
25 | import java.io.IOException;
26 | import java.nio.ByteBuffer;
27 | import java.nio.IntBuffer;
28 | import java.nio.ShortBuffer;
29 |
30 | /**
31 | * Ogg Opus Encoder
32 | */
33 | public class OggOpusEnc extends OpusWriter implements ISpeechEncoder {
34 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
35 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
36 | /** Data writer */
37 | private OpusWriter writer = null;
38 | /** Opus encoder reference */
39 | private PointerByReference opusEncoder;
40 | /**
41 | * Constructor
42 | */
43 | public OggOpusEnc() {}
44 | /**
45 | * For WebSocketClient
46 | * @param uploader
47 | * @throws IOException
48 | */
49 | public void initEncoderWithUploader(IChunkUploader uploader) throws IOException{
50 | writer = new OpusWriter(uploader);
51 |
52 | IntBuffer error = IntBuffer.allocate(4);
53 | this.opusEncoder = JNAOpus.INSTANCE.opus_encoder_create(
54 | SpeechConfiguration.SAMPLE_RATE,
55 | SpeechConfiguration.AUDIO_CHANNELS,
56 | JNAOpus.OPUS_APPLICATION_VOIP,
57 | error);
58 | }
59 | /**
60 | * When the encode begins
61 | */
62 | @Override
63 | public void onStart() {
64 | writer.writeHeader("encoder=Lavc56.20.100 libopus");
65 | }
66 | /**
67 | * Encode raw audio data into Opus format then call OpusWriter to write the Ogg packet
68 | *
69 | * @param rawAudio
70 | * @return
71 | * @throws IOException
72 | */
73 | public int encodeAndWrite(byte[] rawAudio) throws IOException {
74 | int uploadedAudioSize = 0;
75 | ByteArrayInputStream ios = new ByteArrayInputStream(rawAudio);
76 |
77 | byte[] data = new byte[SpeechConfiguration.FRAME_SIZE*2];
78 | int bufferSize, read;
79 |
80 | while((read = ios.read(data)) > 0){
81 | bufferSize = read;
82 | byte[] pcmBuffer = new byte[read];
83 | System.arraycopy(data, 0, pcmBuffer, 0, read);
84 |
85 | ShortBuffer shortBuffer = ShortBuffer.allocate(bufferSize);
86 | for (int i = 0; i < read; i += 2) {
87 | int b1 = pcmBuffer[i] & 0xff;
88 | int b2 = pcmBuffer[i+1] << 8;
89 | shortBuffer.put((short) (b1 | b2));
90 | }
91 | shortBuffer.flip();
92 | ByteBuffer opusBuffer = ByteBuffer.allocate(bufferSize);
93 |
94 | int opus_encoded = JNAOpus.INSTANCE.opus_encode(this.opusEncoder, shortBuffer, SpeechConfiguration.FRAME_SIZE, opusBuffer, bufferSize);
95 |
96 | opusBuffer.position(opus_encoded);
97 | opusBuffer.flip();
98 |
99 | byte[] opusData = new byte[opusBuffer.remaining()];
100 | opusBuffer.get(opusData, 0, opusData.length);
101 |
102 | if (opus_encoded > 0) {
103 | uploadedAudioSize += opusData.length;
104 | writer.writePacket(opusData, 0, opusData.length);
105 | }
106 | }
107 |
108 | ios.close();
109 | return uploadedAudioSize;
110 | }
111 | /**
112 | * Close writer
113 | */
114 | public void close() {
115 | try {
116 | writer.close();
117 | JNAOpus.INSTANCE.opus_encoder_destroy(this.opusEncoder);
118 | } catch (IOException e) {
119 | e.printStackTrace();
120 | }
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/PcmWaveWriter.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * *
3 | * Copyright (c) 1999-2003 Wimba S.A., All Rights Reserved. *
4 | * *
5 | * COPYRIGHT: *
6 | * This software is the property of Wimba S.A. *
7 | * This software is redistributed under the Xiph.org variant of *
8 | * the BSD license. *
9 | * Redistribution and use in source and binary forms, with or without *
10 | * modification, are permitted provided that the following conditions *
11 | * are met: *
12 | * - Redistributions of source code must retain the above copyright *
13 | * notice, this list of conditions and the following disclaimer. *
14 | * - Redistributions in binary form must reproduce the above copyright *
15 | * notice, this list of conditions and the following disclaimer in the *
16 | * documentation and/or other materials provided with the distribution. *
17 | * - Neither the name of Wimba, the Xiph.org Foundation nor the names of *
18 | * its contributors may be used to endorse or promote products derived *
19 | * from this software without specific prior written permission. *
20 | * *
21 | * WARRANTIES: *
22 | * This software is made available by the authors in the hope *
23 | * that it will be useful, but without any warranty. *
24 | * Wimba S.A. is not liable for any consequence related to the *
25 | * use of the provided software. *
26 | * *
27 | * Class: PcmWaveWriter.java *
28 | * *
29 | * Author: James LAWRENCE *
30 | * Modified by: Marc GIMPEL *
31 | * *
32 | * Date: March 2003 *
33 | * *
34 | ******************************************************************************/
35 |
36 | /* $Id: PcmWaveWriter.java,v 1.2 2004/10/21 16:21:57 mgimpel Exp $ */
37 |
38 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
39 |
40 | import android.util.Log;
41 |
42 | import java.io.ByteArrayOutputStream;
43 | import java.io.File;
44 | import java.io.IOException;
45 | import java.io.RandomAccessFile;
46 |
47 | /**
48 | * Writes basic PCM wave files from binary audio data.
49 | *
50 | * Here's an example that writes 2 seconds of silence
51 | *
52 | * PcmWaveWriter s_wsw = new PcmWaveWriter(2, 44100);
53 | * byte[] silence = new byte[16*2*44100];
54 | * wsw.Open("C:\\out.wav");
55 | * wsw.WriteHeader();
56 | * wsw.WriteData(silence, 0, silence.length);
57 | * wsw.WriteData(silence, 0, silence.length);
58 | * wsw.Close();
59 | *
60 | *
61 | * @author Jim Lawrence, helloNetwork.com
62 | * @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
63 | * @version $Revision: 1.2 $
64 | */
65 | public class PcmWaveWriter extends AudioFileWriter {
66 |
67 | private static final String TAG = "PcmWaveWriter";
68 |
69 | /** Wave type code of PCM */
70 | public static final short WAVE_FORMAT_PCM = (short) 0x01;
71 | private RandomAccessFile raf;
72 | /** Defines the sampling rate of the audio input. */
73 | private int sampleRate;
74 | /** Defines the number of channels of the audio input (1=mono, 2=stereo). */
75 | private int channels;
76 |
77 | /**
78 | * Constructor.
79 | */
80 | public PcmWaveWriter() {}
81 |
82 | /**
83 | * Constructor.
84 | * @param sampleRate the number of samples per second.
85 | * @param channels the number of audio channels (1=mono, 2=stereo, ...).
86 | */
87 | public PcmWaveWriter(final int sampleRate, final int channels)
88 | {
89 | this();
90 | this.channels = channels;
91 | this.sampleRate = sampleRate;
92 | }
93 |
94 | /**
95 | * Closes the output file.
96 | * MUST be called to have a correct stream.
97 | * @exception IOException if there was an exception closing the Audio Writer.
98 | */
99 | public void close()
100 | throws IOException
101 | {
102 | raf.close();
103 | }
104 |
105 | /**
106 | * Open the output file.
107 | * @param file - file to open.
108 | * @exception IOException if there was an exception opening the Audio Writer.
109 | */
110 | public void open(final File file)
111 | throws IOException
112 | {
113 | file.delete();
114 | raf = new RandomAccessFile(file, "rw");
115 | }
116 |
117 | /**
118 | * Open the output file.
119 | * @param filename filename to open.
120 | * @exception IOException if there was an exception opening the Audio Writer.
121 | */
122 | public void open(final String filename)
123 | throws IOException
124 | {
125 | open(new File(filename));
126 | }
127 |
128 | /**
129 | * Writes the initial data chunks that start the wave file.
130 | * Prepares file for data samples to written.
131 | * @param comment ignored by the WAV header.
132 | * @exception IOException
133 | */
134 | public void writeHeader(final String comment)
135 | throws IOException
136 | {
137 | /* writes the RIFF chunk indicating wave format */
138 | byte[] chkid = "RIFF".getBytes();
139 | raf.write(chkid, 0, chkid.length);
140 | writeInt(raf, 0); /* total length must be blank */
141 | chkid = "WAVE".getBytes();
142 | raf.write(chkid, 0, chkid.length);
143 |
144 | /* format subchunk: of size 16 */
145 | chkid = "fmt ".getBytes();
146 | raf.write(chkid, 0, chkid.length);
147 |
148 | writeInt(raf, 16); // Size of format chunk
149 | writeShort(raf, WAVE_FORMAT_PCM); // Format tag: PCM
150 | writeShort(raf, (short) channels); // Number of channels
151 | writeInt(raf, sampleRate); // Sampling frequency
152 | writeInt(raf, sampleRate * channels * 2); // Average bytes per second
153 | writeShort(raf, (short) (channels * 2)); // Blocksize of data
154 | writeShort(raf, (short) 16); // Bit per sample
155 | /* write the start of data chunk */
156 | chkid = "data".getBytes();
157 | raf.write(chkid, 0, chkid.length);
158 | writeInt(raf, 0);
159 | }
160 |
161 | /**
162 | * Saves PCM data to WAV file
163 | * @param pcmdata
164 | * : byte array containing the PCM data
165 | * @param srate
166 | * : Sample rate
167 | * @param channel
168 | * : no. of channels
169 | * @param format
170 | * : PCM format (16 bit)
171 | * @throws IOException
172 | */
173 | public byte[] saveWav(byte[] pcmdata, int srate, int channel, int format) {
174 |
175 | byte[] header = new byte[44];
176 | byte[] data = pcmdata;
177 |
178 | long totalDataLen = data.length + 36;
179 | long bitrate = srate * channel * format;
180 |
181 | header[0] = 'R';
182 | header[1] = 'I';
183 | header[2] = 'F';
184 | header[3] = 'F';
185 | header[4] = (byte) (totalDataLen & 0xff);
186 | header[5] = (byte) ((totalDataLen >> 8) & 0xff);
187 | header[6] = (byte) ((totalDataLen >> 16) & 0xff);
188 | header[7] = (byte) ((totalDataLen >> 24) & 0xff);
189 | header[8] = 'W';
190 | header[9] = 'A';
191 | header[10] = 'V';
192 | header[11] = 'E';
193 | header[12] = 'f';
194 | header[13] = 'm';
195 | header[14] = 't';
196 | header[15] = ' ';
197 | header[16] = (byte) format;
198 | header[17] = 0;
199 | header[18] = 0;
200 | header[19] = 0;
201 | header[20] = 1;
202 | header[21] = 0;
203 | header[22] = (byte) channel;
204 | header[23] = 0;
205 | header[24] = (byte) (srate & 0xff);
206 | header[25] = (byte) ((srate >> 8) & 0xff);
207 | header[26] = (byte) ((srate >> 16) & 0xff);
208 | header[27] = (byte) ((srate >> 24) & 0xff);
209 | header[28] = (byte) ((bitrate / 8) & 0xff);
210 | header[29] = (byte) (((bitrate / 8) >> 8) & 0xff);
211 | header[30] = (byte) (((bitrate / 8) >> 16) & 0xff);
212 | header[31] = (byte) (((bitrate / 8) >> 24) & 0xff);
213 | header[32] = (byte) ((channel * format) / 8);
214 | header[33] = 0;
215 | header[34] = 16;
216 | header[35] = 0;
217 | header[36] = 'd';
218 | header[37] = 'a';
219 | header[38] = 't';
220 | header[39] = 'a';
221 | header[40] = (byte) (data.length & 0xff);
222 | header[41] = (byte) ((data.length >> 8) & 0xff);
223 | header[42] = (byte) ((data.length >> 16) & 0xff);
224 | header[43] = (byte) ((data.length >> 24) & 0xff);
225 |
226 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
227 | try {
228 | outputStream.write(header);
229 | outputStream.write(data);
230 |
231 | } catch (IOException e) {
232 | Log.e(TAG, "Error writing data to wav buffer");
233 | e.printStackTrace();
234 | }
235 | return outputStream.toByteArray();
236 | }
237 |
238 | /**
239 | * Saves PCM data to WAV file
240 | * @param pcmdata
241 | * : byte array containing the PCM data
242 | * @param srate
243 | * : Sample rate
244 | * @param channel
245 | * : no. of channels
246 | * @param format
247 | * : PCM format (16 bit)
248 | * @throws IOException
249 | */
250 | public void saveWavFile(byte[] pcmdata, int srate, int channel, int format) {
251 |
252 | byte[] header = new byte[44];
253 | byte[] data = pcmdata;
254 |
255 | long totalDataLen = data.length + 36;
256 | long bitrate = srate * channel * format;
257 |
258 | header[0] = 'R';
259 | header[1] = 'I';
260 | header[2] = 'F';
261 | header[3] = 'F';
262 | header[4] = (byte) (totalDataLen & 0xff);
263 | header[5] = (byte) ((totalDataLen >> 8) & 0xff);
264 | header[6] = (byte) ((totalDataLen >> 16) & 0xff);
265 | header[7] = (byte) ((totalDataLen >> 24) & 0xff);
266 | header[8] = 'W';
267 | header[9] = 'A';
268 | header[10] = 'V';
269 | header[11] = 'E';
270 | header[12] = 'f';
271 | header[13] = 'm';
272 | header[14] = 't';
273 | header[15] = ' ';
274 | header[16] = (byte) format;
275 | header[17] = 0;
276 | header[18] = 0;
277 | header[19] = 0;
278 | header[20] = 1;
279 | header[21] = 0;
280 | header[22] = (byte) channel;
281 | header[23] = 0;
282 | header[24] = (byte) (srate & 0xff);
283 | header[25] = (byte) ((srate >> 8) & 0xff);
284 | header[26] = (byte) ((srate >> 16) & 0xff);
285 | header[27] = (byte) ((srate >> 24) & 0xff);
286 | header[28] = (byte) ((bitrate / 8) & 0xff);
287 | header[29] = (byte) (((bitrate / 8) >> 8) & 0xff);
288 | header[30] = (byte) (((bitrate / 8) >> 16) & 0xff);
289 | header[31] = (byte) (((bitrate / 8) >> 24) & 0xff);
290 | header[32] = (byte) ((channel * format) / 8);
291 | header[33] = 0;
292 | header[34] = 16;
293 | header[35] = 0;
294 | header[36] = 'd';
295 | header[37] = 'a';
296 | header[38] = 't';
297 | header[39] = 'a';
298 | header[40] = (byte) (data.length & 0xff);
299 | header[41] = (byte) ((data.length >> 8) & 0xff);
300 | header[42] = (byte) ((data.length >> 16) & 0xff);
301 | header[43] = (byte) ((data.length >> 24) & 0xff);
302 |
303 | try {
304 | raf.write(header, 0, 44);
305 | raf.write(data);
306 | raf.close();
307 | } catch (IOException e) {
308 | Log.e(TAG, "Error writing data to wav file");
309 | e.printStackTrace();
310 | }
311 |
312 | Log.e(TAG, "wrote Wav File");
313 | }
314 |
315 | /**
316 | * Writes a packet of audio.
317 | * @param data audio data
318 | * @param offset the offset from which to start reading the data.
319 | * @param len the length of data to read.
320 | * @exception IOException
321 | */
322 | public void writePacket(final byte[] data,
323 | final int offset,
324 | final int len)
325 | throws IOException
326 | {
327 | raf.write(data, offset, len);
328 | }
329 | }
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/RawEnc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * Raw data encoder
23 | */
24 | public class RawEnc implements ISpeechEncoder {
25 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
26 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
27 | /** Data writer */
28 | private RawWriter writer = null;
29 | /**
30 | * Constructor.
31 | */
32 | public RawEnc() {}
33 | /**
34 | * For WebSocketClient
35 | * @param uploader
36 | * @throws java.io.IOException
37 | */
38 | public void initEncoderWithUploader(IChunkUploader uploader) throws IOException{
39 | this.writer = new RawWriter(uploader);
40 | }
41 | /**
42 | * On encode begin
43 | */
44 | @Override
45 | public void onStart() {}
46 | /* (non-Javadoc)
47 | * @see com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.SpeechEncoder#encodeAndWrite(byte[])
48 | */
49 | @Override
50 | public int encodeAndWrite(byte[] b) throws IOException {
51 | writer.writePacket(b, 0, b.length);
52 | return b.length;
53 | }
54 | /* (non-Javadoc)
55 | * @see com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.SpeechEncoder#close()
56 | */
57 | public void close() {
58 | if(this.writer != null){
59 | try {
60 | this.writer.close();
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/RawWriter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 |
22 |
23 | /**
24 | * @author Viney
25 | *
26 | */
27 | public class RawWriter extends AudioFileWriter{
28 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
29 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
30 | private IChunkUploader uploader;
31 |
32 | /**
33 | * Construct with WebSocketClient
34 | */
35 | public RawWriter(IChunkUploader uploader) {
36 | this.uploader = uploader;
37 | }
38 |
39 | @Override
40 | public void close() throws IOException {
41 | this.uploader.stop();
42 | }
43 |
44 | @Override
45 | public void open(File file) throws IOException {}
46 |
47 |
48 | @Override
49 | public void open(String filename) throws IOException {}
50 |
51 |
52 | @Override
53 | public void writeHeader(String comment) throws IOException {}
54 |
55 | @Override
56 | public void writePacket(byte[] data, int offset, int len) throws IOException {
57 | this.uploader.upload(data);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/audio/WebSocketUploader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 |
18 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio;
19 |
20 | import java.io.IOException;
21 | import java.net.URI;
22 | import java.net.URISyntaxException;
23 | import java.nio.channels.NotYetConnectedException;
24 | import java.security.KeyManagementException;
25 | import java.security.NoSuchAlgorithmException;
26 | import java.security.cert.CertificateException;
27 | import java.security.cert.X509Certificate;
28 | import java.util.Map;
29 |
30 | import javax.net.ssl.SSLContext;
31 | import javax.net.ssl.SSLSocketFactory;
32 | import javax.net.ssl.TrustManager;
33 | import javax.net.ssl.X509TrustManager;
34 |
35 | import org.java_websocket.client.WebSocketClient;
36 | import org.java_websocket.drafts.Draft_17;
37 | import org.java_websocket.handshake.ServerHandshake;
38 | import org.json.JSONException;
39 | import org.json.JSONObject;
40 |
41 | import android.util.Log;
42 |
43 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.dto.SpeechConfiguration;
44 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.ISpeechDelegate;
45 |
46 | public class WebSocketUploader extends WebSocketClient implements IChunkUploader {
47 | // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice.
48 | public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2015";
49 | private static final String TAG = WebSocketUploader.class.getName();
50 |
51 | private ISpeechEncoder encoder = null;
52 | private Thread initStreamToServerThread;
53 |
54 | private boolean uploadPrepared = false;
55 |
56 | /** STT delegate */
57 | private ISpeechDelegate delegate = null;
58 | /** Recorder delegate */
59 | private SpeechConfiguration sConfig = null;
60 |
61 | /**
62 | * Create an uploader which supports streaming.
63 | *
64 | * @param serverURL LMC server, delivery to back end server
65 | * @throws URISyntaxException
66 | */
67 | public WebSocketUploader(String serverURL, Map header, SpeechConfiguration config) throws URISyntaxException {
68 | super(new URI(serverURL), new Draft_17(), header, config.connectionTimeout);
69 | Log.d(TAG, "New WebSocketUploader: " + serverURL);
70 | Log.d(TAG, serverURL);
71 | this.sConfig = config;
72 |
73 | if(sConfig.audioFormat.equals(SpeechConfiguration.AUDIO_FORMAT_DEFAULT)) {
74 | this.encoder = new RawEnc();
75 | }
76 | else if(sConfig.audioFormat.equals(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS)){
77 | this.encoder = new OggOpusEnc();
78 | }
79 |
80 | if(serverURL.toLowerCase().startsWith("wss") || serverURL.toLowerCase().startsWith("https"))
81 | this.sConfig.isSSL = true;
82 | else this.sConfig.isSSL = false;
83 | }
84 | /**
85 | * Trust server
86 | *
87 | * @throws KeyManagementException
88 | * @throws NoSuchAlgorithmException
89 | */
90 | private void trustServer() throws KeyManagementException, NoSuchAlgorithmException, IOException {
91 | // Create a trust manager that does not validate certificate chains
92 | TrustManager[] certs = new TrustManager[]{ new X509TrustManager() {
93 | public java.security.cert.X509Certificate[] getAcceptedIssuers() {
94 | return new java.security.cert.X509Certificate[]{};
95 | }
96 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
97 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
98 | }};
99 | SSLContext sslContext = null;
100 | sslContext = SSLContext.getInstance("TLS");
101 | sslContext.init(null, certs, new java.security.SecureRandom());
102 | SSLSocketFactory factory = sslContext.getSocketFactory();
103 | this.setSocket(factory.createSocket());
104 | }
105 | /**
106 | * 1. Initialize WebSocket connection
107 | * 2. Init an encoder and writer
108 | *
109 | * @throws Exception
110 | */
111 | private void initStreamAudioToServer() throws Exception {
112 | Log.d(TAG, "Connecting...");
113 | //lifted up for initializing writer, using isRunning to control the flow
114 | this.encoder.initEncoderWithUploader(this);
115 |
116 | if(this.sConfig.isSSL)
117 | this.trustServer();
118 |
119 | boolean rc;
120 | rc = this.connectBlocking();
121 |
122 | if (rc) {
123 | Log.d(TAG, "Connected");
124 | this.sendSpeechHeader();
125 | }
126 | else{
127 | Log.e(TAG, "Connection failed!");
128 | this.uploadPrepared = false;
129 | throw new Exception("Connection failed!");
130 | }
131 |
132 | }
133 |
134 | @Override
135 | public int onHasData(byte[] buffer) {
136 | int uploadedAudioSize = 0;
137 | // NOW, WE HAVE STATUS OF UPLOAD PREPARING, UPLOAD PREPARING OK
138 | if (this.isUploadPrepared()) {
139 | try {
140 | uploadedAudioSize = encoder.encodeAndWrite(buffer);
141 | Log.d(TAG, "onHasData: " + uploadedAudioSize + " " + buffer.length);
142 | // TODO: Capturing data
143 | } catch (IOException e) {
144 | e.printStackTrace();
145 | }
146 | }
147 | else {
148 | try {
149 | Log.w(TAG, "waiting for establishing the connection");
150 | initStreamToServerThread.join();
151 | }
152 | catch (InterruptedException e) {
153 | e.printStackTrace();
154 | }
155 | }
156 | return uploadedAudioSize;
157 | }
158 |
159 | @Override
160 | public boolean isUploadPrepared() {
161 | return this.uploadPrepared;
162 | }
163 |
164 | public void stopUploaderPrepareThread() {
165 | if (initStreamToServerThread != null) {
166 | initStreamToServerThread.interrupt();
167 | }
168 | }
169 | /**
170 | * Prepare connection
171 | */
172 | @Override
173 | public void prepare() {
174 | this.uploadPrepared = false;
175 | initStreamToServerThread = new Thread() {
176 | public void run() {
177 | try {
178 | try {
179 | initStreamAudioToServer();
180 | Log.d(TAG, "WebSocket Connection established");
181 | } catch (IOException e1) {
182 | Log.e(TAG, "IOException: " + e1.getMessage());
183 | throw e1;
184 | } catch (InterruptedException e1) {
185 | Log.e(TAG, "InterruptedException:" + e1.getMessage());
186 | throw e1;
187 | } catch (Exception e1) {
188 | Log.e(TAG, "Exception: " + e1.getMessage());
189 | throw e1;
190 | }
191 | } catch (Exception e) {
192 | e.printStackTrace();
193 | Log.e(TAG, "Connection failed: " + (e == null ? "null exception" : e.getMessage()));
194 | uploadPrepared = false;
195 | close();
196 | }
197 | };
198 | };
199 | initStreamToServerThread.setName("initStreamToServerThread");
200 | initStreamToServerThread.start();
201 | }
202 |
203 | /**
204 | * Write string into socket
205 | *
206 | * @param message
207 | */
208 | public void upload(String message){
209 | try{
210 | this.send(message);
211 | }
212 | catch(NotYetConnectedException ex){
213 | Log.e(TAG, ex.getLocalizedMessage());
214 | }
215 | }
216 |
217 | /**
218 | * Write data into socket
219 | *
220 | * @param data
221 | */
222 | public void upload(byte[] data){
223 | try{
224 | this.send(data);
225 | }
226 | catch(NotYetConnectedException ex){
227 | Log.e(TAG, ex.getLocalizedMessage());
228 | }
229 | }
230 |
231 | /**
232 | * Stop by sending out zero byte of data
233 | */
234 | public void stop(){
235 | byte[] stopData = new byte[0];
236 | this.upload(stopData);
237 | }
238 |
239 | @Override
240 | public void close() {
241 | Log.d(TAG, "closing the websocket");
242 | super.close();
243 | }
244 |
245 | @Override
246 | public void onClose(int code, String reason, boolean remote) {
247 | Log.d(TAG, "WebSocket closed");
248 | this.uploadPrepared = false;
249 |
250 | Log.d(TAG, "### Code: " + code + " reason: " + reason + " remote: " + remote);
251 | if (delegate != null){
252 | delegate.onClose(code, reason, remote);
253 | }
254 | }
255 |
256 | @Override
257 | public void onError(Exception ex) {
258 | Log.e(TAG, "WebSocket error");
259 | String errorMessage = "";
260 | if(ex != null)
261 | errorMessage = ex.getMessage();
262 | // Send the error message to the delegate
263 | this.uploadPrepared = false;
264 | //this.sendMessage(ISpeechDelegate.ERROR);
265 | if (delegate != null){
266 | delegate.onError(errorMessage);
267 | }
268 | }
269 |
270 | @Override
271 | public void onMessage(String message) {
272 |
273 | Log.d(TAG + "onMessage", message);
274 | if (delegate != null){
275 | delegate.onMessage(message);
276 | }
277 | }
278 |
279 | @Override
280 | public void onOpen(ServerHandshake arg0) {
281 | Log.d(TAG, "WS connection opened successfully");
282 | this.uploadPrepared = true;
283 | if (delegate != null){
284 | delegate.onOpen();
285 | }
286 | }
287 |
288 | private void sendSpeechHeader() {
289 |
290 | JSONObject obj = new JSONObject();
291 | try {
292 | obj.put("action", "start");
293 | obj.put("content-type", this.sConfig.audioFormat);
294 | obj.put("interim_results", this.sConfig.returnInterimResults);
295 | obj.put("continuous", this.sConfig.continuous);
296 | obj.put("inactivity_timeout", this.sConfig.inactivityTimeout);
297 |
298 | if (this.sConfig.maxAlternatives > 1) {
299 | obj.put("max_alternatives", this.sConfig.maxAlternatives);
300 | }
301 |
302 | if (!(Float.isNaN(this.sConfig.wordAlternativesThreshold))) {
303 | obj.put("word_alternatives_threshold", this.sConfig.wordAlternativesThreshold);
304 | }
305 | } catch (JSONException e) {
306 | e.printStackTrace();
307 | }
308 | String startHeader = obj.toString();
309 | this.upload(startHeader);
310 | this.encoder.onStart();
311 | Log.d(TAG, "Sending init message: " + startHeader);
312 | }
313 |
314 | /**
315 | * Set delegate
316 | *
317 | * @param delegate
318 | */
319 | public void setDelegate(ISpeechDelegate delegate) {
320 | this.delegate = delegate;
321 | }
322 | }
323 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/dto/SpeechConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 |
18 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.dto;
19 |
20 | /**
21 | * Created by mihui on 9/2/15.
22 | */
23 | public class SpeechConfiguration {
24 |
25 | // PCM format
26 | public static final String AUDIO_FORMAT_DEFAULT = "audio/l16;rate=16000";
27 | // OggOpus format
28 | public static final String AUDIO_FORMAT_OGGOPUS = "audio/ogg;codecs=opus";
29 | // Audio channels
30 | public static final int AUDIO_CHANNELS = 1;
31 | // Frame size
32 | public static final int FRAME_SIZE = 160;
33 | // Sample rate
34 | public static final int SAMPLE_RATE = 16000;
35 | // Timeout
36 | public int inactivityTimeout = 600;
37 | // Data format
38 | public String audioFormat = AUDIO_FORMAT_DEFAULT;
39 | // Authentication flag
40 | public boolean isAuthNeeded = true;
41 | // SSL flag, this would be detected automatically
42 | public boolean isSSL = true;
43 | // Default timeout duration for a connection
44 | public int connectionTimeout = 30000;
45 | // Interim results are intermediate hypotheses of a transcription that are likely to change before the service returns the final result. Interim results are useful for real-time transcription, for example, to obtain alternative transcriptions for a dictation application.
46 | public boolean returnInterimResults = true;
47 | // An integer value that tells the service to return the n-best alternative hypotheses
48 | public int maxAlternatives = 1;
49 | // Reports hypotheses for acoustically similar alternatives for words of the input audio
50 | public float wordAlternativesThreshold = Float.NaN;
51 | // Indicates whether multiple final results that represent consecutive phrases separated by long pauses are returned
52 | public boolean continuous = true;
53 | // Indicates whether to opt out of data collection for requests sent over the connection
54 | public boolean learningOptOut = false;
55 |
56 | /**
57 | * Instantiate default configuration
58 | */
59 | public SpeechConfiguration(){}
60 |
61 | /**
62 | * Constructing configuration by parameters
63 | *
64 | * @param audioFormat
65 | */
66 | public SpeechConfiguration(String audioFormat){
67 | this.audioFormat = audioFormat;
68 | }
69 |
70 | /**
71 | * Constructing configuration by parameters
72 | *
73 | * @param audioFormat
74 | * @param isAuthNeeded
75 | */
76 | public SpeechConfiguration(String audioFormat, boolean isAuthNeeded){
77 | this.audioFormat = audioFormat;
78 | this.isAuthNeeded = isAuthNeeded;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/opus/OggOpus.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.opus;
18 |
19 | public class OggOpus {
20 | public static native void initAudio();
21 | public static native void startRecorder( int sample_rate);
22 | public static native void stopRecorder();
23 | public static native int encode( String s, int sample_rate );
24 | public static native int decode( String s, String o, int sample_rate );
25 | public static native float volume();
26 | static {
27 | System.loadLibrary("oggopus");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/speech_to_text/v1/opus/OpusWriter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.speech_to_text.v1.opus;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.util.Random;
22 |
23 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.AudioFileWriter;
24 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.IChunkUploader;
25 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.OggCrc;
26 |
27 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.dto.SpeechConfiguration;
28 |
29 | public class OpusWriter extends AudioFileWriter {
30 | private String TAG = this.getClass().getSimpleName();
31 | private IChunkUploader uploader;
32 | /** Number of packets in an Ogg page (must be less than 255) */
33 | public static final int PACKETS_PER_OGG_PAGE = 50;
34 | /** Defines the sampling rate of the audio input. */
35 | protected int sampleRate;
36 | /** Ogg Stream Serial Number */
37 | protected int streamSerialNumber;
38 | /** Data buffer */
39 | private byte[] dataBuffer;
40 | /** Pointer within the Data buffer */
41 | private int dataBufferPtr;
42 | /** Header buffer */
43 | private byte[] headerBuffer;
44 | /** Pointer within the Header buffer */
45 | private int headerBufferPtr;
46 | /** Ogg Page count */
47 | protected int pageCount;
48 | /** Opus packet count within an Ogg Page */
49 | private int packetCount;
50 | /**
51 | * Absolute granule position
52 | * (the number of audio samples from beginning of file to end of Ogg Packet).
53 | */
54 | private long granulepos;
55 | /** Frame size */
56 | private int frameSize;
57 |
58 | public OpusWriter(){}
59 |
60 | /**
61 | * Setting up the OggOpus Writer
62 | * @param uploader
63 | */
64 | public OpusWriter(IChunkUploader uploader){
65 | this.uploader = uploader;
66 | if (streamSerialNumber == 0)
67 | streamSerialNumber = new Random().nextInt();
68 | dataBuffer = new byte[65565];
69 | dataBufferPtr = 0;
70 | headerBuffer = new byte[255];
71 | headerBufferPtr = 0;
72 | pageCount = 0;
73 | packetCount = 0;
74 | granulepos = 0;
75 | this.sampleRate = SpeechConfiguration.SAMPLE_RATE;
76 | this.frameSize = SpeechConfiguration.FRAME_SIZE;
77 | }
78 | @Override
79 | public void close() throws IOException {
80 | flush(true);
81 | this.uploader.stop();
82 | }
83 |
84 | @Override
85 | public void open(File file) throws IOException {}
86 |
87 | @Override
88 | public void open(String filename) throws IOException {}
89 |
90 | @Override
91 | public void writeHeader(String comment) {
92 | byte[] header;
93 | byte[] data;
94 | int chkSum;
95 |
96 | /* writes the OGG header page */
97 | header = buildOggPageHeader(2, 0, streamSerialNumber, pageCount++, 1, new byte[] {19});
98 | data = buildOpusHeader(sampleRate);
99 | chkSum = OggCrc.checksum(0, header, 0, header.length);
100 | chkSum = OggCrc.checksum(chkSum, data, 0, data.length);
101 | writeInt(header, 22, chkSum);
102 | this.write(header);
103 | this.write(data);
104 |
105 | /* Writes the OGG comment page */
106 | header = buildOggPageHeader(0, 0, streamSerialNumber, pageCount++, 1, new byte[]{(byte) (comment.length() + 8)});
107 | data = buildOpusComment(comment);
108 | chkSum = OggCrc.checksum(0, header, 0, header.length);
109 | chkSum = OggCrc.checksum(chkSum, data, 0, data.length);
110 | writeInt(header, 22, chkSum);
111 | this.write(header);
112 | this.write(data);
113 | }
114 |
115 | /**
116 | * Write data packet
117 | * @param data audio data
118 | * @param offset the offset from which to start reading the data.
119 | * @param len the length of data to read.
120 | * @throws IOException
121 | */
122 | @Override
123 | public void writePacket(byte[] data, int offset, int len)
124 | throws IOException {
125 | // if nothing to write
126 | if (len <= 0) {
127 | return;
128 | }
129 | if (packetCount > PACKETS_PER_OGG_PAGE) {
130 | flush(false);
131 | }
132 | System.arraycopy(data, offset, dataBuffer, dataBufferPtr, len);
133 | dataBufferPtr += len;
134 | headerBuffer[headerBufferPtr++]=(byte)len;
135 | packetCount++;
136 | granulepos += this.frameSize*2;
137 | }
138 |
139 | /**
140 | * Flush the Ogg page out of the buffers into the file.
141 | * @param eos - end of stream
142 | * @exception IOException
143 | */
144 | protected void flush(final boolean eos) throws IOException{
145 | int chksum;
146 | byte[] header;
147 | /* Writes the OGG header page */
148 | header = buildOggPageHeader((eos ? 4 : 0), granulepos, streamSerialNumber, pageCount++, packetCount, headerBuffer);
149 | chksum = OggCrc.checksum(0, header, 0, header.length);
150 | chksum = OggCrc.checksum(chksum, dataBuffer, 0, dataBufferPtr);
151 | writeInt(header, 22, chksum);
152 |
153 | this.write(header);
154 | this.write(dataBuffer, 0, dataBufferPtr);
155 |
156 | dataBufferPtr = 0;
157 | headerBufferPtr = 0;
158 | packetCount = 0;
159 | }
160 |
161 | /**
162 | * Write data into Socket
163 | * @param data
164 | */
165 | public void write(byte[] data){
166 | this.uploader.upload(data);
167 | }
168 |
169 | /**
170 | * Write data into Socket
171 | * @param data
172 | * @param offset
173 | * @param count
174 | */
175 | public void write(byte[] data, int offset, int count){
176 | byte[] tmp = new byte[count];
177 | System.arraycopy(data, offset, tmp, 0, count);
178 |
179 | this.uploader.upload(tmp);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/text_to_speech/v1/TTSUtility.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.text_to_speech.v1;
18 |
19 | import android.app.Application;
20 | import android.media.AudioFormat;
21 | import android.media.AudioManager;
22 | import android.media.AudioTrack;
23 | import android.os.Environment;
24 | import android.util.Log;
25 |
26 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.opus.OggOpus;
27 |
28 | import org.apache.commons.io.IOUtils;
29 | import org.apache.http.HttpResponse;
30 | import org.apache.http.auth.UsernamePasswordCredentials;
31 | import org.apache.http.client.HttpClient;
32 | import org.apache.http.client.methods.HttpGet;
33 | import org.apache.http.client.utils.URLEncodedUtils;
34 | import org.apache.http.impl.auth.BasicScheme;
35 | import org.apache.http.impl.client.DefaultHttpClient;
36 | import org.apache.http.message.BasicNameValuePair;
37 |
38 | import com.ibm.watson.developer_cloud.android.speech_to_text.v1.audio.PcmWaveWriter;
39 |
40 | import java.io.File;
41 |
42 | import java.io.FileNotFoundException;
43 |
44 | import java.io.IOException;
45 | import java.io.InputStream;
46 |
47 | import java.io.RandomAccessFile;
48 |
49 | import java.util.LinkedList;
50 | import java.util.List;
51 |
52 | public class TTSUtility extends Application {
53 | private static final String TAG = TTSUtility.class.getName();
54 |
55 | public static final String CODEC_WAV = "audio/wav";
56 | public static final int CODEC_WAV_SAMPLE_RATE = 0;
57 |
58 | public static final String CODEC_OPUS = "audio/opus";
59 | public static final int CODEC_OPUS_SAMPLE_RATE = 48000;
60 |
61 | private String username;
62 | private String password;
63 | private String token;
64 | private boolean learningOptOut;
65 | private String voice;
66 | private String content;
67 | private String codec;
68 | private int sampleRate;
69 | private String server;
70 | private AudioTrack audioTrack;
71 |
72 |
73 | public TTSUtility(){
74 | this.codec = CODEC_WAV;
75 | // By default, the sample rate would be detected by the SDK if the value is set to zero
76 | // However, the metadata is not reliable, need to decode at the maximum sample rate
77 | this.sampleRate = 48000;
78 | }
79 |
80 | /**
81 | * Set codec
82 | * @param codec
83 | */
84 | public void setCodec(String codec){
85 | this.codec = codec;
86 | }
87 |
88 | /**
89 | * Stop player
90 | */
91 | private void stopTtsPlayer() {
92 | if (audioTrack != null && audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED ) {
93 | // IMPORTANT: NOT use stop()
94 | // For an immediate stop, use pause(), followed by flush() to discard audio data that hasn't been played back yet.
95 | audioTrack.pause();
96 | audioTrack.flush();
97 | }
98 | }
99 |
100 | /**
101 | * Text to speech
102 | * @param arguments
103 | */
104 | public void synthesize(String[] arguments) {
105 | Log.i(TAG, "Start requesting TTS... ("+this.codec+")");
106 | try {
107 | parseParams(arguments);
108 | } catch (Exception e) {
109 | e.printStackTrace();
110 | }
111 |
112 | if(this.codec == CODEC_WAV){
113 | this.sampleRate = CODEC_WAV_SAMPLE_RATE;
114 | }
115 | else{
116 | this.sampleRate = CODEC_OPUS_SAMPLE_RATE;
117 | }
118 |
119 | TTSThread thread = new TTSThread();
120 | thread.setName("TTSThread");
121 | thread.start();
122 | }
123 |
124 | private void initPlayer(){
125 | stopTtsPlayer();
126 | // IMPORTANT: minimum required buffer size for the successful creation of an AudioTrack instance in streaming mode.
127 | int bufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
128 |
129 | synchronized (this) {
130 | audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
131 | sampleRate,
132 | AudioFormat.CHANNEL_OUT_MONO,
133 | AudioFormat.ENCODING_PCM_16BIT,
134 | bufferSize,
135 | AudioTrack.MODE_STREAM);
136 | if (audioTrack != null)
137 | audioTrack.play();
138 | }
139 | }
140 |
141 | private void parseParams(String[] arguments){
142 | int i = 0;
143 | this.server = arguments[i++];
144 | this.username = arguments[i++];
145 | this.password = arguments[i++];
146 | this.voice = arguments[i++];
147 | this.content = arguments[i++];
148 | this.token = arguments[i++];
149 | this.learningOptOut = Boolean.valueOf(arguments[i++]);
150 | }
151 |
152 | /**
153 | * Post text data to the server and get returned audio data
154 | * @param server iTrans server
155 | * @param username
156 | * @param password
157 | * @param content
158 | * @return {@link HttpResponse}
159 | * @throws Exception
160 | */
161 | public static HttpResponse createPost(String server, String username, String password, String token, boolean learningOptOut, String content, String voice, String codec) throws Exception {
162 | String url = server;
163 |
164 | //HTTP GET Client
165 | HttpClient httpClient = new DefaultHttpClient();
166 | //Add params
167 | List params = new LinkedList();
168 | params.add(new BasicNameValuePair("text", content));
169 | params.add(new BasicNameValuePair("voice", voice));
170 | params.add(new BasicNameValuePair("accept", codec));
171 | HttpGet httpGet = new HttpGet(url+"?"+ URLEncodedUtils.format(params, "utf-8"));
172 | // use token based authentication if possible, otherwise Basic Authentication will be used
173 | if (token != null) {
174 | Log.d(TAG, "using token based authentication");
175 | httpGet.setHeader("X-Watson-Authorization-Token",token);
176 | } else {
177 | Log.d(TAG, "using basic authentication");
178 | httpGet.setHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(username, password), "UTF-8", false));
179 | }
180 |
181 | if (learningOptOut) {
182 | Log.d(TAG, "setting X-Watson-Learning-OptOut");
183 | httpGet.setHeader("X-Watson-Learning-Opt-Out", "true");
184 | }
185 | HttpResponse executed = httpClient.execute(httpGet);
186 | return executed;
187 | }
188 |
189 | /**
190 | * Get storage path
191 | * @return
192 | */
193 | private String getBaseDir() {
194 | String baseDir;
195 | if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
196 | baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
197 | } else {
198 | baseDir = "/data/data/" + getApplicationContext().getPackageName() + "/";
199 | }
200 |
201 | return baseDir;
202 | }
203 |
204 | /**
205 | * Thread to post text data to iTrans server and play returned audio data
206 | * @author chienlk
207 | *
208 | */
209 | public class TTSThread extends Thread {
210 | @Override
211 | public void run() {
212 | android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
213 |
214 | HttpResponse post;
215 | try {
216 | post = createPost(server, username, password, token, learningOptOut, content, voice, codec);
217 | InputStream is = post.getEntity().getContent();
218 |
219 | byte[] data = null;
220 | if(codec == CODEC_WAV) {
221 | data = analyzeWavData(is);
222 | }
223 | else if(codec == CODEC_OPUS){
224 | data = analyzeOpusData(is);
225 | }
226 | initPlayer();
227 | audioTrack.write(data, 0, data.length);
228 | is.close();
229 |
230 | } catch (Exception e) {
231 | e.printStackTrace();
232 | } finally {
233 | Log.i(TAG, "Stopping audioTrack...");
234 | if (audioTrack != null && audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED) {
235 | audioTrack.release();
236 | }
237 | }
238 | }
239 | }
240 |
241 | private byte[] analyzeOpusData(InputStream is) {
242 | String inFilePath = getBaseDir()+"Watson.opus";
243 | String outFilePath = getBaseDir()+"Watson.pcm";
244 | File inFile = new File(inFilePath);
245 | File outFile = new File(outFilePath);
246 | outFile.deleteOnExit();
247 | inFile.deleteOnExit();
248 |
249 | try {
250 | RandomAccessFile inRaf = new RandomAccessFile(inFile, "rw");
251 | byte[] opus = IOUtils.toByteArray(is);
252 | inRaf.write(opus);
253 |
254 | sampleRate = OggOpus.decode(inFilePath, outFilePath, sampleRate); // zero means to detect the sample rate by decoder
255 |
256 | RandomAccessFile outRaf = new RandomAccessFile(outFile, "r");
257 |
258 | byte[] data = new byte[(int)outRaf.length()];
259 |
260 | int outLength = outRaf.read(data);
261 |
262 | inRaf.close();
263 | outRaf.close();
264 | if(outLength == 0){
265 | throw new IOException("Data reading failed");
266 | }
267 | return data;
268 | } catch (FileNotFoundException e) {
269 | e.printStackTrace();
270 | } catch (IOException e) {
271 | e.printStackTrace();
272 | }
273 | return new byte[0];
274 | }
275 |
276 | /**
277 | * Analyze sample rate and return the PCM data
278 | * @param i
279 | * @return
280 | */
281 | public byte[] analyzeWavData(InputStream i){
282 | try {
283 | int headSize=44, metaDataSize=48;
284 | byte[] data = IOUtils.toByteArray(i);
285 | if(data.length < headSize){
286 | throw new IOException("Wrong Wav header");
287 | }
288 |
289 | if(this.sampleRate == 0 && data.length > 28) {
290 | this.sampleRate = readInt(data, 24); // 24 is the position of sample rate in wav format
291 | }
292 |
293 | int destPos = headSize + metaDataSize;
294 | int rawLength = data.length - destPos;
295 |
296 | byte[] d = new byte[rawLength];
297 | System.arraycopy(data, destPos, d, 0, rawLength);
298 | return d;
299 | } catch (IOException e) {
300 | Log.e(TAG, "Error while formatting header");
301 | }
302 | return new byte[0];
303 | }
304 |
305 | public byte[] stripHeaderAndSaveWav(InputStream i) {
306 | byte[] d = new byte[0];
307 | try {
308 | int headSize=44;
309 | int metaDataSize=48;
310 | i.skip(headSize+metaDataSize);
311 | d = IOUtils.toByteArray(i);
312 | } catch (IOException e) {
313 | Log.d(TAG,"Error while formatting header");
314 | }
315 | return saveWav(d);
316 | }
317 |
318 | public byte[] saveWav(byte[] d){
319 | PcmWaveWriter wR = new PcmWaveWriter(sampleRate, 1);
320 | return wR.saveWav(d, sampleRate, 1, 16);
321 | }
322 |
323 | void saveWavFile(byte[] d) {
324 | String fileName = getBaseDir() + "a.wav";
325 | try {
326 | PcmWaveWriter wR = new PcmWaveWriter(sampleRate, 1);
327 | wR.open(fileName);
328 | wR.saveWavFile(d,sampleRate,1,16);
329 | wR.close();
330 | Log.i(TAG, "save file OK");
331 | } catch (IOException e) {
332 | Log.d(TAG, "save file FAIL");
333 | e.printStackTrace();
334 | }
335 | }
336 |
337 | /**
338 | * Converts Little Endian (Windows) bytes to an int (Java uses Big Endian).
339 | * @param data the data to read.
340 | * @param offset the offset from which to start reading.
341 | * @return the integer value of the reassembled bytes.
342 | */
343 | protected static int readInt(final byte[] data, final int offset)
344 | {
345 | return (data[offset] & 0xff) |
346 | ((data[offset+1] & 0xff) << 8) |
347 | ((data[offset+2] & 0xff) << 16) |
348 | (data[offset+3] << 24); // no 0xff on the last one to keep the sign
349 | }
350 |
351 | /**
352 | * Converts Little Endian (Windows) bytes to an short (Java uses Big Endian).
353 | * @param data the data to read.
354 | * @param offset the offset from which to start reading.
355 | * @return the integer value of the reassembled bytes.
356 | */
357 | protected static int readShort(final byte[] data, final int offset)
358 | {
359 | return (data[offset] & 0xff) |
360 | (data[offset+1] << 8); // no 0xff on the last one to keep the sign
361 | }
362 | }
363 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/java/com/ibm/watson/developer_cloud/android/text_to_speech/v1/TextToSpeech.java:
--------------------------------------------------------------------------------
1 | /**
2 | * © Copyright IBM Corporation 2015
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | package com.ibm.watson.developer_cloud.android.text_to_speech.v1;
18 |
19 | import android.util.Log;
20 |
21 | import com.ibm.watson.developer_cloud.android.speech_common.v1.TokenProvider;
22 |
23 | import org.apache.http.HttpResponse;
24 | import org.apache.http.auth.UsernamePasswordCredentials;
25 | import org.apache.http.client.HttpClient;
26 | import org.apache.http.client.methods.HttpGet;
27 | import org.apache.http.impl.auth.BasicScheme;
28 | import org.apache.http.impl.client.DefaultHttpClient;
29 |
30 | import org.json.JSONException;
31 | import org.json.JSONObject;
32 |
33 | import java.io.BufferedReader;
34 | import java.io.IOException;
35 | import java.io.InputStream;
36 | import java.io.InputStreamReader;
37 | import java.net.URI;
38 |
39 | /**
40 | * Speech Recognition Class for SDK functions
41 | * @author Viney Ugave (vaugave@us.ibm.com)
42 | */
43 | public class TextToSpeech {
44 | protected static final String TAG = "TextToSpeech";
45 |
46 | private TTSUtility ttsUtility;
47 | private String username;
48 | private String password;
49 | private URI hostURL;
50 | private TokenProvider tokenProvider = null;
51 | private String voice;
52 | private boolean learningOptOut = false;
53 |
54 | /**Speech Recognition Shared Instance
55 | *
56 | */
57 | private static TextToSpeech _instance = null;
58 |
59 | public static TextToSpeech sharedInstance(){
60 | if(_instance == null){
61 | synchronized(TextToSpeech.class){
62 | _instance = new TextToSpeech();
63 | }
64 | }
65 | return _instance;
66 | }
67 |
68 | /**
69 | * Init the shared instance with the context
70 | * @param uri
71 | */
72 | public void initWithContext(URI uri){
73 | this.setHostURL(uri);
74 | }
75 |
76 | /**
77 | * Send request of TTS
78 | * @param ttsString
79 | */
80 | public void synthesize(String ttsString) {
81 | Log.d(TAG, "synthesize called: " + this.hostURL.toString() + "/v1/synthesize");
82 | String[] Arguments = {
83 | this.hostURL.toString()+"/v1/synthesize",
84 | this.username,
85 | this.password,
86 | this.voice,
87 | ttsString,
88 | this.tokenProvider == null ? null : this.tokenProvider.getToken(),
89 | this.learningOptOut ? "true" : null
90 | };
91 | try {
92 | ttsUtility = new TTSUtility();
93 | ttsUtility.setCodec(TTSUtility.CODEC_WAV);
94 | ttsUtility.synthesize(Arguments);
95 | }
96 | catch (Exception e) {
97 | e.printStackTrace();
98 | }
99 | }
100 |
101 | private void buildAuthenticationHeader(HttpGet httpGet) {
102 |
103 | // use token based authentication if possible, otherwise Basic Authentication will be used
104 | if (this.tokenProvider != null) {
105 | Log.d(TAG, "using token based authentication");
106 | httpGet.setHeader("X-Watson-Authorization-Token",this.tokenProvider.getToken());
107 | } else {
108 | Log.d(TAG, "using basic authentication");
109 | httpGet.setHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(this.username, this.password), "UTF-8",false));
110 | }
111 | }
112 |
113 | public JSONObject getVoices() {
114 |
115 | JSONObject object = null;
116 |
117 | try {
118 | HttpClient httpClient = new DefaultHttpClient();
119 | HttpGet httpGet = new HttpGet(this.hostURL+"/v1/voices");
120 | Log.d(TAG,"url: " + this.hostURL+"/v1/voices");
121 | this.buildAuthenticationHeader(httpGet);
122 | httpGet.setHeader("accept", "application/json");
123 | HttpResponse executed = httpClient.execute(httpGet);
124 | InputStream is = executed.getEntity().getContent();
125 |
126 | // get the JSON object containing the models from the InputStream
127 | BufferedReader streamReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
128 | StringBuilder responseStrBuilder = new StringBuilder();
129 | String inputStr;
130 | while ((inputStr = streamReader.readLine()) != null)
131 | responseStrBuilder.append(inputStr);
132 | object = new JSONObject(responseStrBuilder.toString());
133 | Log.d(TAG, object.toString());
134 | } catch (IOException | JSONException e) {
135 | e.printStackTrace();
136 | }
137 |
138 | return object;
139 | }
140 |
141 | /**
142 | * Set credentials
143 | * @param username
144 | * @param password
145 | */
146 | public void setCredentials(String username, String password) {
147 | this.username = username;
148 | this.password = password;
149 | }
150 |
151 | /**
152 | * Set host URL
153 | * @param hostURL
154 | */
155 | public void setHostURL(URI hostURL) {
156 | this.hostURL = hostURL;
157 | }
158 |
159 | /**
160 | * Set token provider (for token based authentication)
161 | */
162 | public void setTokenProvider(TokenProvider tokenProvider) { this.tokenProvider = tokenProvider; }
163 |
164 | /**
165 | * Set TTS voice
166 | */
167 | public void setVoice(String voice) {
168 | this.voice = voice;
169 | }
170 |
171 | /**
172 | * Set X-Watson-Learning-OptOut
173 | * @param optOut
174 | */
175 | public void setLearningOptOut(boolean optOut) { this.learningOptOut = optOut; }
176 | }
177 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/arm64-v8a/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi-v7a/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/armeabi/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/armeabi/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/mips64/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/mips64/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/libjnidispatch.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/libjnidispatch.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/libogg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/libogg.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/liboggopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/liboggopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/libopus.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/libopus.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/libspeex.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/libspeex.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/jniLibs/x86_64/libspeexdsp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/jniLibs/x86_64/libspeexdsp.so
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/speech-android-sdk/149f105c3e82c40b07e49f449fbf54b602de614d/speech-android-wrapper/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/speech-android-wrapper/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------