use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method constructClientService.
public void constructClientService() throws Throwable {
final String serviceName = "testService";
// set mock values for global params
String version = "testString";
final Authenticator authenticator = new NoAuthAuthenticator();
discoveryService = new Discovery(version, serviceName, authenticator);
String url = server.url("/").toString();
discoveryService.setServiceUrl(url);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class RecognizeUsingWebSocketsWithSpeakerLabelsExample method main.
/**
* The main method.
*
* @param args the arguments
* @throws FileNotFoundException the file not found exception
* @throws InterruptedException the interrupted exception
*/
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
FileInputStream audio = new FileInputStream("src/test/resources/speech_to_text/twospeakers.wav");
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
SpeechToText service = new SpeechToText(authenticator);
RecognizeWithWebsocketsOptions options = new RecognizeWithWebsocketsOptions.Builder().audio(audio).interimResults(true).speakerLabels(true).model(RecognizeOptions.Model.EN_US_NARROWBANDMODEL).contentType(HttpMediaType.AUDIO_WAV).build();
RecoTokens recoTokens = new RecoTokens();
service.recognizeUsingWebSocket(options, new BaseRecognizeCallback() {
@Override
public void onTranscription(SpeechRecognitionResults speechResults) {
recoTokens.add(speechResults);
}
@Override
public void onDisconnected() {
lock.countDown();
}
});
lock.await(1, TimeUnit.MINUTES);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class SpeechToTextExample method main.
public static void main(String[] args) throws FileNotFoundException {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
SpeechToText service = new SpeechToText(authenticator);
File audio = new File("src/test/resources/speech_to_text/sample1.wav");
RecognizeOptions options = new RecognizeOptions.Builder().audio(audio).contentType(HttpMediaType.AUDIO_WAV).build();
SpeechRecognitionResults transcript = service.recognize(options).execute().getResult();
System.out.println(transcript);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class TextToSpeechExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
TextToSpeech service = new TextToSpeech(authenticator);
Voices voices = service.listVoices().execute().getResult();
System.out.println(voices);
}
use of com.ibm.cloud.sdk.core.security.Authenticator 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"));
}
Aggregations