Search in sources :

Example 6 with Translation

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"));
}
Also used : InputStream(java.io.InputStream) TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) TranslationResult(com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult) File(java.io.File) SynthesizeOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions)

Example 7 with Translation

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));
}
Also used : Translation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 8 with Translation

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Pronunciation(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation)

Example 9 with Translation

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));
}
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 10 with Translation

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());
}
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)8 Test (org.junit.Test)7 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)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 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)3 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)3 SynthesizeOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions)3 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)3 InputStream (java.io.InputStream)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 DeleteWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteWordOptions)2 File (java.io.File)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 TranslationResult (com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult)1 TranslateOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions)1 CreateVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.CreateVoiceModelOptions)1 DeleteVoiceModelOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteVoiceModelOptions)1