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();
}
}
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();
}
}
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);
}
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);
}
Aggregations