Search in sources :

Example 16 with Word

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

the class TextToSpeech method getPronunciation.

/**
 * Gets the pronunciation for a word.
 *
 * Returns the phonetic pronunciation for the word specified by the `text` parameter. 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 voice model to see the translation for that
 * voice model. **Note:** This method is currently a beta release.
 *
 * @param getPronunciationOptions the {@link GetPronunciationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Pronunciation}
 */
public ServiceCall<Pronunciation> getPronunciation(GetPronunciationOptions getPronunciationOptions) {
    Validator.notNull(getPronunciationOptions, "getPronunciationOptions cannot be null");
    String[] pathSegments = { "v1/pronunciation" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query("text", getPronunciationOptions.text());
    if (getPronunciationOptions.voice() != null) {
        builder.query("voice", getPronunciationOptions.voice());
    }
    if (getPronunciationOptions.format() != null) {
        builder.query("format", getPronunciationOptions.format());
    }
    if (getPronunciationOptions.customizationId() != null) {
        builder.query("customization_id", getPronunciationOptions.customizationId());
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Pronunciation.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Pronunciation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation)

Example 17 with Word

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

the class CustomizationsIT method instantiateWords.

private List<Word> instantiateWords() {
    Word word1 = new Word();
    word1.setWord("hodor");
    word1.setTranslation("hold the door");
    Word word2 = new Word();
    word2.setWord("shocking");
    word2.setTranslation("<phoneme alphabet='ibm' ph='.1Sa.0kIG'></phoneme>");
    return ImmutableList.of(word1, word2);
}
Also used : Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)

Example 18 with Word

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

the class CustomizationsIT method testAddWords.

/**
 * Test add words and list words.
 */
@Test
public void testAddWords() {
    model = createVoiceModel();
    final List<Word> expected = instantiateWords();
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
    service.addWords(addOptions).execute();
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(model.getCustomizationId()).build();
    final Words words = service.listWords(listOptions).execute();
    assertEquals(expected.size(), words.getWords().size());
}
Also used : Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) Words(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 19 with Word

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

the class CustomizationsIT method testSynthesize.

/**
 * Test synthesize.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testSynthesize() throws IOException {
    model = createVoiceModel();
    final Word expected = instantiateWords().get(0);
    AddWordOptions addOptions = new AddWordOptions.Builder().word(expected.getWord()).translation(expected.getTranslation()).customizationId(model.getCustomizationId()).build();
    service.addWord(addOptions).execute();
    SynthesizeOptions synthesizeOptions1 = new SynthesizeOptions.Builder().text(expected.getWord()).voice(SynthesizeOptions.Voice.EN_US_MICHAELVOICE).accept(SynthesizeOptions.Accept.AUDIO_WAV).build();
    final InputStream stream1 = service.synthesize(synthesizeOptions1).execute();
    SynthesizeOptions synthesizeOptions2 = new SynthesizeOptions.Builder().text(expected.getWord()).voice(SynthesizeOptions.Voice.EN_US_MICHAELVOICE).accept(SynthesizeOptions.Accept.AUDIO_WAV).customizationId(model.getCustomizationId()).build();
    final InputStream stream2 = service.synthesize(synthesizeOptions2).execute();
    assertFalse(TestUtils.streamContentEquals(stream1, stream2));
}
Also used : AddWordOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions) Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) InputStream(java.io.InputStream) SynthesizeOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 20 with Word

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

the class CustomizationsIT method testGetWordJapanese.

/**
 * Test get word for Japanese.
 */
@Test
public void testGetWordJapanese() {
    model = createVoiceModelJapanese();
    final List<Word> expected = instantiateWordsJapanese();
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
    service.addWords(addOptions).execute();
    GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(model.getCustomizationId()).word(expected.get(0).getWord()).build();
    final Translation translation = service.getWord(getOptions).execute();
    assertEquals(expected.get(0).getTranslation(), translation.getTranslation());
    assertEquals(expected.get(0).getPartOfSpeech(), translation.getPartOfSpeech());
}
Also used : Translation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation) Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) GetWordOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)16 Test (org.junit.Test)16 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)8 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)6 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)6 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 Word (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word)5 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)5 Translation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation)5 GetWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 CustomWord (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord)3 DeleteWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteWordOptions)3 ByteString (okio.ByteString)3 JsonObject (com.google.gson.JsonObject)2 GetWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetWordOptions)2 Pronunciation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation)2