Search in sources :

Example 1 with GetPronunciationOptions

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

the class TextToSpeechIT method testGetWordPronunciation.

/**
 * Test word pronunciation.
 */
@Test
public void testGetWordPronunciation() {
    String word = "Congressman";
    GetPronunciationOptions getOptions1 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).format(GetPronunciationOptions.Format.IBM).build();
    Pronunciation pronunciation = service.getPronunciation(getOptions1).execute();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions2 = new GetPronunciationOptions.Builder().text(word).format(GetPronunciationOptions.Format.IBM).build();
    pronunciation = service.getPronunciation(getOptions2).execute();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions3 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).build();
    pronunciation = service.getPronunciation(getOptions3).execute();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions4 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).format(GetPronunciationOptions.Format.IPA).build();
    pronunciation = service.getPronunciation(getOptions4).execute();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
}
Also used : Pronunciation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation) GetPronunciationOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetPronunciationOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with GetPronunciationOptions

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

the class TextToSpeechIT method testGetWordPronunciation.

/**
 * Test word pronunciation.
 */
@Test
public void testGetWordPronunciation() {
    String word = "Congressman";
    GetPronunciationOptions getOptions1 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).format(GetPronunciationOptions.Format.IBM).build();
    Pronunciation pronunciation = service.getPronunciation(getOptions1).execute().getResult();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions2 = new GetPronunciationOptions.Builder().text(word).format(GetPronunciationOptions.Format.IBM).build();
    pronunciation = service.getPronunciation(getOptions2).execute().getResult();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions3 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).build();
    pronunciation = service.getPronunciation(getOptions3).execute().getResult();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
    GetPronunciationOptions getOptions4 = new GetPronunciationOptions.Builder().text(word).voice(GetPronunciationOptions.Voice.EN_US_MICHAELVOICE).format(GetPronunciationOptions.Format.IPA).build();
    pronunciation = service.getPronunciation(getOptions4).execute().getResult();
    assertNotNull(pronunciation);
    assertNotNull(pronunciation.getPronunciation());
}
Also used : Pronunciation(com.ibm.watson.text_to_speech.v1.model.Pronunciation) GetPronunciationOptions(com.ibm.watson.text_to_speech.v1.model.GetPronunciationOptions) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 3 with GetPronunciationOptions

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

the class TextToSpeech method getPronunciation.

/**
 * Get pronunciation.
 *
 * <p>Gets the phonetic pronunciation for the specified word. You can request the pronunciation
 * for a specific format. You can also request the pronunciation for a specific voice to see the
 * default translation for the language of that voice or for a specific custom model to see the
 * translation for that model.
 *
 * <p>**See also:** [Querying a word from a
 * language](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-customWords#cuWordsQueryLanguage).
 *
 * <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 getPronunciationOptions the {@link GetPronunciationOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Pronunciation}
 */
public ServiceCall<Pronunciation> getPronunciation(GetPronunciationOptions getPronunciationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getPronunciationOptions, "getPronunciationOptions cannot be null");
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/pronunciation"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "getPronunciation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("text", String.valueOf(getPronunciationOptions.text()));
    if (getPronunciationOptions.voice() != null) {
        builder.query("voice", String.valueOf(getPronunciationOptions.voice()));
    }
    if (getPronunciationOptions.format() != null) {
        builder.query("format", String.valueOf(getPronunciationOptions.format()));
    }
    if (getPronunciationOptions.customizationId() != null) {
        builder.query("customization_id", String.valueOf(getPronunciationOptions.customizationId()));
    }
    ResponseConverter<Pronunciation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Pronunciation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Pronunciation(com.ibm.watson.text_to_speech.v1.model.Pronunciation)

Example 4 with GetPronunciationOptions

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

the class TextToSpeechTest method testGetPronunciationWOptions.

// Test the getPronunciation operation with a valid options model parameter
@Test
public void testGetPronunciationWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"pronunciation\": \"pronunciation\"}";
    String getPronunciationPath = "/v1/pronunciation";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetPronunciationOptions model
    GetPronunciationOptions getPronunciationOptionsModel = new GetPronunciationOptions.Builder().text("testString").voice("en-US_MichaelV3Voice").format("ipa").customizationId("testString").build();
    // Invoke getPronunciation() with a valid options model and verify the result
    Response<Pronunciation> response = textToSpeechService.getPronunciation(getPronunciationOptionsModel).execute();
    assertNotNull(response);
    Pronunciation 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, getPronunciationPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("text"), "testString");
    assertEquals(query.get("voice"), "en-US_MichaelV3Voice");
    assertEquals(query.get("format"), "ipa");
    assertEquals(query.get("customization_id"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Pronunciation(com.ibm.watson.text_to_speech.v1.model.Pronunciation) GetPronunciationOptions(com.ibm.watson.text_to_speech.v1.model.GetPronunciationOptions) Test(org.testng.annotations.Test)

Aggregations

Pronunciation (com.ibm.watson.text_to_speech.v1.model.Pronunciation)3 GetPronunciationOptions (com.ibm.watson.text_to_speech.v1.model.GetPronunciationOptions)2 Test (org.junit.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 GetPronunciationOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetPronunciationOptions)1 Pronunciation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1