Skip to navigation

Pipecat

Turn detector client for Pipecat Cloud WebSocket turn prediction.
View as Markdown

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.

Contents

  • Usage: required module import and basic flow.
  • Factory functions: create the Pipecat turn detector.
  • Methods: reset, predict, and WebSocket lifecycle methods.
  • TurnEvents: Pipecat turn detector event names and payload fields.

Usage

Add the module before using the namespace:

require(Modules.Pipecat);

Create the detector, stream audio, and listen for turn prediction events.

Factory functions

createTurnDetector

Creates a Pipecat.TurnDetector instance.

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

Parameters

ParameterTypeReq.Description
parametersTurnDetectorParameters✓

Returns

TypeDescription
Promise<Pipecat.TurnDetector>Resolves to the Pipecat.TurnDetector value.

TurnDetector

Methods

addEventListener

Adds a handler for the specified Pipecat.TurnEvents event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.

addEventListener(event: Pipecat.TurnEvents | string, callback: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventPipecat.TurnEvents | string✓Event constant or event name to subscribe to.
callback(event: object) => any✓Function called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

close

Closes the TurnDetector connection (over WebSocket) or connection attempt.

close(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

id

Returns the TurnDetector id.

id(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe 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.

predict(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

removeEventListener

Removes a handler for the specified Pipecat.TurnEvents event.

removeEventListener(event: Pipecat.TurnEvents | string, callback?: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventPipecat.TurnEvents | string✓Event constant or event name to subscribe to.
callback(event: object) => any✗Function called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

reset

Reset the TurnDetector context.

reset(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

webSocketId

Returns the TurnDetector WebSocket id.

webSocketId(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe requested string value.

TurnEvents

These events describe Pipecat Cloud turn detector responses.

The Pipecat.TurnDetector result.

Event constant: TurnEvents.Result

Payload

FieldTypeReq.Description
turnDetectorTurnDetector✓The Pipecat.TurnDetector instance.
endOfTurnboolean✓Indicates whether the event is emitted at the end of the turn. Is true when the model predicts the end of the turn.
probabilitynumber✓The probability of the result, in the range [0.0, 1.0].

The Pipecat.TurnDetector is reset.

Event constant: TurnEvents.Reset

Payload

FieldTypeReq.Description
turnDetectorTurnDetector✓The Pipecat.TurnDetector instance.

The error response event.

Event constant: TurnEvents.Error

Payload

FieldTypeReq.Description
turnDetectorTurnDetector✓The Pipecat.TurnDetector instance.
reasonstring✓The error reason.

Contains information about connector.

Event constant: TurnEvents.ConnectorInformation

Payload

FieldTypeReq.Description
turnDetectorTurnDetector✓The Pipecat.TurnDetector instance.
data{ customEvent?: string; payload?: Object; }✗The ‘payload’ parameter contains the event’s data.