Search in sources :

Example 1 with LanguageTranslator

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

the class LanguageTranslatorIT method testReadme.

/**
 * Test README.
 */
@Test
public void testReadme() throws InterruptedException, IOException {
    // 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 : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) TranslationResult(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with LanguageTranslator

use of com.ibm.watson.developer_cloud.language_translator.v2.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 3 with LanguageTranslator

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

the class LanguageTranslatorTest method setUp.

/*
   * (non-Javadoc)
   * @see com.ibm.watson.developercloud.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    service = new LanguageTranslator();
    service.setApiKey("");
    service.setEndPoint(getMockWebServerUrl());
    // fixtures
    String jsonString = getStringFromInputStream(new FileInputStream(RESOURCE + "identifiable_languages.json"));
    identifiableLanguages = GSON.fromJson(jsonString, TYPE_IDENTIFIED_LANGUAGES);
    model = loadFixture(RESOURCE + "model.json", TranslationModel.class);
    models = loadFixture(RESOURCE + "models.json", TranslationModels.class);
    identifiedLanguages = loadFixture(RESOURCE + "identify_response.json", IdentifiedLanguages.class);
    singleTranslation = loadFixture(RESOURCE + "single_translation.json", TranslationResult.class);
    multipleTranslations = loadFixture(RESOURCE + "multiple_translations.json", TranslationResult.class);
}
Also used : TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) IdentifiedLanguages(com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages) TranslationModels(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModels) TranslationResult(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 4 with LanguageTranslator

use of com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator 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)

Aggregations

TranslateOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions)3 TranslationResult (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 TranslationResult (com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult)1 LanguageTranslator (com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator)1 IdentifiedLanguages (com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages)1 TranslationModel (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel)1 TranslationModels (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModels)1 SynthesizeOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 Test (org.junit.Test)1