Skip to content

Commit 65b1679

Browse files
🐛 fix customization id parameter for speech to text
1 parent 6f0f06e commit 65b1679

File tree

7 files changed

+115
-52
lines changed

7 files changed

+115
-52
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechSession;
4040
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechSessionStatus;
4141
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word;
42+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.WordData;
4243
import com.ibm.watson.developer_cloud.speech_to_text.v1.util.MediaTypeUtils;
4344
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback;
4445
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.WebSocketManager;
@@ -65,7 +66,7 @@ public class SpeechToText extends WatsonService {
6566
private static final String ALLOW_OVERRIDE = "allow_override";
6667
private static final String CALLBACK_URL = "callback_url";
6768
private static final String CONTINUOUS = "continuous";
68-
private static final String CUSTOMIZATION_ID = "custormization_id";
69+
private static final String CUSTOMIZATION_ID = "customization_id";
6970
private static final String EVENTS = "events";
7071
private static final String INACTIVITY_TIMEOUT = "inactivity_timeout";
7172
private static final String KEYWORDS = "keywords";
@@ -620,12 +621,12 @@ public ServiceCall<SpeechSessionStatus> getRecognizeStatus(final SpeechSession s
620621
* @param wordName the word name
621622
* @return the words
622623
*/
623-
public ServiceCall<Word> getWord(String customizationId, String wordName) {
624+
public ServiceCall<WordData> getWord(String customizationId, String wordName) {
624625
Validator.notNull(customizationId, "customizationId cannot be null");
625626
Validator.notNull(wordName, "wordName cannot be null");
626627

627628
RequestBuilder requestBuilder = RequestBuilder.get(String.format(PATH_WORD, customizationId, wordName));
628-
return createServiceCall(requestBuilder.build(), ResponseConverterUtils.getObject(Word.class));
629+
return createServiceCall(requestBuilder.build(), ResponseConverterUtils.getObject(WordData.class));
629630
}
630631

631632
/**
@@ -636,14 +637,14 @@ public ServiceCall<Word> getWord(String customizationId, String wordName) {
636637
* @param type the word type. Possible values are: ALL, USER or CORPORA.
637638
* @return the words
638639
*/
639-
public ServiceCall<List<Word>> getWords(String customizationId, Word.Type type) {
640+
public ServiceCall<List<WordData>> getWords(String customizationId, Word.Type type) {
640641
Validator.notNull(customizationId, "customizationId cannot be null");
641642
RequestBuilder requestBuilder = RequestBuilder.get(String.format(PATH_WORDS, customizationId));
642643
if (type != null) {
643644
requestBuilder.query(WORD_TYPE, type.toString().toLowerCase());
644645
}
645646

646-
ResponseConverter<List<Word>> converter = ResponseConverterUtils.getGenericObject(TYPE_WORDS, WORDS);
647+
ResponseConverter<List<WordData>> converter = ResponseConverterUtils.getGenericObject(TYPE_WORDS, WORDS);
647648
return createServiceCall(requestBuilder.build(), converter);
648649
}
649650

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class Corpus extends GenericModel {
2828
*/
2929
public enum Status {
3030

31-
/** The analyzer. */
32-
@SerializedName("analyzed") ANALYZER,
31+
/** The corpus has been successfully analyzed. */
32+
@SerializedName("analyzed") ANALYZED,
3333

34-
/** The being processed. */
34+
/** The corpus is being processed. */
3535
@SerializedName("being_processed") BEING_PROCESSED,
3636

37-
/** The undetermined. */
37+
/** The corpus analysis has encountered a problem. */
3838
@SerializedName("undetermined") UNDETERMINED
3939
}
4040

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ public enum Type {
2929

3030
@SerializedName("display_as")
3131
private String displayAs;
32-
private String error;
3332
@SerializedName("sounds_like")
3433
private List<String> soundsLike;
35-
36-
private List<String> source;
3734
private String word;
3835

3936
/**
@@ -45,16 +42,6 @@ public String getDisplayAs() {
4542
return displayAs;
4643
}
4744

48-
/**
49-
* Gets the error. <br />
50-
* If the service discovered a problem with the custom word's definition.
51-
*
52-
* @return The error
53-
*/
54-
public String getError() {
55-
return error;
56-
}
57-
5845
/**
5946
* Gets the sounds like. An array of pronunciations for the custom word
6047
*
@@ -64,15 +51,6 @@ public List<String> getSoundsLike() {
6451
return soundsLike;
6552
}
6653

67-
/**
68-
* Gets the array of sources that describes how the word was added to the custom model's words resource.
69-
*
70-
* @return The source
71-
*/
72-
public List<String> getSource() {
73-
return source;
74-
}
75-
7654
/**
7755
* Gets the word.
7856
*
@@ -91,15 +69,6 @@ public void setDisplayAs(String displayAs) {
9169
this.displayAs = displayAs;
9270
}
9371

94-
/**
95-
* Sets the error.
96-
*
97-
* @param error The error
98-
*/
99-
public void setError(String error) {
100-
this.error = error;
101-
}
102-
10372
/**
10473
* Sets the sounds like. An array of pronunciations for the custom word.
10574
*
@@ -109,15 +78,6 @@ public void setSoundsLike(List<String> soundsLike) {
10978
this.soundsLike = soundsLike;
11079
}
11180

112-
/**
113-
* Sets the array of sources that describes how the word was added to the custom model's words resource.
114-
*
115-
* @param source The source
116-
*/
117-
public void setSource(List<String> source) {
118-
this.source = source;
119-
}
120-
12181
/**
12282
* Sets the word.
12383
*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;
14+
15+
import java.util.List;
16+
17+
/**
18+
* Represents a {@link Word} with error and source.
19+
*/
20+
public class WordData extends Word {
21+
22+
private String error;
23+
private List<String> source;
24+
25+
/**
26+
* Gets the error. If the service discovered a problem with the custom word's definition.
27+
*
28+
* @return The error
29+
*/
30+
public String getError() {
31+
return error;
32+
}
33+
34+
/**
35+
* Gets the array of sources that describes how the word was added to the custom model's words resource.
36+
*
37+
* @return The source
38+
*/
39+
public List<String> getSource() {
40+
return source;
41+
}
42+
43+
/**
44+
* Sets the error.
45+
*
46+
* @param error The error
47+
*/
48+
public void setError(String error) {
49+
this.error = error;
50+
}
51+
52+
/**
53+
* Sets the array of sources that describes how the word was added to the custom model's words resource.
54+
*
55+
* @param source The source
56+
*/
57+
public void setSource(List<String> source) {
58+
this.source = source;
59+
}
60+
61+
}

tests/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Transcript;
4747
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word;
4848
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word.Type;
49+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.WordData;
4950
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback;
5051

5152
/**
@@ -384,7 +385,7 @@ public void testAddTextToCorpus() {
384385
*/
385386
@Test
386387
public void testGetWords() {
387-
List<Word> result = service.getWords(customizationId, Type.ALL).execute();
388+
List<WordData> result = service.getWords(customizationId, Type.ALL).execute();
388389
assertNotNull(result);
389390
assertTrue(!result.isEmpty());
390391
}

tests/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@
4141
import com.ibm.watson.developer_cloud.http.HttpMediaType;
4242
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus;
4343
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Customization;
44+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Customization.WordTypeToAdd;
4445
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionJob;
4546
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions;
47+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions.Builder;
4648
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechAlternative;
4749
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechModel;
4850
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;
4951
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechSession;
5052
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Transcript;
5153
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word;
5254
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word.Type;
53-
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.Customization.WordTypeToAdd;
55+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.WordData;
5456
import com.ibm.watson.developer_cloud.speech_to_text.v1.util.MediaTypeUtils;
5557
import com.ibm.watson.developer_cloud.util.GsonSingleton;
5658
import com.ibm.watson.developer_cloud.util.TestUtils;
@@ -259,6 +261,30 @@ public void testRecognize() throws URISyntaxException, InterruptedException {
259261
assertEquals(HttpMediaType.AUDIO_WAV, request.getHeader(CONTENT_TYPE));
260262
}
261263

264+
/**
265+
* Test recognize with customization.
266+
*
267+
* @throws FileNotFoundException the file not found exception
268+
* @throws InterruptedException the interrupted exception
269+
*/
270+
@Test
271+
public void testRecognizeWithCustomization() throws FileNotFoundException, InterruptedException {
272+
String id = "foo";
273+
String recString =
274+
getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/recognition.json"));
275+
JsonObject recognition = new JsonParser().parse(recString).getAsJsonObject();
276+
277+
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(recString));
278+
279+
RecognizeOptions options = new RecognizeOptions.Builder().customizationId(id).build();
280+
SpeechResults result = service.recognize(SAMPLE_WAV, options).execute();
281+
final RecordedRequest request = server.takeRequest();
282+
283+
assertEquals("POST", request.getMethod());
284+
assertEquals(PATH_RECOGNIZE + "?customization_id=" + id, request.getPath());
285+
assertEquals(recognition, GSON.toJsonTree(result));
286+
}
287+
262288
/**
263289
* Test recognize -missing audio file, generate IllegalArgumentException.
264290
*
@@ -583,7 +609,7 @@ public void testGetWords() throws InterruptedException, FileNotFoundException {
583609

584610
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
585611

586-
List<Word> result = service.getWords(id, Type.ALL).execute();
612+
List<WordData> result = service.getWords(id, Type.ALL).execute();
587613
final RecordedRequest request = server.takeRequest();
588614

589615
assertEquals("GET", request.getMethod());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"results": [
3+
{
4+
"alternatives": [
5+
{
6+
"confidence": 0.998,
7+
"transcript": "who is at risk for immune Thrombocytopenia "
8+
}
9+
],
10+
"final": true
11+
}
12+
],
13+
"result_index": 0
14+
}

0 commit comments

Comments
 (0)