Skip to main content

Barge-in

Barge-in, also known as “allow interrupt” or “recognize during prompt”, is a telephony feature which allows callers to interrupt (barge in) during voice prompts issued by their interlocutor.

tip
Enabling barge-in for your voice bot projects will allow bots to detect what clients are saying in real time and react to their prompts accordingly, even when they haven’t finished speaking. This can help the interaction feel more lively and engaging.

Barge-in options

To enable barge-in, call $dialer.bargeInResponse from the appropriate state, passing the necessary barge-in settings into it.

If the client says something to the bot in the middle of its reply, the bot will be interrupted and will process the request in the context of the current state. The following example illustrates the basic usage:

state: Offer
a: We’ve got a special deal just for you!
a: Today and tomorrow only, all “Keep Calm” subscription plans are eligible for a 20% discount!
a: Are you interested?
script:
$dialer.bargeInResponse({
bargeIn: "phrase", // Barge-in mode in which the bot will finish its last reply before being interrupted
bargeInTrigger: "final", // Barge-in will be triggered after the final speech recognition result
noInterruptTime: 1000 // During 1 second after the bot starts its first reply, it cannot be interrupted
});

state: What || noContext = true
q: * [sorry] what *
script:
log($dialer.isBargeInInterrupted()); // => true
a: Today and tomorrow you can apply for a 20% discount on all “Keep Calm” subscription plans!
a: Ready to try it out?

If the client asks “What?” prematurely, the bot will interrupt mid-sentence and reply to the question.

info

The $dialer.isBargeInInterrupted method tells whether barge-in took place.

Contextual barge-in

tip
When the bot response is long and consists of multiple replies, barge-in can be configured so that the barge-in context is different depending on the reply during which barge-in took place.

This contextual barge-in can be set up using parameters for a and audio reaction tags, separated from the tag body by the || separator. The syntax can be observed in the following example.

state: Offer
a: We’ve got a special deal just for you! || bargeInTransition = /Offer/NotDone, bargeInLabel = firstReply
a: Today and tomorrow only, || bargeInTransition = /Offer/NotDone, bargeInLabel = secondReply
a: all “Keep Calm” subscription plans are eligible for a 20% discount! || ignoreBargeIn = true
a: Are you interested? || bargeInTransition = /Offer/Done, bargeInLabel = thirdReply
script:
$dialer.bargeInResponse({
bargeIn: "forced",
bargeInTrigger: "interim",
noInterruptTime: 0
});
go: /Offer/Done

state: NotDone

state: No
intent: /No
a: But I haven’t finished yet! This is truly a unique offer!
go!: /Offer

state: CatchAll
event: noMatch
event: speechNotRecognized
a: I’m sorry, I didn’t catch what you said. Please let me go on.
script:
log($dialer.getBargeInTransition()); // => "/Offer/NotDone"
go!: /Offer

state: Done

state: No
intent: /No
a: Right then, thanks for your time! Have a good day!
script:
$dialer.hangUp();

state: CatchAll || noContext = true
event: noMatch
event: speechNotRecognized
script:
if ($dialer.isBargeInInterrupted()) {
log($dialer.getBargeInLabel()); // => "thirdReply"
}
a: I don’t quite follow you. Are you ready to try out our offer?

bargeInTransition

The bargeInTransition parameter sets the path to the state where the bot will be redirected if a barge-in occurs. The path follows the same format as after the go reaction tag.

In the example above, the client may decline the offer during the first or second reply, when the bot hasn’t yet told them the full offer conditions. Then the bot will make a transition to the /Offer/NotDone state, process the premature refusal in /Offer/NotDone/No, and go back to repeat the offer.

If, however, the refusal happens during the last reply, the request will be processed in the context of /Offer/Done. In this case, barge-in will cause the bot to say goodbye and end the call.

info

$dialer.getBargeInTransition returns the path to the state for handling barge-in set for the reply.

bargeInLabel

The bargeInLabel parameter labels the barge-in with some arbitrary data, such as the number of the reply where barge-in occurred.

info

The label value can be obtained in the barge-in handler state via $dialer.getBargeInLabel.

ignoreBargeIn

Replies which have the ignoreBargeIn parameter set to true force barge-in to be ignored when such replies are being pronounced.

tip
Barge-in should be ignored for replies with important information which the client shouldn’t miss if they have listened this far.

Conditional barge-in

The methods for processing barge-in illustrated above have the following drawback: the bot has to interrupt mid-sentence and process the request on receiving any result from the ASR provider.

This may prove inefficient when there is heavy background noise or when the client is prone to using communicative markers (“right”, “uh-huh”, etc.), which necessitate no reply but which the bot has to interrupt for in order to process them.

Solving this issue is possible via conditional barge-in, which allows the script itself to determine if the barge-in attempt should be processed or ignored. The example below illustrates how this can be achieved.

state: Yes
intent: /Yes
a: Thank you! The subscription has been activated. Have a nice day! || bargeInIf = beforeHangup
script:
$dialer.bargeInResponse({
bargeIn: "forced",
bargeInTrigger: "final",
noInterruptTime: 0
});

state: BargeInIntent || noContext = true
event: bargeInIntent
script:
var bargeInIntentStatus = $dialer.getBargeInIntentStatus();
log(bargeInIntentStatus.bargeInIf); // => "beforeHangup"
var text = bargeInIntentStatus.text;

if (text.indexOf("human") > -1) {
$dialer.bargeInInterrupt(true);
}

state: Switch
intent: /Human
a: I’m sorry if I misunderstood you. Transferring your call to our call center.
script:
$response.replies = $response.replies || [];
$response.replies.push({
type: "switch",
// ...
});

state: HangUp
event: speechNotRecognized
script:
$dialer.hangUp();

bargeInIf

The bargeInIf parameter set after the a or audio reaction tag enables conditional barge-in for this reply. The parameter value is the conditional barge-in label — a string with any arbitrary data.

bargeInIntent

If the client interrupts a bot during a reply for which bargeInIf is set, a bargeInIntent event will be generated and has to be processed in a separate state.

tip
This event by itself will not cause the bot to interrupt: it will carry on with its reply and simultaneously trigger the event handler state. The handler script determines whether the attempted barge-in should indeed cause the bot to interrupt or should be ignored.

The following methods can be called from the bargeInIntent event handler:

In the example above, the client will be able to interrupt the bot when it is saying goodbye only by calling for a “human”.

tip
The $nlp.matchPatterns method can be used for implementing more advanced NLU by matching barge-in attempt requests against patterns.

Behavior of bargeInTrigger

The conditions under which bargeInIntent is triggered are different based on the value of bargeInTrigger set during barge-in configuration.

caution
If the interim mode is used, the event is triggered on every intermediate speech recognition result. Calling the event handler too often may negatively impact bot performance.

It is recommended to use only the final trigger for conditional barge-in, so that the event only occurs on final speech recognition results.