Search in sources :

Example 1 with LanguageTranslator

use of com.ibm.watson.language_translator.v3.LanguageTranslator in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorExample method main.

public static void main(String[] args) {
    LanguageTranslator service = new LanguageTranslator();
    service.setUsernameAndPassword("<username>", "<password>");
    TranslateOptions translateOptions = new TranslateOptions.Builder().addText("hello").source(Language.ENGLISH).target(Language.SPANISH).build();
    TranslationResult translationResult = service.translate(translateOptions).execute();
    System.out.println(translationResult);
}
Also used : LanguageTranslator(com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator) TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) TranslationResult(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult)

Example 2 with LanguageTranslator

use of com.ibm.watson.language_translator.v3.LanguageTranslator in project java-sdk by watson-developer-cloud.

the class TranslateAndSynthesizeExample method main.

public static void main(String[] args) throws IOException {
    Authenticator ltAuthenticator = new IamAuthenticator("<iam_api_key>");
    LanguageTranslator translator = new LanguageTranslator("2019-11-22", ltAuthenticator);
    Authenticator ttsAuthenticator = new IamAuthenticator("<iam_api_key>");
    TextToSpeech synthesizer = new TextToSpeech(ttsAuthenticator);
    String text = "Greetings from Watson Developer Cloud";
    // translate
    TranslateOptions translateOptions = new TranslateOptions.Builder().addText(text).source(Language.ENGLISH).target(Language.SPANISH).build();
    TranslationResult translationResult = translator.translate(translateOptions).execute().getResult();
    String translation = translationResult.getTranslations().get(0).getTranslation();
    // synthesize
    SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(translation).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(HttpMediaType.AUDIO_WAV).build();
    InputStream in = synthesizer.synthesize(synthesizeOptions).execute().getResult();
    writeToFile(WaveUtils.reWriteWaveHeader(in), new File("output.wav"));
}
Also used : LanguageTranslator(com.ibm.watson.language_translator.v3.LanguageTranslator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) InputStream(java.io.InputStream) TranslateOptions(com.ibm.watson.language_translator.v3.model.TranslateOptions) TranslationResult(com.ibm.watson.language_translator.v3.model.TranslationResult) File(java.io.File) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) SynthesizeOptions(com.ibm.watson.text_to_speech.v1.model.SynthesizeOptions)

Example 3 with LanguageTranslator

use of com.ibm.watson.language_translator.v3.LanguageTranslator in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorExample method main.

public static void main(String[] args) {
    Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
    LanguageTranslator service = new LanguageTranslator("2018-05-01", authenticator);
    TranslateOptions translateOptions = new TranslateOptions.Builder().addText("text").modelId("en-es").build();
    TranslationResult translationResult = service.translate(translateOptions).execute().getResult();
    System.out.println(translationResult);
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) TranslateOptions(com.ibm.watson.language_translator.v3.model.TranslateOptions) TranslationResult(com.ibm.watson.language_translator.v3.model.TranslationResult) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator)

Aggregations

Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)2 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)2 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)2 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)2 LanguageTranslator (com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator)1 TranslateOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions)1 TranslationResult (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult)1 LanguageTranslator (com.ibm.watson.language_translator.v3.LanguageTranslator)1 SynthesizeOptions (com.ibm.watson.text_to_speech.v1.model.SynthesizeOptions)1 File (java.io.File)1 InputStream (java.io.InputStream)1