Esempio n. 1
0
 public void TestConstructorNoApikey()
 {
     IamAuthenticator authenticator = new IamAuthenticator(
         apikey: null
         );
 }
Esempio n. 2
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));

            //            }
        }