예제 #1
0
//This is related to the Speech to Text
    void Update()
    {
        if (listening)
        {
            //Verify if the 2 condition to stop listening are there
            if (cooldownSTT >= limitSTT && !String.IsNullOrEmpty(savedLineSTT))
            {
                STTstreamer.StopRecording();
                string tempString = lineSTT.Trim(Environment.NewLine.ToCharArray());
                associatedLogControl.LogText(tempString, new Color(252f / 255, 161f / 255, 157f / 255));
                SendLineAssistant(tempString);
                savedLineSTT      = "";
                lineSTT           = "";
                listening         = false;
                finishedListening = true;
            }//Add 1 (time period) if the 2 texts are equal
            if (lineSTT == savedLineSTT)
            {
                cooldownSTT += Time.deltaTime;
            }
            else//Otherwise, reset time and copy the line from the STT to the line saved.
            {
                cooldownSTT  = 0f;
                savedLineSTT = lineSTT;
            }
            if (!STTstreamer.Active && cooldownSTT > 2f)
            {
                STTstreamer = new ExampleStreaming();
                STTstreamer.SetServiceFromWrapper(stt);
                STTstreamer.StartRecording();
                cooldownSTT = 0f;
            }
        }
    }
예제 #2
0
    IEnumerator SetUpSpeechToText()
    {
        TokenOptions iamTokenOptions = new TokenOptions()
        {
            IamApiKey = "pS_euGwN75JNCi4nKzd9EKPnkuaWQnY0qVA5v6rAC0cv"
                        //IamApiKey = "liOt3C4cqS86vauIsjDd11uAny_ezrjp2tarts5LYrmi"
        };

        Credentials credentials = new Credentials(iamTokenOptions, "https://gateway-lon.watsonplatform.net/speech-to-text/api");

        while (!credentials.HasIamTokenData())
        {
            yield return(null);
        }

        stt        = new SpeechToTextService(credentials);
        sttStarted = true;
        //Set up the Example Streamer using the created STTAssistant
        STTstreamer = GameObject.FindGameObjectWithTag("Streamer").GetComponent <ExampleStreaming>();
        STTstreamer.SetServiceFromWrapper(stt);
    }