コード例 #1
0
        public IEnumerator MyCoroutine()
        {
            string text = Text.text;

            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            textToSpeechService = new TextToSpeechService(authenticator);
            textToSpeechService.SetServiceUrl("https://gateway-lon.watsonplatform.net/text-to-speech/api");

            byte[]    synthesizeResponse = null;
            AudioClip clip = null;

            textToSpeechService.Synthesize(
                callback: (DetailedResponse <byte[]> response, IBMError error) =>
            {
                synthesizeResponse = response.Result;
                clip = WaveFile.ParseWAV("hello_world.wav", synthesizeResponse);
                AudioSource audioSource = GetComponent <AudioSource>();
                audioSource.clip        = clip;
                audioSource.Play();
            },
                text: text,
                voice: voice,
                accept: "audio/wav"
                );

            while (synthesizeResponse == null)
            {
                yield return(null);
            }
        }
コード例 #2
0
    public IEnumerator GetLanguages()
    {
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        languageTranslatorService = new LanguageTranslatorService(versionDate, authenticator);
        languageTranslatorService.SetServiceUrl("https://gateway-lon.watsonplatform.net/language-translator/api");

        languageTranslatorService.ListIdentifiableLanguages(
            callback: (DetailedResponse <IdentifiableLanguages> response, IBMError error) =>
        {
            if (error != null)
            {
                return;
            }

            foreach (var element in response.Result.Languages)
            {
                languages.Add(element.Name);
                languagesShort.Add(element.Language);
            }
        });
    }
コード例 #3
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(apikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: apikey);

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            assistantService = new AssistantService("2019-11-12", authenticator);

            if (!string.IsNullOrEmpty(serviceUrl))
            {
                assistantService.SetServiceUrl(serviceUrl);
            }

            //  Create a session
            CreateSession();
        }
コード例 #4
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            //  Create authenticator and instantiate service
            Authenticator speechToTextAuthenticator = new IamAuthenticator(
                apikey: iamApikey,
                url: serviceUrl
                );

            //  Wait for authenticator
            while (!speechToTextAuthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _service = new SpeechToTextService(speechToTextAuthenticator);
            _service.StreamMultipart = true;

            Active = true;
            StartRecording();
        }
コード例 #5
0
    private IEnumerator CreateAuthenticateServices()
    {
        _assistantAuthenticator = new IamAuthenticator(apiKey);

        while (!_assistantAuthenticator.CanAuthenticate())
        {
            yield return(null);
        }

        _assistantService = new AssistantService(serviceVersionDate, _assistantAuthenticator);

        if (!string.IsNullOrEmpty(serviceUrl))
        {
            _assistantService.SetServiceUrl(serviceUrl);
        }
        else
        {
            Debug.LogError("Assistant Service URL is null or empty");
        }

        _assistantService.CreateSession(OnCreateSession, assistantId);

        while (!_createSessionTested)
        {
            yield return(null);
        }
    }
コード例 #6
0
    public IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(settings.Assistant_apikey))
        {
            throw new IBMException("Please provide Watson Assistant IAM ApiKey for the service.");
        }

        //  Create credential and instantiate service
        //            IamAuthenticator authenticator = new IamAuthenticator(apikey: Assistant_apikey, url: serviceUrl);
        IamAuthenticator authenticator = new IamAuthenticator(apikey: settings.Assistant_apikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        Assistant_service = new AssistantService(settings.versionDate, authenticator);
        if (!string.IsNullOrEmpty(settings.serviceUrl))
        {
            Assistant_service.SetServiceUrl(settings.serviceUrl);
        }

        Assistant_service.CreateSession(OnCreateSession, settings.assistantId);

        while (!createSessionTested)
        {
            yield return(null);
        }
    }
コード例 #7
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(_iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: _iamApikey);

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _service = new SpeechToTextService(authenticator);
            if (!string.IsNullOrEmpty(_serviceUrl))
            {
                _service.SetServiceUrl(_serviceUrl);
            }
            _service.StreamMultipart = true;

            Active = true;
            StartRecording();
        }
コード例 #8
0
    // Update is called once per frame
    public IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        //  Create credential and instantiate service
        IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        service = new LanguageTranslatorService(versionDate, authenticator);
        if (!string.IsNullOrEmpty(serviceUrl))
        {
            service.SetServiceUrl(serviceUrl);
        }

        Log.Debug("LanguageTranslatorServiceV3", "ListModels result");
        Translate(new List <string>()
        {
            "hola", "como", "estas"
        });
    }
コード例 #9
0
    // Update is called once per frame
    public IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        //  Create credential and instantiate service
        IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        service = new DiscoveryService(versionDate, authenticator);
        if (!string.IsNullOrEmpty(serviceUrl))
        {
            service.SetServiceUrl(serviceUrl);
        }

        Runnable.Run(ExampleCreateEnvironment());
        Runnable.Run(ExampleListEnvironments());
    }
