This topic describes how to use AICallKit SDK to enable push-to-talk mode.
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 Integrate AICallKit SDK for Android, Integrate AICallKit SDK for iOS, and Integrate AICallKit SDK for Web.
Overview
Enable push-to-talk mode Switches from natural conversation mode to push-to-talk mode.
| Start speaking Presses and holds the Speak button to start communicating with the agent.
|
This feature is included in the integration solution with a UI.
How it works
In push-to-talk mode, each input from a user and each response from the AI agent are treated as independent events, similar to how traditional intercoms work. This mode makes the interaction between the users and AI agent more structured and orderly. In push-to-talk mode, users can communicate with the AI agent in a more efficient and organized manner.
API details
API operation | Description |
enablePushToTalk | Enables or disables push-to-talk mode. The status is indicated by the |
startPushToTalk | Presses and holds to start speaking. This call is valid only after push-to-talk mode is enabled. During this period, the agent will remain in the listening state, and what the user says will be displayed in real time. Note We recommend that you call this API operation in the press event, and not in the release event. |
finishPushToTalk | Releases to finish speaking. The AI agent enters the thinking state, and soon broadcasts the results. |
cancelPushToTalk | Releases to cancel speaking. The AI agent does nothing and immediately returns to the waiting state of holding down to start speaking. |
Sample code
Android
// By default, push-to-talk mode is disabled. In this example, true is passed to enable push-to-talk mode.
mARTCAICallEngine.enablePushToTalk(enable: true)
// Press and hold to start speaking.
mARTCAICallEngine.startPushToTalk()
// Release to finish speaking.
mARTCAICallEngine.finishPushToTalk()
// Release to cancel speaking.
mARTCAICallEngine.cancelPushToTalk()
// Handle callback events.
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
@Override
public void onPushToTalk(boolean enable) {
// Indicate whether the onPushToTalk callback is configured for the current call.
// The onPushToTalk callback will tell you if push-to-talk mode has been enabled or disabled.
}
}Web
// By default, push-to-talk mode is disabled. In this example, true is passed to enable push-to-talk mode.
engine.enablePushToTalk(enable);
// Press and hold to start speaking.
engine.startPushToTalk();
// Release to finish speaking.
engine.finishPushToTalk();
// Release to cancel speaking.
engine.cancelPushToTalk();
engine.on('pushToTalkChanged', (enable) => {
// Indicate whether the onPushToTalk callback is configured for the current call.
// The onPushToTalk callback will tell you if push-to-talk mode has been enabled or disabled.
console.log('AICallPushToTalk', enable);
});
