Unlock the Power of AI

1 million free tokens

88% Price Reduction

Activate Now

Interrupt the speech of an intelligent agent

Updated at: 2025-03-21 10:17

This topic describes how to use AICallKit SDK to interrupt an intelligent agent during its speech.

Usage notes

How to interrupt

You can interrupt the speech of the intelligent agent by using one of the following methods:

Manual interruption

Manual interruption: sends an interrupt message to the intelligent agent that is speaking. Upon receiving the message, the agent stops answering the current question. To enable manual interruption, call interruptSpeaking in AICallKit SDK.

Intelligent interruption

Intelligent interruption: interrupts the voice output of an intelligent agent with new voice inputs. For example, if a user asks Question B while the agent is still answering Question A, the agent will stop answering Question A and begin answering Question B instead. To enable intelligent interruption, call enableVoiceInterrupt in AICallKit SDK. The status of intelligent interruption is indicated by the onVoiceInterrupted callback.

Sample code

Android
iOS
Web
// By default, intelligent interruption is enabled. In this example, false is passed to disable intelligent interruption.
mARTCAICallEngine.enableVoiceInterrupt(false); 

// Enable manual interruption.
mARTCAICallEngine.interruptSpeaking(); 


// Handle callback events.
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
    
    @Override
    public void onVoiceInterrupted(boolean enable) {
        // Indicate whether the onVoiceInterrupted callback is configured for the current call.
        // The onVoiceInterrupted callback will tell you if voice interruptions have been enabled or disabled.
    }
}
// By default, intelligent interruption is enabled. In this example, false is passed to disable intelligent interruption.
_ = self.engine.enableVoiceInterrupt(enable: false)

// Enable manual interruption.
_ = self.engine.interruptSpeaking()

func onVoiceInterrupted(enable: Bool) {
    // Indicate whether the onVoiceInterrupted callback is configured for the current call.
    // The onVoiceInterrupted callback will tell you if voice interruptions have been enabled or disabled.
}
// By default, intelligent interruption is enabled. In this example, false is passed to disable intelligent interruption.
engine.enableVoiceInterrupt(false);
// Enable manual interruption.
engine.interruptSpeaking();

engine.on('voiceInterruptChanged', (ennable) => {
  // Indicate whether the onVoiceInterrupted callback is configured for the current call.
  // The onVoiceInterrupted callback will tell you if voice interruptions have been enabled or disabled.
  console.log('AICallVoiceInterruptChanged', ennable);
});

Interruption by using a designated keyword

During a call with an intelligent agent, users can interrupt the agent by using a designated keyword. The keyword typically needs to be configured when you start the agent.

Sample code

Android
iOS
// 1. Start an AI-powered call by setting an interruption keyword.

// Create an ARTCAICallConfig object and configure ARTCAICallAgentTemplateConfig.
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
artcaiCallConfig.mAiCallAgentTemplateConfig.interruptWords.add("Excuse me");
artcaiCallConfig.mAiCallAgentTemplateConfig.interruptWords.add("Test interruption");


// Omit the call initiation process.



// 2. If the agent is interrupted by a designated keyword, the onSpeakingInterrupted callback is invoked, with the reason specified by byWords.
@Override
        public void onSpeakingInterrupted(ARTCAICallEngine.ARTCAICallSpeakingInterruptedReason reason) {
// ARTCAICallSpeakingInterruptedReason.ByWords
        }

// 1. Start an AI-powered call by setting an interruption keyword.

// Create an ARTCAICallTemplateConfig object and set the interruptWords parameter. 
let templateConfig = ARTCAICallTemplateConfig()
templateConfig.interruptWords = ["Excuse me", "xxxx"]

// If you use the integration solution with UI, set config.templateConfig when you start a call.
let controller = AUIAICallStandardController(userId: userId)
controller.config.templateConfig = templateConfig
...

// If you use the integration solution without UI, convert templateConfig into a JSON string and use it as a request parameter of StartAIAgentInstance or GenerateAIAgentCall.
let jsonString = templateConfig.getJsonString(agentType)
...


// 2. If the agent is interrupted by a designated keyword, the onSpeakingInterrupted callback is invoked, with the reason specified by byWords.
public func onSpeakingInterrupted(reason: ARTCAICallSpeakingInterruptedReason) {
    
}
  • On this page (1, T)
  • Usage notes
  • How to interrupt
  • Manual interruption
  • Intelligent interruption
  • Interruption by using a designated keyword
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare