Search in sources :

Example 6 with CustomModel

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

the class TextToSpeechIT method testAddCustomPrompts.

/**
 * Test addCustomPrompts.
 */
@Test
public void testAddCustomPrompts() {
    try {
        CreateCustomModelOptions createCustomModelOptions = new CreateCustomModelOptions.Builder().description("testdescription").name("testname").language(CreateCustomModelOptions.Language.EN_US).build();
        CustomModel customModel = service.createCustomModel(createCustomModelOptions).execute().getResult();
        customizationId = customModel.getCustomizationId();
        PromptMetadata promptMetadata = new PromptMetadata.Builder().promptText("promptText").build();
        File file = new File(RESOURCE + "numbers.wav");
        AddCustomPromptOptions addCustomPromptOptions = new AddCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").metadata(promptMetadata).file(file).build();
        Prompt prompt = service.addCustomPrompt(addCustomPromptOptions).execute().getResult();
        assertNotNull(prompt.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
        service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) File(java.io.File) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 7 with CustomModel

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

the class TextToSpeechIT method testDeleteCustomPrompts.

/**
 * Test deleteCustomPrompts.
 */
@Test
public void testDeleteCustomPrompts() {
    try {
        CreateCustomModelOptions createCustomModelOptions = new CreateCustomModelOptions.Builder().description("testdescription").name("testname").language(CreateCustomModelOptions.Language.EN_US).build();
        CustomModel customModel = service.createCustomModel(createCustomModelOptions).execute().getResult();
        customizationId = customModel.getCustomizationId();
        PromptMetadata promptMetadata = new PromptMetadata.Builder().promptText("promptText").build();
        File file = new File(RESOURCE + "numbers.wav");
        AddCustomPromptOptions addCustomPromptOptions = new AddCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").metadata(promptMetadata).file(file).build();
        Prompt prompt = service.addCustomPrompt(addCustomPromptOptions).execute().getResult();
        assertNotNull(prompt.getStatus());
        DeleteCustomPromptOptions deleteCustomPromptOptions = new DeleteCustomPromptOptions.Builder().customizationId(customizationId).promptId(prompt.getPromptId()).build();
        service.deleteCustomPrompt(deleteCustomPromptOptions).execute().getResult();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
        service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) DeleteCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) File(java.io.File) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 8 with CustomModel

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

the class TextToSpeechTest method testCreateCustomModelWOptions.

// Test the createCustomModel operation with a valid options model parameter
@Test
public void testCreateCustomModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customization_id\": \"customizationId\", \"name\": \"name\", \"language\": \"language\", \"owner\": \"owner\", \"created\": \"created\", \"last_modified\": \"lastModified\", \"description\": \"description\", \"words\": [{\"word\": \"word\", \"translation\": \"translation\", \"part_of_speech\": \"Dosi\"}], \"prompts\": [{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}]}";
    String createCustomModelPath = "/v1/customizations";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the CreateCustomModelOptions model
    CreateCustomModelOptions createCustomModelOptionsModel = new CreateCustomModelOptions.Builder().name("testString").language("en-US").description("testString").build();
    // Invoke createCustomModel() with a valid options model and verify the result
    Response<CustomModel> response = textToSpeechService.createCustomModel(createCustomModelOptionsModel).execute();
    assertNotNull(response);
    CustomModel responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createCustomModelPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) Test(org.testng.annotations.Test)

Example 9 with CustomModel

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

the class TextToSpeech method createCustomModel.

/**
 * Create a custom model.
 *
 * <p>Creates a new empty custom model. You must specify a name for the new custom model. You can
 * optionally specify the language and a description for the new model. The model is owned by the
 * instance of the service whose credentials are used to create it.
 *
 * <p>**See also:** [Creating a custom
 * model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-customModels#cuModelsCreate).
 *
 * <p>**Note:** The Arabic, Chinese, Czech, Dutch (Belgian and Netherlands), Australian English,
 * Korean, and Swedish languages and voices are supported only for IBM Cloud; they are deprecated
 * for IBM Cloud Pak for Data. Also, the `ar-AR` language identifier cannot be used to create a
 * custom model; use the `ar-MS` identifier instead.
 *
 * @param createCustomModelOptions the {@link CreateCustomModelOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link CustomModel}
 */
public ServiceCall<CustomModel> createCustomModel(CreateCustomModelOptions createCustomModelOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCustomModelOptions, "createCustomModelOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/customizations"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "createCustomModel");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createCustomModelOptions.name());
    if (createCustomModelOptions.language() != null) {
        contentJson.addProperty("language", createCustomModelOptions.language());
    }
    if (createCustomModelOptions.description() != null) {
        contentJson.addProperty("description", createCustomModelOptions.description());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<CustomModel> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CustomModel>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel)

Aggregations

CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)9 CreateCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions)6 DeleteCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions)5 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)4 File (java.io.File)4 Test (org.junit.Test)4 AddCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions)3 Prompt (com.ibm.watson.text_to_speech.v1.model.Prompt)3 PromptMetadata (com.ibm.watson.text_to_speech.v1.model.PromptMetadata)3 IOException (java.io.IOException)3 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 AddWordOptions (com.ibm.watson.text_to_speech.v1.model.AddWordOptions)1 AddWordsOptions (com.ibm.watson.text_to_speech.v1.model.AddWordsOptions)1