VoiceAgentLiveConnection interface

GPT Live 語音會話。

讀取事件時,只需一個 for await 迴圈,或使用 on、 、 off以及 once 監聽器。 離開迴圈會結束該工作階段。 接收到的音訊區塊是 base64 字串。

Extends

AsyncIterable<VoiceAgentLiveEvent>

屬性

closed

連線關閉時解決,若有服務確認及錯誤詳細資訊(如有)。

session

最新的工作階段設定。 connect() 返回後立即可用。

sessionStarted

原始啟動事件,包括服務提供時持續存在的對話 ID。

state

目前連線狀態。

方法

appendCommentary(string, VoiceAgentLiveAppendOptions)

為模型新增文字,讓模型對使用者說。 這是背景說明,不是用戶訊息。

appendInstructions(string, VoiceAgentLiveAppendOptions)

新增指令至工作階段,而非使用者訊息。

appendThinking(string, VoiceAgentLiveAppendOptions)

在不需要模型說話的情況下,加入背景語境。 不要用這個來隱藏秘密。

close(number, string)

關閉工作階段並等待服務確認。 如果連線失敗或未確認完成,包括當 socket 已經關閉時,則拒絕。

configureSession(LiveSessionUpdateParams, VoiceAgentEventOptions)

更新委派後端設定與逐字稿觸發器。 音訊格式、模型及委派擁有者無法更改。

dispose()

關閉工作階段。 等價於 close()。

muteInputAudio(VoiceAgentEventOptions)

停止模型處理輸入音訊。 Live 沒有輸入緩衝區可供提交或清除。

off<K>(K, VoiceAgentLiveEventHandler<K>)

移除先前已註冊的監聽器。

on<K>(K, VoiceAgentLiveEventHandler<K>)

為後續事件新增監聽器。 啟動事件使用連線選項 onEvent,或讀取 sessionStarted,以取得啟動元資料。

once<K>(K, VoiceAgentLiveEventHandler<K>)

新增一個執行一次的監聽器。

requestResponse(VoiceAgentEventOptions)

要求回應後端回應。 需要回應委派。

send(VoiceAgentLiveClientEvent, VoiceAgentSendOptions)

發送即時指令。 請勿傳送 session.start;服務會啟動該工作階段。

sendAudio(ArrayBuffer | Uint8Array, VoiceAgentEventOptions)

以設定的輸入格式傳送原始音訊,不包含 WAV 或其他檔案標頭。

sendEvent(VoiceAgentLiveClientEvent, VoiceAgentSendOptions)

用於 send() 的別名。

sendResponseItem(Record<string, unknown>, VoiceAgentEventOptions)

當工作階段使用 Responses 委派時,新增一個對話項目。

sendToolOutput(string, string, VoiceAgentSendToolOutputOptions)

將函式結果傳送至回應後端,並預設請求後續回應。

unmuteInputAudio(VoiceAgentEventOptions)

恢復模型音訊輸入。

繼承的方法

[asyncIterator]()

屬性詳細資料

closed

連線關閉時解決,若有服務確認及錯誤詳細資訊(如有)。

closed: Promise<VoiceAgentLiveCloseResult>

屬性值

session

最新的工作階段設定。 connect() 返回後立即可用。

session: VoiceAgentLiveSessionResource

屬性值

sessionStarted

原始啟動事件,包括服務提供時持續存在的對話 ID。

sessionStarted: LiveServerEventLiveSessionStarted

屬性值

state

目前連線狀態。

state: VoiceAgentConnectionState

屬性值

方法詳細資料

appendCommentary(string, VoiceAgentLiveAppendOptions)

為模型新增文字,讓模型對使用者說。 這是背景說明,不是用戶訊息。

function appendCommentary(content: string, options?: VoiceAgentLiveAppendOptions): Promise<void>

參數

content

string

傳回

Promise<void>

appendInstructions(string, VoiceAgentLiveAppendOptions)

新增指令至工作階段,而非使用者訊息。

function appendInstructions(content: string, options?: VoiceAgentLiveAppendOptions): Promise<void>

參數

content

string

傳回

Promise<void>

appendThinking(string, VoiceAgentLiveAppendOptions)

在不需要模型說話的情況下,加入背景語境。 不要用這個來隱藏秘密。

