Error! Session timed out
@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 Taj is out on vacation so for the next 2 weeks.
@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 Are you still having issues?
@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 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 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?
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.
@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 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.
@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 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.
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?
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
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.
https://github.com/watson-developer-cloud/unity-sdk/pull/259
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
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.
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.