use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation in project java-sdk by watson-developer-cloud.
the class TranslateAndSynthesizeExample method main.
public static void main(String[] args) throws IOException {
LanguageTranslator translator = new LanguageTranslator();
translator.setUsernameAndPassword("username", "password");
TextToSpeech synthesizer = new TextToSpeech();
synthesizer.setUsernameAndPassword("username", "password");
String text = "Greetings from Watson Developer Cloud";
// translate
TranslateOptions translateOptions = new TranslateOptions.Builder().addText(text).source(Language.ENGLISH).target(Language.SPANISH).build();
TranslationResult translationResult = service.translate(translateOptions).execute();
String translation = translationResult.getTranslations().get(0).getTranslation();
// synthesize
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(translation).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(SynthesizeOptions.Accept.AUDIO_WAV).build();
InputStream in = service.synthesize(synthesizeOptions).execute();
writeToFile(WaveUtils.reWriteWaveHeader(in), new File("output.wav"));
}
use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation in project java-sdk by watson-developer-cloud.
the class TextToSpeech method getWord.
/**
* Queries details about a word in a custom voice model.
*
* Returns the translation for a single word from the custom model with the specified `customization_id`. The output
* shows the translation as it is defined in the model. You must use credentials for the instance of the service that
* owns a model to query information about its words. **Note:** This method is currently a beta release.
*
* @param getWordOptions the {@link GetWordOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Translation}
*/
public ServiceCall<Translation> getWord(GetWordOptions getWordOptions) {
Validator.notNull(getWordOptions, "getWordOptions cannot be null");
String[] pathSegments = { "v1/customizations", "words" };
String[] pathParameters = { getWordOptions.customizationId(), getWordOptions.word() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Translation.class));
}
use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation 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.Translation 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.Translation 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