function appendThinking(content: string, options?: VoiceAgentLiveAppendOptions): Promise<void>

參數

content

string

傳回

Promise<void>

close(number, string)

關閉工作階段並等待服務確認。 如果連線失敗或未確認完成,包括當 socket 已經關閉時,則拒絕。

function close(code?: number, reason?: string): Promise<void>

參數

code

number

reason

string

傳回

Promise<void>

configureSession(LiveSessionUpdateParams, VoiceAgentEventOptions)

更新委派後端設定與逐字稿觸發器。 音訊格式、模型及委派擁有者無法更改。

function configureSession(session: LiveSessionUpdateParams, options?: VoiceAgentEventOptions): Promise<void>

參數

傳回

Promise<void>

dispose()

關閉工作階段。 等價於 close()。

function dispose(): Promise<void>

傳回

Promise<void>

muteInputAudio(VoiceAgentEventOptions)

停止模型處理輸入音訊。 Live 沒有輸入緩衝區可供提交或清除。

function muteInputAudio(options?: VoiceAgentEventOptions): Promise<void>

參數

傳回

Promise<void>

off<K>(K, VoiceAgentLiveEventHandler<K>)

移除先前已註冊的監聽器。

function off<K>(type: K, handler: VoiceAgentLiveEventHandler<K>): this

參數

type

K

傳回

this

on<K>(K, VoiceAgentLiveEventHandler<K>)

為後續事件新增監聽器。 啟動事件使用連線選項 onEvent,或讀取 sessionStarted,以取得啟動元資料。

function on<K>(type: K, handler: VoiceAgentLiveEventHandler<K>): this

參數

type

K

傳回

this

once<K>(K, VoiceAgentLiveEventHandler<K>)

新增一個執行一次的監聽器。

function once<K>(type: K, handler: VoiceAgentLiveEventHandler<K>): this

參數

type

K

傳回

this

requestResponse(VoiceAgentEventOptions)

要求回應後端回應。 需要回應委派。

function requestResponse(options?: VoiceAgentEventOptions): Promise<void>

參數

傳回

Promise<void>

send(VoiceAgentLiveClientEvent, VoiceAgentSendOptions)

發送即時指令。 請勿傳送 session.start;服務會啟動該工作階段。

function send(event: VoiceAgentLiveClientEvent, options?: VoiceAgentSendOptions): Promise<void>

參數

傳回

Promise<void>

sendAudio(ArrayBuffer | Uint8Array, VoiceAgentEventOptions)

以設定的輸入格式傳送原始音訊,不包含 WAV 或其他檔案標頭。

function sendAudio(audio: ArrayBuffer | Uint8Array, options?: VoiceAgentEventOptions): Promise<void>

參數

audio

ArrayBuffer | Uint8Array

傳回

Promise<void>

sendEvent(VoiceAgentLiveClientEvent, VoiceAgentSendOptions)

用於 send() 的別名。

function sendEvent(event: VoiceAgentLiveClientEvent, options?: VoiceAgentSendOptions): Promise<void>

參數

傳回

Promise<void>

sendResponseItem(Record<string, unknown>, VoiceAgentEventOptions)

當工作階段使用 Responses 委派時,新增一個對話項目。

function sendResponseItem(item: Record<string, unknown>, options?: VoiceAgentEventOptions): Promise<void>

參數

item

Record<string, unknown>

傳回

Promise<void>

sendToolOutput(string, string, VoiceAgentSendToolOutputOptions)

將函式結果傳送至回應後端,並預設請求後續回應。

function sendToolOutput(callId: string, output: string, options?: VoiceAgentSendToolOutputOptions): Promise<void>

參數

callId

string

output

string

傳回

Promise<void>

unmuteInputAudio(VoiceAgentEventOptions)

恢復模型音訊輸入。

function unmuteInputAudio(options?: VoiceAgentEventOptions): Promise<void>

參數

傳回

Promise<void>

繼承的方法的詳細資料

[asyncIterator]()

function [asyncIterator](): AsyncIterator<VoiceAgentLiveEvent, any, any>

傳回

AsyncIterator<VoiceAgentLiveEvent, any, any>

繼承自 非同步梯碼。[非同步迭代器]