Search in sources :

Example 1 with VoiceModel

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

the class TextToSpeech method createVoiceModel.

/**
 * Creates a new custom voice model.
 *
 * Creates a new empty custom voice model. The model is owned by the instance of the service whose credentials are
 * used to create it. **Note:** This method is currently a beta release.
 *
 * @param createVoiceModelOptions the {@link CreateVoiceModelOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link VoiceModel}
 */
public ServiceCall<VoiceModel> createVoiceModel(CreateVoiceModelOptions createVoiceModelOptions) {
    Validator.notNull(createVoiceModelOptions, "createVoiceModelOptions cannot be null");
    String[] pathSegments = { "v1/customizations" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createVoiceModelOptions.name());
    if (createVoiceModelOptions.language() != null) {
        contentJson.addProperty("language", createVoiceModelOptions.language());
    }
    if (createVoiceModelOptions.description() != null) {
        contentJson.addProperty("description", createVoiceModelOptions.description());
    }
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject)

Example 2 with VoiceModel

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

the class CustomizationsIT method testListModelsAfterCreate.

/**
 * Test list models after create.
 */
@Test
public void testListModelsAfterCreate() {
    model = createVoiceModel();
    ListVoiceModelsOptions listOptions = new ListVoiceModelsOptions.Builder().language(model.getLanguage()).build();
    final VoiceModels models = service.listVoiceModels(listOptions).execute();
    VoiceModel model2 = null;
    for (VoiceModel m : models.getCustomizations()) {
        if (m.getCustomizationId().equals(model.getCustomizationId())) {
            model2 = m;
            break;
        }
    }
    assertNotNull(model2);
    assertModelsEqual(model, model2);
}
Also used : VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) ListVoiceModelsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListVoiceModelsOptions) VoiceModels(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModels) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 3 with VoiceModel

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

the class CustomizationsIT method assertModelsEqual.

private void assertModelsEqual(VoiceModel a, VoiceModel b) {
    assertEquals(a.getCustomizationId(), b.getCustomizationId());
    GetVoiceModelOptions getOptionsA = new GetVoiceModelOptions.Builder().customizationId(a.getCustomizationId()).build();
    assertEquals((service.getVoiceModel(getOptionsA).execute()).getName(), b.getName());
    assertEquals((service.getVoiceModel(getOptionsA).execute()).getLanguage(), b.getLanguage());
}
Also used : GetVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions)

Example 4 with VoiceModel

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

the class CustomizationsIT method testGetVoiceModelObject.

/**
 * Test get voice model.
 */
@Test
public void testGetVoiceModelObject() {
    model = createVoiceModel();
    GetVoiceModelOptions getOptions = new GetVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).build();
    final VoiceModel model2 = service.getVoiceModel(getOptions).execute();
    assertNotNull(model2);
    assertModelsEqual(model, model2);
    assertNotNull(model2.getOwner());
    assertNotNull(model2.getCreated());
    assertNotNull(model2.getLastModified());
}
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) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 5 with VoiceModel

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

the class CustomizationsTest method testGetVoiceModel.

/**
 * Test get voice model.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetVoiceModel() throws InterruptedException {
    // Test with customization ID
    server.enqueue(jsonResponse(voiceModelWords));
    GetVoiceModelOptions getOptions = new GetVoiceModelOptions.Builder().customizationId(CUSTOMIZATION_ID).build();
    VoiceModel result = service.getVoiceModel(getOptions).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(String.format(VOICE_MODEL_PATH, CUSTOMIZATION_ID), request.getPath());
    assertEquals("GET", request.getMethod());
    assertEquals(voiceModelWords, result);
    assertNotNull(voiceModelWords.getWords());
    assertEquals(voiceModelWords.getWords(), result.getWords());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions) VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

VoiceModel (com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel)13 GetVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions)10 Test (org.junit.Test)10 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)6 UpdateVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.UpdateVoiceModelOptions)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 CreateVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.CreateVoiceModelOptions)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 ListVoiceModelsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListVoiceModelsOptions)2 VoiceModels (com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModels)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 JsonObject (com.google.gson.JsonObject)1 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)1 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)1 DeleteVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteVoiceModelOptions)1 DeleteWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteWordOptions)1 GetVoiceOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions)1 GetWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions)1 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)1