Skip to content

Commit d7bded0

Browse files
committed
chore(Speech to Text): Add code directly from generator
1 parent 6134419 commit d7bded0

16 files changed

+75
-174
lines changed

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToText.java

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,12 @@
7070
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.UpgradeLanguageModelOptions;
7171
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word;
7272
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words;
73-
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback;
74-
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.SpeechToTextWebSocketListener;
7573
import com.ibm.watson.developer_cloud.util.GsonSingleton;
7674
import com.ibm.watson.developer_cloud.util.RequestUtils;
7775
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
7876
import com.ibm.watson.developer_cloud.util.Validator;
79-
import okhttp3.HttpUrl;
80-
import okhttp3.OkHttpClient;
81-
import okhttp3.Request;
82-
import okhttp3.WebSocket;
83-
84-
import java.util.concurrent.TimeUnit;
77+
import okhttp3.MultipartBody;
78+
import okhttp3.RequestBody;
8579

8680
/**
8781
* The IBM® Speech to Text service provides APIs that use IBM's speech-recognition capabilities to produce
@@ -200,10 +194,10 @@ public ServiceCall<SpeechModels> listModels() {
200194
/**
201195
* Recognize audio.
202196
*
203-
* Sends audio and returns transcription results for a recognition request. Returns only the final results; to enable
204-
* interim results, use the WebSocket API. The service imposes a data size limit of 100 MB. It automatically detects
205-
* the endianness of the incoming audio and, for audio that includes multiple channels, downmixes the audio to
206-
* one-channel mono during transcoding.
197+
* Sends audio and returns transcription results for a recognition request. You can pass a maximum of 100 MB and a
198+
* minimum of 100 bytes of audio with a request. The service automatically detects the endianness of the incoming
199+
* audio and, for audio that includes multiple channels, downmixes the audio to one-channel mono during transcoding.
200+
* The method returns only final results; to enable interim results, use the WebSocket API.
207201
*
208202
* **See also:** [Making a basic HTTP
209203
* request](https://console.bluemix.net/docs/services/speech-to-text/http.html#HTTP-basic).
@@ -218,7 +212,7 @@ public ServiceCall<SpeechModels> listModels() {
218212
*
219213
* **See also:**
220214
* * [Audio transmission](https://console.bluemix.net/docs/services/speech-to-text/input.html#transmission)
221-
* * [Timeouts](https://console.bluemix.net/docs/services/speech-to-text/input.html#timeouts).
215+
* * [Timeouts](https://console.bluemix.net/docs/services/speech-to-text/input.html#timeouts)
222216
*
223217
* ### Audio formats (content types)
224218
*
@@ -248,14 +242,13 @@ public ServiceCall<SpeechModels> listModels() {
248242
*
249243
* **See also:** [Audio formats](https://console.bluemix.net/docs/services/speech-to-text/audio-formats.html).
250244
*
251-
* **Note:** You must pass a content type when using any of the Watson SDKs. The SDKs require the content-type
252-
* parameter for all audio formats.
253-
*
254245
* ### Multipart speech recognition
255246
*
256-
* The method also supports multipart recognition requests. With multipart requests, you pass all audio data as
257-
* multipart form data. You specify some parameters as request headers and query parameters, but you pass JSON
258-
* metadata as form data to control most aspects of the transcription.
247+
* **Note:** The Watson SDKs do not support multipart speech recognition.
248+
*
249+
* The HTTP `POST` method of the service also supports multipart speech recognition. With multipart requests, you pass
250+
* all audio data as multipart form data. You specify some parameters as request headers and query parameters, but you
251+
* pass JSON metadata as form data to control most aspects of the transcription.
259252
*
260253
* The multipart approach is intended for use with browsers for which JavaScript is disabled or when the parameters
261254
* used with the request are greater than the 8 KB limit imposed by most HTTP servers and proxies. You can encounter
@@ -324,59 +317,6 @@ public ServiceCall<SpeechRecognitionResults> recognize(RecognizeOptions recogniz
324317
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(SpeechRecognitionResults.class));
325318
}
326319

327-
/**
328-
* Sends audio and returns transcription results for recognition requests over a WebSocket connection. Requests and
329-
* responses are enabled over a single TCP connection that abstracts much of the complexity of the request to offer
330-
* efficient implementation, low latency, high throughput, and an asynchronous response. By default, only final
331-
* results are returned for any request; to enable interim results, set the interimResults parameter to true.
332-
*
333-
* The service imposes a data size limit of 100 MB per utterance (per recognition request). You can send multiple
334-
* utterances over a single WebSocket connection. The service automatically detects the endianness of the incoming
335-
* audio and, for audio that includes multiple channels, downmixes the audio to one-channel mono during transcoding.
336-
* (For the audio/l16 format, you can specify the endianness.)
337-
*
338-
* @param recognizeOptions the recognize options
339-
* @param callback the {@link RecognizeCallback} instance where results will be sent
340-
* @return the {@link WebSocket}
341-
*/
342-
public WebSocket recognizeUsingWebSocket(RecognizeOptions recognizeOptions, RecognizeCallback callback) {
343-
Validator.notNull(recognizeOptions, "recognizeOptions cannot be null");
344-
Validator.notNull(recognizeOptions.audio(), "audio cannot be null");
345-
Validator.notNull(callback, "callback cannot be null");
346-
347-
HttpUrl.Builder urlBuilder = HttpUrl.parse(getEndPoint() + "/v1/recognize").newBuilder();
348-
349-
if (recognizeOptions.model() != null) {
350-
urlBuilder.addQueryParameter("model", recognizeOptions.model());
351-
}
352-
if (recognizeOptions.customizationId() != null) {
353-
urlBuilder.addQueryParameter("customization_id", recognizeOptions.customizationId());
354-
}
355-
if (recognizeOptions.languageCustomizationId() != null) {
356-
urlBuilder.addQueryParameter("language_customization_id", recognizeOptions.languageCustomizationId());
357-
}
358-
if (recognizeOptions.acousticCustomizationId() != null) {
359-
urlBuilder.addQueryParameter("acoustic_customization_id", recognizeOptions.acousticCustomizationId());
360-
}
361-
if (recognizeOptions.baseModelVersion() != null) {
362-
urlBuilder.addQueryParameter("base_model_version", recognizeOptions.baseModelVersion());
363-
}
364-
if (recognizeOptions.customizationWeight() != null) {
365-
urlBuilder.addQueryParameter("customization_weight",
366-
String.valueOf(recognizeOptions.customizationWeight()));
367-
}
368-
369-
String url = urlBuilder.toString().replace("https://", "wss://");
370-
Request.Builder builder = new Request.Builder().url(url);
371-
372-
setAuthentication(builder);
373-
setDefaultHeaders(builder);
374-
375-
OkHttpClient client = configureHttpClient();
376-
client = client.newBuilder().pingInterval(30, TimeUnit.SECONDS).build();
377-
return client.newWebSocket(builder.build(), new SpeechToTextWebSocketListener(recognizeOptions, callback));
378-
}
379-
380320
/**
381321
* Check a job.
382322
*
@@ -474,8 +414,10 @@ public ServiceCall<RecognitionJobs> checkJobs() {
474414
* * `user_token`
475415
* * `results_ttl`
476416
*
477-
* The service imposes a data size limit of 100 MB. It automatically detects the endianness of the incoming audio and,
478-
* for audio that includes multiple channels, downmixes the audio to one-channel mono during transcoding.
417+
* You can pass a maximum of 100 MB and a minimum of 100 bytes of audio with a request. The service automatically
418+
* detects the endianness of the incoming audio and, for audio that includes multiple channels, downmixes the audio to
419+
* one-channel mono during transcoding. The method returns only final results; to enable interim results, use the
420+
* WebSocket API.
479421
*
480422
* **See also:** [Creating a job](https://console.bluemix.net/docs/services/speech-to-text/async.html#create).
481423
*
@@ -519,9 +461,6 @@ public ServiceCall<RecognitionJobs> checkJobs() {
519461
*
520462
* **See also:** [Audio formats](https://console.bluemix.net/docs/services/speech-to-text/audio-formats.html).
521463
*
522-
* **Note:** You must pass a content type when using any of the Watson SDKs. The SDKs require the content-type
523-
* parameter for all audio formats.
524-
*
525464
* @param createJobOptions the {@link CreateJobOptions} containing the options for the call
526465
* @return a {@link ServiceCall} with a response type of {@link RecognitionJob}
527466
*/
@@ -945,7 +884,11 @@ public ServiceCall<Void> addCorpus(AddCorpusOptions addCorpusOptions) {
945884
if (addCorpusOptions.allowOverwrite() != null) {
946885
builder.query("allow_overwrite", String.valueOf(addCorpusOptions.allowOverwrite()));
947886
}
948-
builder.body(RequestUtils.inputStreamBody(addCorpusOptions.corpusFile(), "text/plain"));
887+
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
888+
multipartBuilder.setType(MultipartBody.FORM);
889+
RequestBody corpusFileBody = RequestUtils.inputStreamBody(addCorpusOptions.corpusFile(), "text/plain");
890+
multipartBuilder.addFormDataPart("corpus_file", addCorpusOptions.corpusFilename(), corpusFileBody);
891+
builder.body(multipartBuilder.build());
949892
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
950893
}
951894

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/AddAudioOptions.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,6 @@ private Builder(AddAudioOptions addAudioOptions) {
129129
public Builder() {
130130
}
131131

132-
/**
133-
* Instantiates a new builder.
134-
*
135-
* @param customizationId the customizationId
136-
* @param audioName the audioName
137-
* @deprecated audioResource and contentType are now required, so this constructor will be removed. Please use
138-
* the constructor with 4 parameters.
139-
*/
140-
public Builder(String customizationId, String audioName) {
141-
this.customizationId = customizationId;
142-
this.audioName = audioName;
143-
}
144-
145132
/**
146133
* Instantiates a new builder with required properties.
147134
*

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/AddCorpusOptions.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@ public String corpusName() {
200200
* Gets the corpusFile.
201201
*
202202
* A plain text file that contains the training data for the corpus. Encode the file in UTF-8 if it contains non-ASCII
203-
* characters; the service assumes UTF-8 encoding if it encounters non-ASCII characters. With the `curl` command, use
204-
* the `--data-binary` option to upload the file for the request.
203+
* characters; the service assumes UTF-8 encoding if it encounters non-ASCII characters.
204+
*
205+
* Make sure that you know the character encoding of the file. You must use that encoding when working with the words
206+
* in the custom language model. For more information, see [Character
207+
* encoding](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#charEncoding).
208+
*
209+
* With the `curl` command, use the `--data-binary` option to upload the file for the request.
205210
*
206211
* @return the corpusFile
207212
*/

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/AddWordOptions.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ public String customizationId() {
179179
/**
180180
* Gets the wordName.
181181
*
182-
* The custom word for the custom language model. When you add or update a custom word with the **Add a custom word**
183-
* method, do not include spaces in the word. Use a `-` (dash) or `_` (underscore) to connect the tokens of compound
184-
* words.
182+
* The custom word that is to be added to or updated in the custom language model. Do not include spaces in the word.
183+
* Use a `-` (dash) or `_` (underscore) to connect the tokens of compound words. URL-encode the word if it includes
184+
* non-ASCII characters. For more information, see [Character
185+
* encoding](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#charEncoding).
185186
*
186187
* @return the wordName
187188
*/
@@ -196,7 +197,7 @@ public String wordName() {
196197
* custom model. Do not include spaces in the word. Use a `-` (dash) or `_` (underscore) to connect the tokens of
197198
* compound words.
198199
*
199-
* Omit this field for the **Add a custom word** method.
200+
* Omit this parameter for the **Add a custom word** method.
200201
*
201202
* @return the word
202203
*/

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/CreateAcousticModelOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public class CreateAcousticModelOptions extends GenericModel {
2222

2323
/**
2424
* The name of the base language model that is to be customized by the new custom acoustic model. The new custom model
25-
* can be used only with the base model that it customizes. To determine whether a base model supports acoustic model
26-
* customization, refer to [Language support for
25+
* can be used only with the base model that it customizes.
26+
*
27+
* To determine whether a base model supports acoustic model customization, refer to [Language support for
2728
* customization](https://console.bluemix.net/docs/services/speech-to-text/custom.html#languageSupport).
2829
*/
2930
public interface BaseModelName {
@@ -175,8 +176,9 @@ public String name() {
175176
* Gets the baseModelName.
176177
*
177178
* The name of the base language model that is to be customized by the new custom acoustic model. The new custom model
178-
* can be used only with the base model that it customizes. To determine whether a base model supports acoustic model
179-
* customization, refer to [Language support for
179+
* can be used only with the base model that it customizes.
180+
*
181+
* To determine whether a base model supports acoustic model customization, refer to [Language support for
180182
* customization](https://console.bluemix.net/docs/services/speech-to-text/custom.html#languageSupport).
181183
*
182184
* @return the baseModelName

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/CreateJobOptions.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ public Builder speakerLabels(Boolean speakerLabels) {
483483
*
484484
* @param customizationId the customizationId
485485
* @return the CreateJobOptions builder
486-
* @deprecated Use the `languageCustomizationId` setter to specify the customization ID (GUID) of a custom
487-
* language model that is to be used with the recognition request. Do not specify both parameters with a request.
488486
*/
489487
public Builder customizationId(String customizationId) {
490488
this.customizationId = customizationId;
@@ -828,7 +826,7 @@ public Boolean profanityFilter() {
828826
* If `true`, the service converts dates, times, series of digits and numbers, phone numbers, currency values, and
829827
* internet addresses into more readable, conventional representations in the final transcript of a recognition
830828
* request. For US English, the service also converts certain keyword strings to punctuation symbols. By default, no
831-
* smart formatting is performed. Applies to US English and Spanish transcription only. See [Smart
829+
* smart formatting is performed. Applies to US English, Japanese, and Spanish transcription only. See [Smart
832830
* formatting](https://console.bluemix.net/docs/services/speech-to-text/output.html#smart_formatting).
833831
*
834832
* @return the smartFormatting
@@ -842,9 +840,10 @@ public Boolean smartFormatting() {
842840
*
843841
* If `true`, the response includes labels that identify which words were spoken by which participants in a
844842
* multi-person exchange. By default, no speaker labels are returned. Setting `speaker_labels` to `true` forces the
845-
* `timestamps` parameter to be `true`, regardless of whether you specify `false` for the parameter. To determine
846-
* whether a language model supports speaker labels, use the **Get models** method and check that the attribute
847-
* `speaker_labels` is set to `true`. See [Speaker
843+
* `timestamps` parameter to be `true`, regardless of whether you specify `false` for the parameter.
844+
*
845+
* To determine whether a language model supports speaker labels, use the **Get a model** method and check that the
846+
* attribute `speaker_labels` is set to `true`. See [Speaker
848847
* labels](https://console.bluemix.net/docs/services/speech-to-text/output.html#speaker_labels).
849848
*
850849
* @return the speakerLabels
@@ -860,8 +859,6 @@ public Boolean speakerLabels() {
860859
* language model that is to be used with the recognition request. Do not specify both parameters with a request.
861860
*
862861
* @return the customizationId
863-
* @deprecated Use the `languageCustomizationId` getter to get the customization ID (GUID) of a custom
864-
* language model that is to be used with the recognition request.
865862
*/
866863
public String customizationId() {
867864
return customizationId;

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/CreateLanguageModelOptions.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public class CreateLanguageModelOptions extends GenericModel {
2222

2323
/**
2424
* The name of the base language model that is to be customized by the new custom language model. The new custom model
25-
* can be used only with the base model that it customizes. To determine whether a base model supports language model
26-
* customization, request information about the base model and check that the attribute `custom_language_model` is set
27-
* to `true`, or refer to [Language support for
25+
* can be used only with the base model that it customizes.
26+
*
27+
* To determine whether a base model supports language model customization, use the **Get a model** method and check
28+
* that the attribute `custom_language_model` is set to `true`. You can also refer to [Language support for
2829
* customization](https://console.bluemix.net/docs/services/speech-to-text/custom.html#languageSupport).
2930
*/
3031
public interface BaseModelName {
@@ -185,9 +186,10 @@ public String name() {
185186
* Gets the baseModelName.
186187
*
187188
* The name of the base language model that is to be customized by the new custom language model. The new custom model
188-
* can be used only with the base model that it customizes. To determine whether a base model supports language model
189-
* customization, request information about the base model and check that the attribute `custom_language_model` is set
190-
* to `true`, or refer to [Language support for
189+
* can be used only with the base model that it customizes.
190+
*
191+
* To determine whether a base model supports language model customization, use the **Get a model** method and check
192+
* that the attribute `custom_language_model` is set to `true`. You can also refer to [Language support for
191193
* customization](https://console.bluemix.net/docs/services/speech-to-text/custom.html#languageSupport).
192194
*
193195
* @return the baseModelName

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/CustomWord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class CustomWord extends GenericModel {
3535
* custom model. Do not include spaces in the word. Use a `-` (dash) or `_` (underscore) to connect the tokens of
3636
* compound words.
3737
*
38-
* Omit this field for the **Add a custom word** method.
38+
* Omit this parameter for the **Add a custom word** method.
3939
*
4040
* @return the word
4141
*/

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/DeleteWordOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public String customizationId() {
115115
/**
116116
* Gets the wordName.
117117
*
118-
* The custom word for the custom language model. When you add or update a custom word with the **Add a custom word**
119-
* method, do not include spaces in the word. Use a `-` (dash) or `_` (underscore) to connect the tokens of compound
120-
* words.
118+
* The custom word that is to be deleted from the custom language model. URL-encode the word if it includes non-ASCII
119+
* characters. For more information, see [Character
120+
* encoding](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#charEncoding).
121121
*
122122
* @return the wordName
123123
*/

speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/GetModelOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class GetModelOptions extends GenericModel {
2222

2323
/**
24-
* The identifier of the model in the form of its name from the output of the **Get models** method.
24+
* The identifier of the model in the form of its name from the output of the **Get a model** method.
2525
*/
2626
public interface ModelId {
2727
/** ar-AR_BroadbandModel. */
@@ -125,7 +125,7 @@ public Builder newBuilder() {
125125
/**
126126
* Gets the modelId.
127127
*
128-
* The identifier of the model in the form of its name from the output of the **Get models** method.
128+
* The identifier of the model in the form of its name from the output of the **Get a model** method.
129129
*
130130
* @return the modelId
131131
*/

0 commit comments

Comments
 (0)