Search in sources :

Example 1 with GetVoiceOptions

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

the class TextToSpeech method getVoice.

/**
 * Retrieves a specific voice available for speech synthesis.
 *
 * Lists information about the voice specified with the `voice` path parameter. Specify the `customization_id` query
 * parameter to obtain information for that custom voice model of the specified voice. Use the `GET /v1/voices` method
 * to see a list of all available voices.
 *
 * @param getVoiceOptions the {@link GetVoiceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Voice}
 */
public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
    Validator.notNull(getVoiceOptions, "getVoiceOptions cannot be null");
    String[] pathSegments = { "v1/voices" };
    String[] pathParameters = { getVoiceOptions.voice() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    if (getVoiceOptions.customizationId() != null) {
        builder.query("customization_id", getVoiceOptions.customizationId());
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Voice.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Voice(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice)

Example 2 with GetVoiceOptions

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

the class CustomizationsTest method testGetVoiceCustomization.

/**
 * Test get voice with custom voice model.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetVoiceCustomization() throws InterruptedException {
    server.enqueue(jsonResponse(voice));
    GetVoiceOptions getOptions = new GetVoiceOptions.Builder().voice("en-US_TestMaleVoice").customizationId("cafebabe-1234-5678-9abc-def012345678").build();
    final Voice result = service.getVoice(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(VOICES_PATH + "/en-US_TestMaleVoice?customization_id=" + CUSTOMIZATION_ID, request.getPath());
    assertEquals("GET", request.getMethod());
    assertEquals(voice, result);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Voice(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice) GetVoiceOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 3 with GetVoiceOptions

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

the class CustomizationsIT method testGetVoiceCustomization.

/**
 * Test get voice with customization.
 */
@Test
public void testGetVoiceCustomization() {
    model = createVoiceModel();
    GetVoiceModelOptions getVoiceModelOptions = new GetVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).build();
    final VoiceModel model2 = service.getVoiceModel(getVoiceModelOptions).execute();
    GetVoiceOptions getVoiceOptions = new GetVoiceOptions.Builder().customizationId(model.getCustomizationId()).voice(GetVoiceOptions.Voice.EN_US_ALLISONVOICE).build();
    final Voice voice = service.getVoice(getVoiceOptions).execute();
    assertNotNull(model);
    assertNotNull(model2);
    assertNotNull(voice);
    assertEquals(model2.getCustomizationId(), voice.getCustomization().getCustomizationId());
    assertEquals(model2.getName(), voice.getCustomization().getName());
    assertEquals(model2.getDescription(), voice.getCustomization().getDescription());
    assertEquals(model2.getLanguage(), voice.getCustomization().getLanguage());
    assertEquals(model2.getOwner(), voice.getCustomization().getOwner());
    assertEquals(model2.getCreated(), voice.getCustomization().getCreated());
    assertEquals(model2.getLastModified(), voice.getCustomization().getLastModified());
}
Also used : GetVoiceModelOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions) VoiceModel(com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel) Voice(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice) GetVoiceOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 4 with GetVoiceOptions

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

the class TextToSpeechIT method testGetVoice.

/**
 * Test get voice.
 */
@Test
public void testGetVoice() {
    GetVoiceOptions getOptions = new GetVoiceOptions.Builder().voice(voiceName).build();
    Voice voice = service.getVoice(getOptions).execute();
    assertNotNull(voice);
    assertNotNull(voice.getDescription());
    assertNotNull(voice.getGender());
    assertNotNull(voice.getLanguage());
    assertNotNull(voice.getName());
    assertNotNull(voice.getUrl());
}
Also used : Voice(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice) GetVoiceOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with GetVoiceOptions

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

the class TextToSpeechTest method testGetVoice.

/**
 * Test get voice.
 */
@Test
public void testGetVoice() {
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(getVoiceResponse)));
    GetVoiceOptions getOptions = new GetVoiceOptions.Builder().voice("en-US_TestMaleVoice").build();
    Voice result = service.getVoice(getOptions).execute();
    assertNotNull(result);
    assertEquals(result, getVoiceResponse);
    try {
        TestUtils.assertNoExceptionsOnGetters(result);
    } catch (final Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Voice(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GetVoiceOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Voice (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice)5 GetVoiceOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions)4 Test (org.junit.Test)4 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 GetVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceModelOptions)1 VoiceModel (com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModel)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1