Search in sources :

Example 31 with Authenticator

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);
}
Also used : NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) NoAuthAuthenticator(com.ibm.cloud.sdk.core.security.NoAuthAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator)

Example 32 with Authenticator

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);
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) BaseRecognizeCallback(com.ibm.watson.speech_to_text.v1.websocket.BaseRecognizeCallback) RecognizeWithWebsocketsOptions(com.ibm.watson.speech_to_text.v1.model.RecognizeWithWebsocketsOptions) FileInputStream(java.io.FileInputStream) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) SpeechRecognitionResults(com.ibm.watson.speech_to_text.v1.model.SpeechRecognitionResults)

Example 33 with Authenticator

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);
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) File(java.io.File) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) SpeechRecognitionResults(com.ibm.watson.speech_to_text.v1.model.SpeechRecognitionResults) RecognizeOptions(com.ibm.watson.speech_to_text.v1.model.RecognizeOptions)

Example 34 with Authenticator

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);
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Voices(com.ibm.watson.text_to_speech.v1.model.Voices)

Example 35 with Authenticator

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

Aggregations

Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)58 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)32 Before (org.junit.Before)15 NoAuthAuthenticator (com.ibm.cloud.sdk.core.security.NoAuthAuthenticator)14 Test (org.testng.annotations.Test)8 SpeechRecognitionResults (com.ibm.watson.speech_to_text.v1.model.SpeechRecognitionResults)5 BasicAuthenticator (com.ibm.cloud.sdk.core.security.BasicAuthenticator)4 BearerTokenAuthenticator (com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator)4 File (java.io.File)4 InputStream (java.io.InputStream)4 CouchDbSessionAuthenticator (com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator)3 HttpConfigOptions (com.ibm.cloud.sdk.core.http.HttpConfigOptions)3 Response (com.ibm.cloud.sdk.core.http.Response)2 MessageInput (com.ibm.watson.assistant.v1.model.MessageInput)2 MessageOptions (com.ibm.watson.assistant.v1.model.MessageOptions)2 MessageResponse (com.ibm.watson.assistant.v1.model.MessageResponse)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)2 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)2 RecognizeWithWebsocketsOptions (com.ibm.watson.speech_to_text.v1.model.RecognizeWithWebsocketsOptions)2