コード例 #10
0
        private IEnumerator CreateService()
        {
            IamAuthenticator authenticator = new IamAuthenticator(apikey: "{iamApikey}");

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new PersonalityInsightsService("2019-02-18", authenticator);

            Runnable.Run(Examples());
        }
コード例 #11
0
 public IEnumerator InitalizeService()
 {
     authenticator = new IamAuthenticator(
         apikey: apiKey
         );
     while (!authenticator.CanAuthenticate())
     {
         yield return(null);
     }
     tts = new TextToSpeechService(authenticator);
     tts.SetServiceUrl(url);
     Debug.Log("TTS is initialized");
     //StartCoroutine(ReadText("The Hero was frozen in his track for a moment, but then he decided that he should kill the opponent"));
 }
コード例 #12
0
    private IEnumerator CreateASService()
    {
        IamAuthenticator authenticator = new IamAuthenticator(apikey: ASSIamApikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        ASService = new AssistantService("2019-02-18", authenticator);
        ASService.SetServiceUrl(ASServiceUrl);

        Debug.Log(" Assistant Service Created ...");
    }
コード例 #13
0
        private IEnumerator CreateService()
        {
            IamAuthenticator authenticator = new IamAuthenticator(apikey: "{iamApikey}");

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new AssistantService("2019-02-18", authenticator);

            workspaceId = Environment.GetEnvironmentVariable("CONVERSATION_WORKSPACE_ID");
            Runnable.Run(Examples());
        }
コード例 #14
0
    // Create the IBM text to speech service
    public IEnumerator CreateService()
    {
        //  Create credential and instantiate service
        tts_authenticator = new IamAuthenticator(apikey: settings.tts_apikey);

        //  Wait for tokendata
        while (!tts_authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        tts_service = new TextToSpeechService(tts_authenticator);
        if (!string.IsNullOrEmpty(settings.tts_serviceUrl))
        {
            tts_service.SetServiceUrl(settings.tts_serviceUrl);
        }
    }
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new NaturalLanguageClassifierService(authenticator);

            Runnable.Run(ExampleListClassifiers());
        }
コード例 #16
0
        private IEnumerator CreateService()
        {
            //  Create authenticator
            Authenticator languageTranslatorAuthenticator = new IamAuthenticator(
                apikey: iamApikey,
                url: serviceUrl
                );

            //  Yield here until we have IAM token data
            while (!languageTranslatorAuthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            //  Instantiate service
            languageTranslator = new LanguageTranslatorService(
                versionDate: "2019-04-09",
                authenticator: languageTranslatorAuthenticator
                );
        }
コード例 #17
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new NaturalLanguageUnderstandingService(versionDate, authenticator);

            Runnable.Run(ExampleAnalyze());
            Runnable.Run(ExampleListModels());
            Runnable.Run(ExampleDeleteModel());
        }
コード例 #18
0
    private IEnumerator CreateAuthenticateServices()
    {
        _textToSpeechAuthenticator = new IamAuthenticator(apiKey);

        while (!_textToSpeechAuthenticator.CanAuthenticate())
        {
            yield return(null);
        }

        _textToSpeechService = new TextToSpeechService(_textToSpeechAuthenticator);

        if (!string.IsNullOrEmpty(serviceUrl))
        {
            _textToSpeechService.SetServiceUrl(serviceUrl);
        }
        else
        {
            Debug.LogError("Speech to text Service URL is null or empty");
        }
    }
コード例 #19
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            //  Create credential and instantiate service
            IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new AssistantService(versionDate, authenticator);

            Runnable.Run(Examples());
        }
コード例 #20
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new TextToSpeechService(authenticator);
            if (!string.IsNullOrEmpty(serviceUrl))
            {
                service.SetServiceUrl(serviceUrl);
            }
        }
