use of com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions 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.GetCustomPromptOptions in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testGetCustomPromptWOptions.
// Test the getCustomPrompt operation with a valid options model parameter
@Test
public void testGetCustomPromptWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}";
String getCustomPromptPath = "/v1/customizations/testString/prompts/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetCustomPromptOptions model
GetCustomPromptOptions getCustomPromptOptionsModel = new GetCustomPromptOptions.Builder().customizationId("testString").promptId("testString").build();
// Invoke getCustomPrompt() with a valid options model and verify the result
Response<Prompt> response = textToSpeechService.getCustomPrompt(getCustomPromptOptionsModel).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(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getCustomPromptPath);
// 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.GetCustomPromptOptions in project java-sdk by watson-developer-cloud.
the class TextToSpeech method getCustomPrompt.
/**
* Get a custom prompt.
*
* <p>Gets information about a specified custom prompt for a specified custom model. The
* information includes the prompt ID, prompt text, status, and optional speaker ID for each
* prompt of the custom model. You must use credentials for the instance of the service that owns
* the custom model. Custom prompts are supported only for use with US English custom models and
* voices.
*
* <p>**See also:** [Listing custom
* prompts](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-tbe-custom-prompts#tbe-custom-prompts-list).
*
* @param getCustomPromptOptions the {@link GetCustomPromptOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link Prompt}
*/
public ServiceCall<Prompt> getCustomPrompt(GetCustomPromptOptions getCustomPromptOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getCustomPromptOptions, "getCustomPromptOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("customization_id", getCustomPromptOptions.customizationId());
pathParamsMap.put("prompt_id", getCustomPromptOptions.promptId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/customizations/{customization_id}/prompts/{prompt_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "getCustomPrompt");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Prompt> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Prompt>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations