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