> 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

Learn how Pipecat turn detection fits into a VoxEngine call flow.

## Contents

* &#x20;[Usage](#usage): required module import and basic flow.
* &#x20;[Factory functions](#factory-functions): create the Pipecat turn detector.
* &#x20;[Methods](#methods): reset, predict, and WebSocket lifecycle methods.
* &#x20;[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

### &#x20;createTurnDetector

Creates a [Pipecat.TurnDetector](/api-reference/voxengine/pipecat#turndetector) instance.

```ts
createTurnDetector(parameters: TurnDetectorParameters): Promise<Pipecat.TurnDetector>
```

**Parameters**

| Parameter    | Type                                       | Req. | Description |
| ------------ | ------------------------------------------ | ---- | ----------- |
| `parameters` | <code>TurnDetector<wbr />Parameters</code> | ✓    |             |

**Returns**

| Type                                        | Description                                                    |
| ------------------------------------------- | -------------------------------------------------------------- |
| <code>Promise\<Pipecat.TurnDetector></code> | Resolves to the [`Pipecat.TurnDetector`](#turndetector) value. |

## TurnDetector

## Methods

### &#x20;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`    | <code>Pipecat.<wbr />TurnEvents \| string</code> | ✓    | Event constant or event name to subscribe to. |
| `callback` | <code>(event: object) => any</code>              | ✓    | Function called when the event is emitted.    |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;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. |

### &#x20;id

Returns the TurnDetector id.

```ts
id(): string
```

**Parameters**

This method does not accept parameters.

**Returns**

| Type     | Description                 |
| -------- | --------------------------- |
| `string` | The requested string value. |

### &#x20;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. |

### &#x20;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`    | <code>Pipecat.<wbr />TurnEvents \| string</code> | ✓    | Event constant or event name to subscribe to. |
| `callback` | <code>(event: object) => any</code>              | ✗    | Function called when the event is emitted.    |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;reset

Reset the TurnDetector context.

```ts
reset(): void
```

**Parameters**

This method does not accept parameters.

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;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.

<a id="-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].                                                                |

<a id="-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. |

<a id="-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.                                                                   |

<a id="-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`         | `Object`       | ✗    | The event's data.                                                                   |