Search in sources :

Example 16 with Words

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testListWords.

/**
 * Test list words.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testListWords() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String wordsAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/words.json"));
    JsonObject words = new JsonParser().parse(wordsAsStr).getAsJsonObject();
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(id).build();
    Words result = service.listWords(listOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_WORDS, id), request.getPath());
    assertEquals(words.get("words"), GSON.toJsonTree(result.getWords()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Words(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 17 with Words

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testListWordsSort.

/**
 * Test list words with sort order alphabetical.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testListWordsSort() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String wordsAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/words.json"));
    JsonObject words = new JsonParser().parse(wordsAsStr).getAsJsonObject();
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(id).sort(ListWordsOptions.Sort.ALPHABETICAL).build();
    Words result = service.listWords(listOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_WORDS, id) + "?sort=alphabetical", request.getPath());
    assertEquals(words.get("words"), GSON.toJsonTree(result.getWords()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Words(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 18 with Words

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testListWordsTypeSort.

/**
 * Test list words with word type all and sort order alphabetical.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testListWordsTypeSort() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String wordsAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/words.json"));
    JsonObject words = new JsonParser().parse(wordsAsStr).getAsJsonObject();
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(id).sort(ListWordsOptions.Sort.ALPHABETICAL).wordType(ListWordsOptions.WordType.ALL).build();
    Words result = service.listWords(listOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_WORDS, id) + "?word_type=all&sort=alphabetical", request.getPath());
    assertEquals(words.get("words"), GSON.toJsonTree(result.getWords()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Words(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 19 with Words

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.

the class TextToSpeech method getWord.

/**
 * Queries details about a word in a custom voice model.
 *
 * Returns the translation for a single word from the custom model with the specified `customization_id`. The output
 * shows the translation as it is defined in the model. You must use credentials for the instance of the service that
 * owns a model to query information about its words. **Note:** This method is currently a beta release.
 *
 * @param getWordOptions the {@link GetWordOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Translation}
 */
public ServiceCall<Translation> getWord(GetWordOptions getWordOptions) {
    Validator.notNull(getWordOptions, "getWordOptions cannot be null");
    String[] pathSegments = { "v1/customizations", "words" };
    String[] pathParameters = { getWordOptions.customizationId(), getWordOptions.word() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Translation.class));
}
Also used : Translation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 20 with Words

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.

the class TextToSpeech method getVoiceModel.

/**
 * Queries the contents of a custom voice model.
 *
 * Lists all information about the custom voice model with the specified `customization_id`. In addition to metadata
 * such as the name and description of the voice model, the output includes the words in the model and their
 * translations as defined in the model. To see just the metadata for a voice model, use the `GET /v1/customizations`
 * method. You must use credentials for the instance of the service that owns a model to list information about it.
 * **Note:** This method is currently a beta release.
 *
 * @param getVoiceModelOptions the {@link GetVoiceModelOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link VoiceModel}
 */
public ServiceCall<VoiceModel> getVoiceModel(GetVoiceModelOptions getVoiceModelOptions) {
    Validator.notNull(getVoiceModelOptions, "getVoiceModelOptions cannot be null");
    String[] pathSegments = { "v1/customizations" };
    String[] pathParameters = { getVoiceModelOptions.customizationId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(VoiceModel.class));
}
Also used : VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Aggregations

Test (org.junit.Test)20 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)13 Words (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words)12 ListWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions)11 Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)9 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)7 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)6 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)5 Ignore (org.junit.Ignore)5 JsonObject (com.google.gson.JsonObject)4 JsonParser (com.google.gson.JsonParser)4 Translation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation)4 VoiceModel (com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel)4 FileInputStream (java.io.FileInputStream)4 ByteString (okio.ByteString)4 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)3