Installation
Install the Smart Turn plugin withExample
Check out our simple agent example to see a practical implementation of the plugin and get inspiration for your own projects, or read on for some key details.Initialisation
First, make sure you’ve created an API key for the FAL.ai service and set theFAL_KEY
environment variable to your API key.
The Smart Turn plugin is exposed via the TurnDetection
class:
Parameters
You can customise the behaviour of Smart Turn through the following parameters:Name | Type | Default | Description |
---|---|---|---|
api_key | str|None | None | FAL API key. If None, uses FAL_KEY environment variable. |
buffer_duration | float | 2.0 | Duration in seconds to buffer audio before processing. |
confidence_threshold | float | 0.5 | Probability threshold (0.0–1.0) for determining turn completion. |
sample_rate | int | 16000 | Audio sample rate in Hz for processing (audio is resampled automatically). |
channels | int | 1 | Number of audio channels (mono). |
Functionality
Process Audio
After joining a Stream call, pass audio directly to Smart Turn for turn detection. The plugin automatically handles buffering, resampling and turn prediction:Start and Stop
Control turn detection with thestart()
and stop()
methods:
Events
The plugin emits turn detection events through the Vision Agents event system:Turn Started Event
Fired when a user begins speaking:Turn Ended Event
Fired when a user completes their turn (based on the model’s prediction and confidence threshold):Event Properties
BothTurnStartedEvent
and TurnEndedEvent
include the following properties:
Property | Type | Description |
---|---|---|
speaker_id | str | ID of the user whose turn started or ended. |
confidence | float|None | Confidence level of the turn detection (0.0–1.0). |
duration | float|None | Duration of the turn in seconds (if available). |
custom | dict|None | Additional data from the FAL model (prediction, etc). |