Search in sources :

Example 1 with GetCustomPromptOptions

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();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) GetCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions) 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 2 with GetCustomPromptOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) Test(org.testng.annotations.Test)

Example 3 with GetCustomPromptOptions

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt)

Aggregations

Prompt (com.ibm.watson.text_to_speech.v1.model.Prompt)3 GetCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 AddCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions)1 CreateCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions)1 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)1 DeleteCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions)1 PromptMetadata (com.ibm.watson.text_to_speech.v1.model.PromptMetadata)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1