unity-sdk icon indicating copy to clipboard operation
unity-sdk copied to clipboard

Error! Session timed out

Open ghettokon opened this issue 9 years ago • 18 comments

@mediumTaj, congrats on this release, worth waiting for. I have a quick question, in the example streaming, I got the session timed out error after a specific time, I ran into this setting issue on RPI too, wondering where do I go change the setting so it waits longer.

best,

ghettokon avatar Sep 14 '17 04:09 ghettokon

@ghettokon Taj is out on vacation so for the next 2 weeks.

germanattanasio avatar Sep 14 '17 14:09 germanattanasio

@germanattanasio thanks for heads-up. Do you have any idea where do I change that so I don't get the session timed out every 30 sec? In the streaming example.

ghettokon avatar Sep 19 '17 22:09 ghettokon

@ghettokon Are you still having issues?

mediumTaj avatar Sep 25 '17 19:09 mediumTaj

@ghettokon can you try to add this to your code?

In SpeechToText.cs,

Change the SendStart method to

private void SendStart()
{
    if (_listenSocket == null)
        throw new WatsonException("SendStart() called with null connector.");

    Dictionary<string, object> start = new Dictionary<string, object>();
    start["action"] = "start";
    start["content-type"] = "audio/l16;rate=" + _recordingHZ.ToString() + ";channels=1;";
    start["continuous"] = EnableContinousRecognition;
    start["max_alternatives"] = _maxAlternatives;
    start["interim_results"] = EnableInterimResults;
    start["word_confidence"] = _wordConfidence;
    start["timestamps"] = _timestamps;
    start["speaker_labels"] = SpeakerLabels;
    start["small_formatting"] = SmallFormatting;
    start["profanity_filter"] = ProfanityFilter;
    start["word_alternatives_threshold"] = WordAlternativesThreshold;
    start["keywords_threshold"] = KeywordsThreshold;
    start["keywords"] = Keywords;
    start["inactivity_timeout"] = -1;

    _listenSocket.Send(new WSConnector.TextMessage(Json.Serialize(start)));
    _lastStartSent = DateTime.Now;
}

Change the KeepAlive method to

private IEnumerator KeepAlive()
{
    while (_listenSocket != null)
    {
        yield return null;

        if ((DateTime.Now - _lastKeepAlive).TotalSeconds > WsKeepAliveInterval)
        {
            Dictionary<string, string> nop = new Dictionary<string, string>();
            nop["action"] = "no-op";

#if ENABLE_DEBUGGING
            Log.Debug("SpeechToText", "Sending keep alive.");
#endif
            _listenSocket.Send(new WSConnector.TextMessage(Json.Serialize(nop)));
            AudioClip clip = AudioClip.Create("silence", 44100, 1, 44100, false);
            _listenSocket.Send(new WSConnector.BinaryMessage(WaveFile.CreateWAV(clip)));
            _lastKeepAlive = DateTime.Now;
        }
    }
    Log.Debug("SpeechToText", "KeepAlive exited.");
}

The service used to be happy with a short message to keep the connection alive. It looks like we now have to send a bit of silence as well.

mediumTaj avatar Sep 25 '17 21:09 mediumTaj

@mediumTaj I just tried your suggestion. It didn't work. Got any other ideas? By the way, in your suggested new version of the SendStart method, you have an extra space in the InactivityTimeout label (you have it as start["inactivity_timeout "] = -1; but I think it should be: start["inactivity_timeout"] = -1;

I tried both variations but neither one worked.

Is the Watson STT Inactivity Timeout parameter defined as part of the Unity SDK?

RMichaelPickering avatar Oct 12 '17 18:10 RMichaelPickering

@RMichaelPickering Yes the space should not be there - I edited my comment. inactivity_timeout is not defined in the Unity SDK.

Can you try to set the SilenceThreshold in the service to 0?

_speechToText.SilenceThreshold = 0.00f;

I will take a closer look.

Is your implementation continuously listening or does it require a button press?

mediumTaj avatar Oct 12 '17 19:10 mediumTaj

It looks like sending

nop["action"] = "no-op";

is deprecated. I moved inactivity_timeout into the query parameters where it belongs. I'm not sure the service likes the silence wav file I'm creating and sending. Checking to see if this may be the issue.

mediumTaj avatar Oct 12 '17 21:10 mediumTaj

@RMichaelPickering Please try the latest in this branch

I added a short .wav file in the Resources directory and am sending that file to keep alive. I've had the service running for several minutes this way. The service says I should be able to send a short clip of silence to keep alive but any silent audio clips I generate don't seem to keep the service alive. I'll try to generate another audio file.

mediumTaj avatar Oct 12 '17 22:10 mediumTaj

@mediumTaj I tried a few more things, including adding a Debug to log any Warnings returned back by Watson. Based on this, I found that the parameter as defined in the Unity SDK as "small_formatting" should actually be "smart_formatting" (that is, smaRT rather than small) and the "continuous" parameter is not used by the Watson STT API at all. I also tried a few other values for "inactivity_timeout" including 0, 60, and 3600. Only zero seemed to have some effect on the STT behaviour but unfortunately it resulted in an immediate timeout.

RMichaelPickering avatar Oct 13 '17 11:10 RMichaelPickering

@mediumTaj Your new branch seems to have fixed the keep alive! Thanks!! It would be good to make the other minor fixes that I mentioned above, too! Finally, is there a way to get an explicit answer as to what is the allowed range of values for "inactivity_timeout"? It really looks to me like -1 does not work. How high can I set it though?

RMichaelPickering avatar Oct 13 '17 11:10 RMichaelPickering

@RMichaelPickering Yes there are some params in there that were deprecated. I still need to remove them. I'll create an issue.

I'm glad that works - The service either did not like my generated silence or does not accept -1 as infinite. I'll have to see one way or another.

Once I figure out the generated silence bit I will merge this into the develop branch.

mediumTaj avatar Oct 13 '17 14:10 mediumTaj

I cleaned up a bit in STT in the gh-174-stt-timeout branch. I don't seem to have an issue with the InactivityTimeout = -1 now. If you have a chance can you check it out and confirm?

mediumTaj avatar Oct 13 '17 15:10 mediumTaj

Hi Ajiemar,

Happy to help! I'm assuming that I should just need to update the SpeechToText.cs in the Watson asset folder, correct?

Not sure what happened to my original issue now...

Regards,

Mike

RMichaelPickering avatar Oct 13 '17 17:10 RMichaelPickering

Yes, they file and the exampleStreaming.cs if you are using it. I think you have an open issue in the .NET SDK. Is that the one you’re referring to? I’m still waiting on Átila to check that one out.

mediumTaj avatar Oct 13 '17 17:10 mediumTaj

https://github.com/watson-developer-cloud/unity-sdk/pull/259

mediumTaj avatar Oct 17 '17 20:10 mediumTaj

Why cannot we just change the wsKeepAliveInterval to a high value, or just change the condition of checking the time to something like while(true)? So it will keep running forever, Just asking, Not an expert of this API

Sewmina7 avatar Feb 20 '20 20:02 Sewmina7

I've got myself a solution, You can start a new ListenConnector, that resets the condition for KeepAlive, and I see it like a way to start a new session.

Sewmina7 avatar Feb 20 '20 20:02 Sewmina7

Using the NodeJS SDK (ibm-watson) with websockets, we had to use a short recording of background noise to stop the session timing out. Generated silence didn't work. Hopefully this helps someone.

jjtindale avatar Jan 05 '22 15:01 jjtindale