Search in sources :

Example 1 with Prompts

use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.

the class TextToSpeechIT method testListCustomPrompts.

/**
 * Test listCustomPrompts.
 */
@Test
public void testListCustomPrompts() {
    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();
    ListCustomPromptsOptions listCustomPromptsOptions = new ListCustomPromptsOptions.Builder().customizationId(customizationId).build();
    Prompts prompts = service.listCustomPrompts(listCustomPromptsOptions).execute().getResult();
    assertNotNull(prompts.getPrompts());
    DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
    service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
}
Also used : ListCustomPromptsOptions(com.ibm.watson.text_to_speech.v1.model.ListCustomPromptsOptions) CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) Prompts(com.ibm.watson.text_to_speech.v1.model.Prompts) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 2 with Prompts

use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.

the class TextToSpeechTest method testGetVoiceWOptions.

// Test the getVoice operation with a valid options model parameter
@Test
public void testGetVoiceWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"url\": \"url\", \"gender\": \"gender\", \"name\": \"name\", \"language\": \"language\", \"description\": \"description\", \"customizable\": true, \"supported_features\": {\"custom_pronunciation\": false, \"voice_transformation\": false}, \"customization\": {\"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 getVoicePath = "/v1/voices/ar-AR_OmarVoice";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetVoiceOptions model
    GetVoiceOptions getVoiceOptionsModel = new GetVoiceOptions.Builder().voice("ar-AR_OmarVoice").customizationId("testString").build();
    // Invoke getVoice() with a valid options model and verify the result
    Response<Voice> response = textToSpeechService.getVoice(getVoiceOptionsModel).execute();
    assertNotNull(response);
    Voice 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, getVoicePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("customization_id"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Voice(com.ibm.watson.text_to_speech.v1.model.Voice) GetVoiceOptions(com.ibm.watson.text_to_speech.v1.model.GetVoiceOptions) Test(org.testng.annotations.Test)

Example 3 with Prompts

use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.

the class TextToSpeechTest method testListCustomModelsWOptions.

// Test the listCustomModels operation with a valid options model parameter
@Test
public void testListCustomModelsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customizations\": [{\"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 listCustomModelsPath = "/v1/customizations";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListCustomModelsOptions model
    ListCustomModelsOptions listCustomModelsOptionsModel = new ListCustomModelsOptions.Builder().language("ar-MS").build();
    // Invoke listCustomModels() with a valid options model and verify the result
    Response<CustomModels> response = textToSpeechService.listCustomModels(listCustomModelsOptionsModel).execute();
    assertNotNull(response);
    CustomModels 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, listCustomModelsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("language"), "ar-MS");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SpeakerCustomModels(com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels) CustomModels(com.ibm.watson.text_to_speech.v1.model.CustomModels) ListCustomModelsOptions(com.ibm.watson.text_to_speech.v1.model.ListCustomModelsOptions) Test(org.testng.annotations.Test)

Example 4 with Prompts

use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.

the class TextToSpeech method listSpeakerModels.

/**
 * List speaker models.
 *
 * <p>Lists information about all speaker models that are defined for a service instance. The
 * information includes the speaker ID and speaker name of each defined speaker. You must use
 * credentials for the instance of a service to list its speakers. Speaker models and the custom
 * prompts with which they are used are supported only for use with US English custom models and
 * voices.
 *
 * <p>**See also:** [Listing speaker
 * models](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-tbe-speaker-models#tbe-speaker-models-list).
 *
 * @param listSpeakerModelsOptions the {@link ListSpeakerModelsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Speakers}
 */
public ServiceCall<Speakers> listSpeakerModels(ListSpeakerModelsOptions listSpeakerModelsOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/speakers"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "listSpeakerModels");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Speakers> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Speakers>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Speakers(com.ibm.watson.text_to_speech.v1.model.Speakers)

Example 5 with Prompts

use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.

the class TextToSpeech method listCustomPrompts.

/**
 * List custom prompts.
 *
 * <p>Lists information about all custom prompts that are defined for a 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. The same information about all of the prompts for a custom model is also
 * provided by the [Get a custom model](#getcustommodel) method. That method provides complete
 * details about a specified custom model, including its language, owner, custom words, and more.
 * 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 listCustomPromptsOptions the {@link ListCustomPromptsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Prompts}
 */
public ServiceCall<Prompts> listCustomPrompts(ListCustomPromptsOptions listCustomPromptsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCustomPromptsOptions, "listCustomPromptsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("customization_id", listCustomPromptsOptions.customizationId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/customizations/{customization_id}/prompts", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "listCustomPrompts");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Prompts> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Prompts>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Prompts(com.ibm.watson.text_to_speech.v1.model.Prompts)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)10 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 Test (org.testng.annotations.Test)10 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 HashMap (java.util.HashMap)5 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)4 Prompt (com.ibm.watson.text_to_speech.v1.model.Prompt)4 SpeakerCustomModels (com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels)4 Prompts (com.ibm.watson.text_to_speech.v1.model.Prompts)3 CreateCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions)2 CustomModels (com.ibm.watson.text_to_speech.v1.model.CustomModels)2 ListCustomPromptsOptions (com.ibm.watson.text_to_speech.v1.model.ListCustomPromptsOptions)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 AddCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions)1 DeleteCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions)1 DeleteCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomPromptOptions)1 GetCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.GetCustomModelOptions)1 GetCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions)1 GetSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions)1 GetVoiceOptions (com.ibm.watson.text_to_speech.v1.model.GetVoiceOptions)1