Search in sources :

Example 1 with SpeakerCustomModels

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

the class TextToSpeechIT method testGetSpeakerModel.

/**
 * Test getSpeakerModel.
 */
@Test
public void testGetSpeakerModel() {
    try {
        CreateSpeakerModelOptions createSpeakerModelOptions = new CreateSpeakerModelOptions.Builder().speakerName("speakerName").audio(new File(RESOURCE + "numbers.wav")).build();
        SpeakerModel speakerModel = service.createSpeakerModel(createSpeakerModelOptions).execute().getResult();
        speakerId = speakerModel.getSpeakerId();
        assertNotNull(speakerModel.getSpeakerId());
        GetSpeakerModelOptions getSpeakerModelOptions = new GetSpeakerModelOptions.Builder().speakerId(speakerId).build();
        SpeakerCustomModels speakerCustomModels = service.getSpeakerModel(getSpeakerModelOptions).execute().getResult();
        assertNotNull(speakerCustomModels.getCustomizations());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteSpeakerModelOptions deleteSpeakerModelOptions = new DeleteSpeakerModelOptions.Builder().speakerId(speakerId).build();
        service.deleteSpeakerModel(deleteSpeakerModelOptions).execute().getResult();
    }
}
Also used : DeleteSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions) SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) CreateSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions) GetSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions) File(java.io.File) SpeakerCustomModels(com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 2 with SpeakerCustomModels

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

the class TextToSpeech method getSpeakerModel.

/**
 * Get a speaker model.
 *
 * <p>Gets information about all prompts that are defined by a specified speaker for all custom
 * models that are owned by a service instance. The information is grouped by the customization
 * IDs of the custom models. For each custom model, the information lists information about each
 * prompt that is defined for that custom model by the speaker. You must use credentials for the
 * instance of the service that owns a speaker model to list its prompts. 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 the custom prompts for a speaker
 * model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-tbe-speaker-models#tbe-speaker-models-list-prompts).
 *
 * @param getSpeakerModelOptions the {@link GetSpeakerModelOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link SpeakerCustomModels}
 */
public ServiceCall<SpeakerCustomModels> getSpeakerModel(GetSpeakerModelOptions getSpeakerModelOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSpeakerModelOptions, "getSpeakerModelOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("speaker_id", getSpeakerModelOptions.speakerId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/speakers/{speaker_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "getSpeakerModel");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<SpeakerCustomModels> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SpeakerCustomModels>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) SpeakerCustomModels(com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels)

Example 3 with SpeakerCustomModels

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

the class TextToSpeechTest method testGetSpeakerModelWOptions.

// Test the getSpeakerModel operation with a valid options model parameter
@Test
public void testGetSpeakerModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customizations\": [{\"customization_id\": \"customizationId\", \"prompts\": [{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\"}]}]}";
    String getSpeakerModelPath = "/v1/speakers/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetSpeakerModelOptions model
    GetSpeakerModelOptions getSpeakerModelOptionsModel = new GetSpeakerModelOptions.Builder().speakerId("testString").build();
    // Invoke getSpeakerModel() with a valid options model and verify the result
    Response<SpeakerCustomModels> response = textToSpeechService.getSpeakerModel(getSpeakerModelOptionsModel).execute();
    assertNotNull(response);
    SpeakerCustomModels 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, getSpeakerModelPath);
    // 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) GetSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions) SpeakerCustomModels(com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels) Test(org.testng.annotations.Test)

Aggregations

SpeakerCustomModels (com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels)3 GetSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 CreateSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions)1 DeleteSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions)1 SpeakerModel (com.ibm.watson.text_to_speech.v1.model.SpeakerModel)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