Search in sources :

Example 6 with CreateCustomModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions 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 7 with CreateCustomModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions 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)7 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 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)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 CustomModels (com.ibm.watson.text_to_speech.v1.model.CustomModels)1 DeleteCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomPromptOptions)1 DeleteWordOptions (com.ibm.watson.text_to_speech.v1.model.DeleteWordOptions)1