Search in sources :

Example 21 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 CustomizationsIT method testAddWords.

/**
 * Test add words and list words.
 */
@Test
public void testAddWords() {
    model = createVoiceModel();
    final List<Word> expected = instantiateWords();
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
    service.addWords(addOptions).execute();
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(model.getCustomizationId()).build();
    final Words words = service.listWords(listOptions).execute();
    assertEquals(expected.size(), words.getWords().size());
}
Also used : Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) Words(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 22 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 CustomizationsIT method testUpdateVoiceModelWords.

/**
 * Test update voice model with new name and new custom translations.
 */
@Test
public void testUpdateVoiceModelWords() {
    final String newName = "new test";
    model = createVoiceModel();
    GetVoiceModelOptions getOptions = new GetVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).build();
    model = service.getVoiceModel(getOptions).execute();
    UpdateVoiceModelOptions updateOptions = new UpdateVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).name(newName).words(instantiateWords()).build();
    service.updateVoiceModel(updateOptions).execute();
    final VoiceModel model2 = service.getVoiceModel(getOptions).execute();
    assertModelsEqual(model, model2);
    assertNotEquals(model.getWords(), model2.getWords());
}
Also used : GetVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions) VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) UpdateVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.UpdateVoiceModelOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 23 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 CustomizationsIT method testGetWordJapanese.

/**
 * Test get word for Japanese.
 */
@Test
public void testGetWordJapanese() {
    model = createVoiceModelJapanese();
    final List<Word> expected = instantiateWordsJapanese();
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
    service.addWords(addOptions).execute();
    GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(model.getCustomizationId()).word(expected.get(0).getWord()).build();
    final Translation translation = service.getWord(getOptions).execute();
    assertEquals(expected.get(0).getTranslation(), translation.getTranslation());
    assertEquals(expected.get(0).getPartOfSpeech(), translation.getPartOfSpeech());
}
Also used : Translation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation) Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) GetWordOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 24 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 CustomizationsTest method testUpdateVoiceModelWords.

/**
 * Test update voice model with new words.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testUpdateVoiceModelWords() throws InterruptedException {
    // Create the custom voice model.
    server.enqueue(jsonResponse(voiceModelWords));
    CreateVoiceModelOptions createOptions = new CreateVoiceModelOptions.Builder().name(MODEL_NAME).language(MODEL_LANGUAGE).description(MODEL_DESCRIPTION).build();
    final VoiceModel result = service.createVoiceModel(createOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(CUSTOMIZATION_ID, result.getCustomizationId());
    // Update the custom voice model with new words.
    server.enqueue(new MockResponse().setResponseCode(201));
    UpdateVoiceModelOptions updateOptions = new UpdateVoiceModelOptions.Builder().customizationId(CUSTOMIZATION_ID).name(MODEL_NAME).description(MODEL_DESCRIPTION).words(instantiateWords()).build();
    service.updateVoiceModel(updateOptions).execute();
    final RecordedRequest updateRequest = server.takeRequest();
    assertEquals(String.format(VOICE_MODEL_PATH, CUSTOMIZATION_ID), updateRequest.getPath());
    assertEquals("POST", request.getMethod());
    // Compare expected with actual results.
    server.enqueue(jsonResponse(voiceModelWords));
    GetVoiceModelOptions getOptions = new GetVoiceModelOptions.Builder().customizationId(CUSTOMIZATION_ID).build();
    final VoiceModel getResult = service.getVoiceModel(getOptions).execute();
    final RecordedRequest getRequest = server.takeRequest();
    assertEquals(String.format(VOICE_MODEL_PATH, CUSTOMIZATION_ID), getRequest.getPath());
    assertEquals("GET", getRequest.getMethod());
    assertEquals(voiceModelWords, getResult);
    assertNotNull(voiceModelWords.getWords());
    assertEquals(voiceModelWords.getWords(), getResult.getWords());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) MockResponse(okhttp3.mockwebserver.MockResponse) GetVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions) UpdateVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.UpdateVoiceModelOptions) CreateVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.CreateVoiceModelOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 25 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 CustomizationsTest method testAddWords.

/**
 * Test add words.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testAddWords() throws InterruptedException {
    final List<Word> expected = instantiateWords();
    server.enqueue(new MockResponse().setResponseCode(201));
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(CUSTOMIZATION_ID).words(expected).build();
    service.addWords(addOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(String.format(WORDS_PATH, CUSTOMIZATION_ID), request.getPath());
    assertEquals("POST", request.getMethod());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

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