コード例 #21
0
        private IEnumerator CreateServices()
        {
            // Creating STT Service ---------------------------------------------------------------------------------------------------------------------------
            if (string.IsNullOrEmpty(_speechToTextIamApikey))
            {
                throw new IBMException("Please provide IAM ApiKey for the STT service.");
            }

            IamAuthenticator sttAuthenticator = new IamAuthenticator(apikey: _speechToTextIamApikey);

            //  Wait for token data
            while (!sttAuthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _speechToTextService = new SpeechToTextService(sttAuthenticator);
            if (!string.IsNullOrEmpty(_speechToTextServiceUrl))
            {
                _speechToTextService.SetServiceUrl(_speechToTextServiceUrl);
            }
            _speechToTextService.StreamMultipart = true;

            Active = true;

            // Creating Assistant Service ---------------------------------------------------------------------------------------------------------------------
            IamAuthenticator assistantAuthenticator = new IamAuthenticator(apikey: "9Az7c6aj2kKhH31OROZ_cIlaYXo8HT8ut248Q8CXx_qq");

            //  Wait for tokendata
            while (!assistantAuthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _assistantService = new AssistantService("2019-02-18", assistantAuthenticator);
            _assistantService.SetServiceUrl("https://api.eu-gb.assistant.watson.cloud.ibm.com/instances/f53fde36-02ed-4410-a49b-d18c6566f0bc");

            // ------------------------------------------------------------------------------------------------------------------------------------------------

            StartRecording();
        }
コード例 #22
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(_STTApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            IamAuthenticator TTSauthenticator = new IamAuthenticator(apikey: _STTApikey);

            //  Wait for tokendata
            while (!TTSauthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _STTservice = new SpeechToTextService(TTSauthenticator);
            if (!string.IsNullOrEmpty(_STTUrl))
            {
                _STTservice.SetServiceUrl(_STTUrl);
            }
            _STTservice.StreamMultipart = true;

            //  Create credential and instantiate service
            tts_authenticator = new IamAuthenticator(apikey: _TTSApikey);

            //  Wait for tokendata
            while (!tts_authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            tts_service = new TextToSpeechService(tts_authenticator);
            if (!string.IsNullOrEmpty(_TTSUrl))
            {
                tts_service.SetServiceUrl(_TTSUrl);
            }

            // Yazilan string baslangicta asistan tarafından söylenir

            Active = true;
        }
コード例 #23
0
    private IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(_iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        IamAuthenticator authenticator = new IamAuthenticator(apikey: _iamApikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        textToSpeech = new TextToSpeechService(authenticator);
        textToSpeech.SetServiceUrl(TextToSpeechURL);
        // textToSpeech.StreamMultipart = true;

        //  Active = true;
        Runnable.Run(CallTextToSpeech("Select Mangoe!"));
    }
コード例 #24
0
    // Update is called once per frame
    public IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        //  Create credential and instantiate service
        IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

        //  Wait for tokendata
        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        service = new LanguageTranslatorService(versionDate, authenticator);
        service.SetServiceUrl("https://api.us-south.language-translator.test.watson.cloud.ibm.com");


        Log.Debug("LanguageTranslatorServiceV3", "ListModels result");
    }
コード例 #25
0
    private IEnumerator CreateTTSService()
    {
        if (string.IsNullOrEmpty(TTSIamApikey))
        {
            throw new IBMException("Please add TTS IAM ApiKey to the Iam Apikey field in the inspector.");
        }

        IamAuthenticator authenticator = new IamAuthenticator(apikey: TTSIamApikey);

        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        TTSService = new TextToSpeechService(authenticator);

        if (!string.IsNullOrEmpty(TTSServiceUrl))
        {
            TTSService.SetServiceUrl(TTSServiceUrl);
        }
        Debug.Log(" Text To Speech Service Created ...");
    }
コード例 #26
0
    private IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(_iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        //     //  Create credential and instantiate service
        //     Credentials credentials = null;

        //     //  Authenticate using iamApikey
        //     TokenOptions tokenOptions = new TokenOptions()
        //     {
        //         IamApiKey = _iamApikey
        //     };

        //     credentials = new Credentials(tokenOptions, _serviceUrl);

        //     //  Wait for tokendata
        //     while (!credentials.HasIamTokenData())
        //         yield return null;

        //     _service = new TextToSpeechService(credentials);
        // }

        IamAuthenticator authenticator = new IamAuthenticator(apikey: _iamApikey);

        while (!authenticator.CanAuthenticate())
        {
            yield return(null);
        }

        _service = new TextToSpeechService(authenticator);
        if (!string.IsNullOrEmpty(_serviceUrl))
        {
            _service.SetServiceUrl(_serviceUrl);
        }
    }
コード例 #27
0
ファイル: IBMService.cs プロジェクト: RorySan/Story-Teller
 protected static bool WaitForTokenData(IamAuthenticator authenticator)
 {
     return(!authenticator.CanAuthenticate());
 }
コード例 #28
0
        public IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(Assistant_apikey))
            {
                throw new IBMException("Please provide Watson Assistant IAM ApiKey for the service.");
            }

            //  Create credential and instantiate service
            //            IamAuthenticator authenticator = new IamAuthenticator(apikey: Assistant_apikey, url: serviceUrl);
            IamAuthenticator authenticator = new IamAuthenticator(apikey: Assistant_apikey);

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            Assistant_service = new AssistantService(versionDate, authenticator);
            if (!string.IsNullOrEmpty(serviceUrl))
            {
                Assistant_service.SetServiceUrl(serviceUrl);
            }

            if (string.IsNullOrEmpty(tts_apikey))
            {
                throw new IBMException("Please provide Text-to-speech IAM ApiKey for the service.");
            }


            //  Create credential and instantiate service
            tts_authenticator = new IamAuthenticator(apikey: tts_apikey);

            //  Wait for tokendata
            while (!tts_authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            tts_service = new TextToSpeechService(tts_authenticator);
            if (!string.IsNullOrEmpty(tts_serviceUrl))
            {
                tts_service.SetServiceUrl(tts_serviceUrl);
            }

            // Set speech processing status to "Processing"
            processStatus = "Processing";

            // Create services
            Runnable.Run(speechStreamer.CreateService());

            // Ignore input speech while the bot is speaking.
            speechStreamer.Active = false;


            Assistant_service.CreateSession(OnCreateSession, assistantId);

            while (!createSessionTested)
            {
                yield return(null);
            }

            messageTested = false;
            var inputMessage = new MessageInput()
            {
                Text    = inputSpeech,
                Options = new MessageInputOptions()
                {
                    ReturnContext = true
                }
            };

            Assistant_service.Message(OnMessage, assistantId, sessionId);
            while (!messageTested)
            {
                messageTested = false;
                yield return(null);
            }


            //_testString = "I am Bob";
            //            if (!String.IsNullOrEmpty(_testString))
            //            {
            byte[]    synthesizeResponse = null;
            AudioClip clip = null;

            tts_service.Synthesize(
                callback: (DetailedResponse <byte[]> response, IBMError error) =>
            {
                synthesizeResponse = response.Result;
                clip = WaveFile.ParseWAV("myClip" + counter.ToString(), synthesizeResponse);
                PlayClip(clip);
            },
                text: _testString,
                //voice: "en-US_AllisonV3Voice",
                voice: "en-US_MichaelV3Voice",
                //voice: "en-US_MichaelVoice",
                accept: "audio/wav"
                );

            while (synthesizeResponse == null)
            {
                yield return(null);
            }

            counter++;

            processStatus = "Finished";

            yield return(new WaitForSeconds(clip.length));

            //            }
        }
コード例 #29
0
//NEW: This authentication function has been adapted from the examples here https://github.com/watson-developer-cloud/unity-sdk/tree/master/Examples
    private IEnumerator InitializeServices()
    {
        if (string.IsNullOrEmpty(assistantIamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the Assistant service.");
        }

        IamAuthenticator assistantAuthenticator = new IamAuthenticator(apikey: assistantIamApikey);

        while (!assistantAuthenticator.CanAuthenticate())
        {
#if ENABLE_DEBUGGING
            Debug.Log("Not yet authenticated Assitant");
#endif
            yield return(null);
        }

        _assistant = new AssistantService("2019-02-08", assistantAuthenticator);
        if (!string.IsNullOrEmpty(AssistantURL))
        {
            _assistant.SetServiceUrl(AssistantURL);
        }

        _assistant.CreateSession(OnCreateSession, assistantId);

 #if ENABLE_DEBUGGING
        Debug.Log("Created Assistant Instance");
 #endif
        while (!sessionCreated)
        {
            yield return(null);

 #if ENABLE_DEBUGGING
            Debug.Log("No Assistant Instance Created");
#endif


            loadingText.text = "Loading Watson Assistant...";
        }

        if (string.IsNullOrEmpty(TextToSpeechIamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the TTS service.");
        }

        IamAuthenticator ttsAuthenticator = new IamAuthenticator(apikey: TextToSpeechIamApikey);

        while (!ttsAuthenticator.CanAuthenticate())
        {
            yield return(null);

            Debug.Log("Not yet authenticated Text to Speech");
            loadingText.text = "Loading Watson...";
        }
        _textToSpeech = new TextToSpeechService(ttsAuthenticator);
        Debug.Log("Created textToSpeechService");

        if (!string.IsNullOrEmpty(TextToSpeechURL))
        {
            _textToSpeech.SetServiceUrl(TextToSpeechURL);
        }

        if (string.IsNullOrEmpty(SpeechToTextIamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the STT service.");
        }

        IamAuthenticator sttAuthenticator = new IamAuthenticator(apikey: SpeechToTextIamApikey);

        while (!sttAuthenticator.CanAuthenticate())
        {
            yield return(null);

            Debug.Log("Not yet authenticated Speech to Text");
            loadingText.text = "Loading Watson...";
        }

        _speechToText = new SpeechToTextService(sttAuthenticator);
        Debug.Log("Created SpeechToTextService");

        if (!string.IsNullOrEmpty(SpeechToTextURL))
        {
            _speechToText.SetServiceUrl(SpeechToTextURL);
        }

        Debug.Log("Setting Active to True...");
        Active = true;

        //NEW: Watson message on Startup
        //welcomeMessage();

        //SendTextMessage("Assistant started");

        StartRecording();   // Setup recording
    }