Search in sources :

Example 6 with GetVoiceOptions

use of com.ibm.watson.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)

Example 7 with GetVoiceOptions

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

the class TextToSpeech method getVoice.

/**
 * Get a voice.
 *
 * <p>Gets information about the specified voice. The information includes the name, language,
 * gender, and other details about the voice. Specify a customization ID to obtain information for
 * a custom model that is defined for the language of the specified voice. To list information
 * about all available voices, use the [List voices](#listvoices) method.
 *
 * <p>**See also:** [Listing a specific
 * voice](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices#listVoice).
 *
 * <p>**Note:** The Arabic, Chinese, Czech, Dutch (Belgian and Netherlands), Australian English,
 * Korean, and Swedish languages and voices are supported only for IBM Cloud; they are deprecated
 * for IBM Cloud Pak for Data. Also, the `ar-AR_OmarVoice` voice is deprecated; use the
 * `ar-MS_OmarVoice` voice instead.
 *
 * @param getVoiceOptions the {@link GetVoiceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Voice}
 */
public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getVoiceOptions, "getVoiceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("voice", getVoiceOptions.voice());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/voices/{voice}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "getVoice");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getVoiceOptions.customizationId() != null) {
        builder.query("customization_id", String.valueOf(getVoiceOptions.customizationId()));
    }
    ResponseConverter<Voice> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Voice>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Voice(com.ibm.watson.text_to_speech.v1.model.Voice)

Aggregations

Test (org.junit.Test)5 GetVoiceOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetVoiceOptions)4 Voice (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice)4 Voice (com.ibm.watson.text_to_speech.v1.model.Voice)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 GetVoiceOptions (com.ibm.watson.text_to_speech.v1.model.GetVoiceOptions)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)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 HashMap (java.util.HashMap)1 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)1 Test (org.testng.annotations.Test)1