> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt # Pipecat Pipecat provides a VoxEngine client for streaming audio to Pipecat Cloud and receiving turn-taking predictions. Use `Pipecat.createTurnDetector(...)` to create a `TurnDetector` for the current scenario. ## Related guides #### [Pipecat turn detection guide](/voice-ai-orchestration/speech-flow-control/turn-detection) Learn how turn detection fits into a VoxEngine call flow. ## Contents * [Usage](#usage): required module import and basic flow. * [Factory functions](#factory-functions): create the Pipecat turn detector. * [Methods](#methods): reset, predict, and WebSocket lifecycle methods. * [TurnEvents](#turnevents): Pipecat turn detector event names and payload fields. ## Usage Add the module before using the namespace: ```js require(Modules.Pipecat); ``` Create the detector, stream audio, and listen for turn prediction events. ## Factory functions ### createTurnDetector Creates a [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance. ```ts createTurnDetector(parameters: TurnDetectorParameters): Promise ``` **Parameters** | Parameter | Type | Req. | Description | | ------------ | ------------------------------------------ | ---- | ----------- | | `parameters` | TurnDetectorParameters | ✓ | | **Returns** | Type | Description | | ------------------------------- | -------------------------------------------------------------- | | `Promise` | Resolves to the [`Pipecat.TurnDetector`](#turndetector) value. | ## TurnDetector ## Methods ### addEventListener Adds a handler for the specified [Pipecat.TurnEvents](/api-reference/voxengine/pipecat#turnevents) event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called. ```ts addEventListener(event: Pipecat.TurnEvents | string, callback: (event: object) => any): void ``` **Parameters** | Parameter | Type | Req. | Description | | ---------- | ------------------------------------------------ | ---- | --------------------------------------------- | | `event` | Pipecat.TurnEvents \| string | ✓ | Event constant or event name to subscribe to. | | `callback` | `(event: object) => any` | ✓ | Function called when the event is emitted. | **Returns** | Type | Description | | ------ | ------------------------ | | `void` | Does not return a value. | ### close Closes the TurnDetector connection (over WebSocket) or connection attempt. ```ts close(): void ``` **Parameters** This method does not accept parameters. **Returns** | Type | Description | | ------ | ------------------------ | | `void` | Does not return a value. | ### id Returns the TurnDetector id. ```ts id(): string ``` **Parameters** This method does not accept parameters. **Returns** | Type | Description | | -------- | --------------------------- | | `string` | The requested string value. | ### predict Triggers the TurnDetector to analyze the current audio and make a prediction. The result is returned in the `Pipecat.TurnEvents.Result` event. ```ts predict(): void ``` **Parameters** This method does not accept parameters. **Returns** | Type | Description | | ------ | ------------------------ | | `void` | Does not return a value. | ### removeEventListener Removes a handler for the specified [Pipecat.TurnEvents](/api-reference/voxengine/pipecat#turnevents) event. ```ts removeEventListener(event: Pipecat.TurnEvents | string, callback?: (event: object) => any): void ``` **Parameters** | Parameter | Type | Req. | Description | | ---------- | ------------------------------------------------ | ---- | --------------------------------------------- | | `event` | Pipecat.TurnEvents \| string | ✓ | Event constant or event name to subscribe to. | | `callback` | `(event: object) => any` | ✗ | Function called when the event is emitted. | **Returns** | Type | Description | | ------ | ------------------------ | | `void` | Does not return a value. | ### reset Reset the TurnDetector context. ```ts reset(): void ``` **Parameters** This method does not accept parameters. **Returns** | Type | Description | | ------ | ------------------------ | | `void` | Does not return a value. | ### webSocketId Returns the TurnDetector WebSocket id. ```ts webSocketId(): string ``` **Parameters** This method does not accept parameters. **Returns** | Type | Description | | -------- | --------------------------- | | `string` | The requested string value. | ## TurnEvents These events describe Pipecat Cloud turn detector responses. #### Result The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) result. Event constant: `TurnEvents.Result` **Payload** | Field | Type | Req. | Description | | -------------- | -------------- | ---- | ----------------------------------------------------------------------------------------------------------------------- | | `turnDetector` | `TurnDetector` | ✓ | The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance. | | `endOfTurn` | `boolean` | ✓ | Indicates whether the event is emitted at the end of the turn. Is **true** when the model predicts the end of the turn. | | `probability` | `number` | ✓ | The probability of the result, in the range \[0.0, 1.0]. | #### Reset The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) is reset. Event constant: `TurnEvents.Reset` **Payload** | Field | Type | Req. | Description | | -------------- | -------------- | ---- | ----------------------------------------------------------------------------------- | | `turnDetector` | `TurnDetector` | ✓ | The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance. | #### Error The error response event. Event constant: `TurnEvents.Error` **Payload** | Field | Type | Req. | Description | | -------------- | -------------- | ---- | ----------------------------------------------------------------------------------- | | `turnDetector` | `TurnDetector` | ✓ | The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance. | | `reason` | `string` | ✓ | The error reason. | #### ConnectorInformation Contains information about connector. Event constant: `TurnEvents.ConnectorInformation` **Payload** | Field | Type | Req. | Description | | -------------- | ---------------------------------------------------------------- | ---- | ----------------------------------------------------------------------------------- | | `turnDetector` | `TurnDetector` | ✓ | The [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance. | | `data` | \{ customEvent?: string; payload?: Object; } | ✗ | The 'payload' parameter contains the event's data. | > Turn detector client for Pipecat Cloud WebSocket turn prediction.