rtvi

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package rtvi implements the RTVI protocol over a transport's messaging channel: a JSON message format and a processor that completes the client handshake and reports pipeline events to the client.

RTVI (Real-Time Voice Interface) is the protocol the Pipecat client SDKs speak, so a jargo server interoperates with existing RTVI web, iOS and Android clients. Messages are JSON objects of the form {"label":"rtvi-ai","type":...,"id":...,"data":...} exchanged over the WebRTC data channel.

Index

Constants

View Source
const (
	// MessageLabel tags every RTVI message.
	MessageLabel = "rtvi-ai"
	// ProtocolVersion is the RTVI protocol version this implementation speaks.
	ProtocolVersion = "2.0.0"
)
View Source
const (
	TypeClientReady         = "client-ready"
	TypeBotReady            = "bot-ready"
	TypeError               = "error"
	TypeUserTranscription   = "user-transcription"
	TypeBotTranscription    = "bot-transcription"
	TypeBotTTSText          = "bot-tts-text"
	TypeBotLLMText          = "bot-llm-text"
	TypeUserStartedSpeaking = "user-started-speaking"
	TypeUserStoppedSpeaking = "user-stopped-speaking"
	TypeBotStartedSpeaking  = "bot-started-speaking"
	TypeBotStoppedSpeaking  = "bot-stopped-speaking"
	TypeMetrics             = "metrics"
)

Message types exchanged over the data channel.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotReadyData

type BotReadyData struct {
	Version string `json:"version"`
}

BotReadyData is the payload of a bot-ready message.

type ErrorData

type ErrorData struct {
	Error string `json:"error"`
	Fatal bool   `json:"fatal"`
}

ErrorData is the payload of an error message.

type Incoming

type Incoming struct {
	Label string          `json:"label"`
	Type  string          `json:"type"`
	ID    string          `json:"id"`
	Data  json.RawMessage `json:"data"`
}

Incoming is a received RTVI message with its data left as raw JSON for type-specific decoding.

func ParseIncoming

func ParseIncoming(raw []byte) (Incoming, error)

ParseIncoming decodes a received RTVI message.

type Message

type Message struct {
	Label string `json:"label"`
	Type  string `json:"type"`
	ID    string `json:"id,omitempty"`
	Data  any    `json:"data,omitempty"`
}

Message is the RTVI message envelope. Outgoing event messages omit id; bot-ready and responses echo the request id.

func BotLLMText

func BotLLMText(text string) Message

BotLLMText builds a bot-llm-text message.

func BotReady

func BotReady(id string) Message

BotReady builds a bot-ready message in reply to the client-ready with id.

func BotTTSText

func BotTTSText(text string) Message

BotTTSText builds a bot-tts-text message.

func BotTranscription

func BotTranscription(text string) Message

BotTranscription builds a bot-transcription message.

func Error

func Error(msg string, fatal bool) Message

Error builds an error message.

func Metrics

func Metrics(data MetricsData) Message

Metrics builds a metrics message from data.

func UserTranscription

func UserTranscription(text, userID, timestamp string, final bool) Message

UserTranscription builds a user-transcription message.

type MetricData

type MetricData struct {
	Processor string  `json:"processor"`
	Value     float64 `json:"value"`
	Model     string  `json:"model,omitempty"`
}

MetricData is one timing or count entry in a metrics message (ttfb, processing or characters). Value is in seconds for timings, or a count.

type MetricsData

type MetricsData struct {
	TTFB       []MetricData      `json:"ttfb,omitempty"`
	Processing []MetricData      `json:"processing,omitempty"`
	Characters []MetricData      `json:"characters,omitempty"`
	Tokens     []TokenMetricData `json:"tokens,omitempty"`
}

MetricsData is the payload of a metrics message: each kind is a list so a single message can report several processors at once.

type Processor

type Processor struct {
	*processor.Base
}

Processor bridges a pipeline to an RTVI client. It completes the handshake — replying to client-ready with bot-ready — and reports pipeline events (transcriptions, speaking state, errors, LLM text) to the client as RTVI messages. Place it in the pipeline upstream of the output transport, which carries the messages to the client.

Incoming client messages arrive as InputTransportMessageFrames; outgoing messages are pushed downstream as OutputTransportMessageFrames.

func NewProcessor

func NewProcessor() *Processor

NewProcessor builds an RTVI processor.

func (*Processor) ProcessFrame

func (p *Processor) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame handles RTVI client messages and converts pipeline frames into RTVI messages, forwarding every frame on.

type TextData

type TextData struct {
	Text string `json:"text"`
}

TextData is the payload of text messages (bot-transcription, bot-tts-text, bot-llm-text).

type TokenMetricData

type TokenMetricData struct {
	Processor        string `json:"processor"`
	Model            string `json:"model,omitempty"`
	PromptTokens     int64  `json:"prompt_tokens"`
	CompletionTokens int64  `json:"completion_tokens"`
	TotalTokens      int64  `json:"total_tokens"`
}

TokenMetricData is one LLM token-usage entry in a metrics message.

type UserTranscriptionData

type UserTranscriptionData struct {
	Text      string `json:"text"`
	UserID    string `json:"user_id"`
	Timestamp string `json:"timestamp"`
	Final     bool   `json:"final"`
}

UserTranscriptionData is the payload of a user-transcription message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL