use of com.ibm.watson.text_to_speech.v1.model.PromptMetadata in project java-sdk by watson-developer-cloud.
the class TextToSpeechIT method testGetCustomPrompts.
/**
* Test getCustomPrompts.
*/
@Test
public void testGetCustomPrompts() {
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());
GetCustomPromptOptions getCustomPromptOptions = new GetCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").build();
Prompt prompt1 = service.getCustomPrompt(getCustomPromptOptions).execute().getResult();
assertNotNull(prompt1.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.PromptMetadata 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.PromptMetadata 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.PromptMetadata in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testAddCustomPromptWOptions.
// Test the addCustomPrompt operation with a valid options model parameter
@Test
public void testAddCustomPromptWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}";
String addCustomPromptPath = "/v1/customizations/testString/prompts/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the PromptMetadata model
PromptMetadata promptMetadataModel = new PromptMetadata.Builder().promptText("testString").speakerId("testString").build();
// Construct an instance of the AddCustomPromptOptions model
AddCustomPromptOptions addCustomPromptOptionsModel = new AddCustomPromptOptions.Builder().customizationId("testString").promptId("testString").metadata(promptMetadataModel).file(TestUtilities.createMockStream("This is a mock file.")).build();
// Invoke addCustomPrompt() with a valid options model and verify the result
Response<Prompt> response = textToSpeechService.addCustomPrompt(addCustomPromptOptionsModel).execute();
assertNotNull(response);
Prompt 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, addCustomPromptPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
Aggregations