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:

1require(Modules.Pipecat);

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

Factory functions

createTurnDetector

Creates a Pipecat.TurnDetector instance.

1createTurnDetector(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.

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

Parameters

ParameterTypeReq.Description
eventPipecat.TurnEvents | stringEvent constant or event name to subscribe to.
callback(event: object) => anyFunction called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

close

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

1close(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

id

Returns the TurnDetector id.

1id(): 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.

1predict(): 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.

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

Parameters

ParameterTypeReq.Description
eventPipecat.TurnEvents | stringEvent constant or event name to subscribe to.
callback(event: object) => anyFunction called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

reset

Reset the TurnDetector context.

1reset(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

webSocketId

Returns the TurnDetector WebSocket id.

1webSocketId(): 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
turnDetectorTurnDetectorThe Pipecat.TurnDetector instance.
endOfTurnbooleanIndicates whether the event is emitted at the end of the turn. Is true when the model predicts the end of the turn.
probabilitynumberThe probability of the result, in the range [0.0, 1.0].

The Pipecat.TurnDetector is reset.

Event constant: TurnEvents.Reset

Payload

FieldTypeReq.Description
turnDetectorTurnDetectorThe Pipecat.TurnDetector instance.

The error response event.

Event constant: TurnEvents.Error

Payload

FieldTypeReq.Description
turnDetectorTurnDetectorThe Pipecat.TurnDetector instance.
reasonstringThe error reason.

Contains information about connector.

Event constant: TurnEvents.ConnectorInformation

Payload

FieldTypeReq.Description
turnDetectorTurnDetectorThe Pipecat.TurnDetector instance.
dataObjectThe event’s data.