Determining whether a QuestionAnswerActivity was barged in
From now on, I will follow a different approach with my Speech Server related posts. Rather than having tutorials (many of which are also in the docs and sample apps), I will discuss actual questions that were posed to me through this blog and during my normal day. So, if you have any topics or questions you would like me to go over, and our legal department allows me to discuss them, I will post on it.
The topic for today is determining whether a QuestionAnswerActivity was barged in on. For those who aren't familiar with barge in, barge in allows you to interrupt an application prompt with a response. It is very common in speech applications because typically users do not want to wait for all choices to be listed - they will make their choice when they hear what they need.
All QuestionAnswerActivities have barge in turned on by default. You can turn it off using the CanBargeIn property, which is sometimes useful if you want to make sure listeners hear the entire prompt. This is very common for the "our menu has changed" messages.
I was recently asked how to determine whether a given QA was actually barged in on. At first I thought this would be a simple property but to date I have not found one. To get around this, it is necessary to make use of the Core API. As I mentioned earlier there are a number of cases when you'll need to revert to the Core API and this is one of them.
The object we are interested in is the Synthesizer and the event we want is SpeakCompleted. One way to attach to this event is in the TurnStarting event handler for the QA. Within your event handler, simply check the value of BargeInType in the event args that are passed to the event handler. Possible values are Speech, Dtmf, and None which I assume are self-explanatory. Depending on this value, set a class variable or property with the necessary information. In the case of a boolean value, one method is to set it to false in the TurnStarting event for the QA, then set it to true in SpeakCompleted if BargeInType is not None.
One last thing to watch out for is to detach from the SpeakCompleted event in the handler, unless the code is prepared to handle the results from multiple QAs and statements. This event handler is not attached to any particular QA, but to the Synthesizer which plays every time a prompt is played.