All Products
Search
Document Center

Intelligent Media Services:Interrupt the agent's speech

Last Updated:Jun 05, 2025

This topic describes how to use AICallKit SDK to interrupt the AI agent while it is speaking.

Before you begin

  • The following examples show how to implement this feature using the API without the UI.

  • You must integrate AICallKit SDK in advance. For more information, see Android, iOS, and Web.

Methods

Use one of the following methods to interrupt the agent's speech:

Manual interruption

Sends an interrupt message to the agent that is speaking. Upon receiving the message, the agent stops answering the current question. To enable it, call interruptSpeaking in AICallKit SDK.

Intelligent interruption

Interrupts the voice output of the 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 it, call enableVoiceInterrupt in AICallKit SDK. The status of intelligent interruption is indicated by the onVoiceInterrupted callback.

Sample code

Android
// 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.
    }
}
iOS
// 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.
}
Web
// 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

Interrupts the agent by using a designated keyword. The keyword typically needs to be configured when you start the agent.

Sample code

Android
// 1. Start a call by setting the interruptWords parameter.
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
artcaiCallConfig.agentConfig.interruptConfig.interruptWords.add("Excuse me");
artcaiCallConfig.agentConfig.interruptConfig.interruptWords.add("Test interruption");

// Omit the call initiation process.
......

// 2. If a designated interruption keyword is detected, the onSpeakingInterrupted callback is invoked, with the reason specified by byWords.
@Override
public void onSpeakingInterrupted(ARTCAICallEngine.ARTCAICallSpeakingInterruptedReason reason) {
//Cause: ARTCAICallSpeakingInterruptedReason.ByWorks
}
iOS
// 1. Start a call by setting the interruptWords parameter.
let agentConfig = ARTCAICallAgentConfig()         // Create an ARTCAICallAgentConfig object.
agentConfig.interruptConfig.interruptWords = ["Excuse me", "xxxx"]

// Omit the call initiation process.
......

// 2. If a designated interruption keyword is detected, the onSpeakingInterrupted callback is invoked, with the reason specified by byWords.
public func onSpeakingInterrupted(reason: ARTCAICallSpeakingInterruptedReason) {
    
}

Web

// 1. Start a call by setting the interruptWords parameter.
const agentConfig = new AICallAgentConfig();               // Create an ARTCAICallAgentConfig object.
agentConfig.interruptConfig.interruptWords = ['Excuse me', 'xxxx'];

// Omit the call initiation process.
......

// 2. If a designated interruption keyword is detected, the onSpeakingInterrupted callback is invoked, with the reason specified by byWords.
engine.on('speakingInterrupted', (reason) => {
  
});