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));
}
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);
}
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());
}
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));
}
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());
}
Aggregations