VoiceSession
A live voice session.
Properties
Section titled “Properties”sessionId
Section titled “sessionId”
readonlysessionId:string
The session id.
readonlystate:SessionState
The current state. listening once connect() has resolved.
transport
Section titled “transport”
readonlytransport:"webrtc"|"websocket"
The transport in use: webrtc, or websocket after the fallback.
Methods
Section titled “Methods”end():
Promise<void>
Ends the session and releases the microphone.
Returns
Section titled “Returns”Promise<void>
interrupt()
Section titled “interrupt()”interrupt():
void
Stops the reply now, as if the person had started speaking.
Returns
Section titled “Returns”void
levels()
Section titled “levels()”levels():
object
Loudness, 0..1, for meters.
Returns
Section titled “Returns”object
input:
number
output
Section titled “output”output:
number
mute()
Section titled “mute()”mute(
muted):void
Mutes or unmutes the microphone.
Parameters
Section titled “Parameters”boolean
Returns
Section titled “Returns”void
on<
K>(name,fn): () =>void
Subscribes; the returned function unsubscribes. A new state listener first gets the current state, once, in a
microtask after on() returns; then every change. Events that arrived while connect() was running are
delivered in a task after it resolves, so listeners attached right after await connect() miss none of them.
Type Parameters
Section titled “Type Parameters”K extends keyof SessionEvents
Parameters
Section titled “Parameters”K
(e) => void
Returns
Section titled “Returns”() => void
resumeAudio()
Section titled “resumeAudio()”resumeAudio():
void
After a non-fatal audio_unavailable (the browser refused to play the voice): call it
synchronously in a click or tap handler. It resumes the audio and retries playing the voice inside that gesture;
the conversation goes on. If the browser still refuses, audio_unavailable is reported again. Does nothing after
ended.
Returns
Section titled “Returns”void
sendText()
Section titled “sendText()”sendText(
text):void
Sends a typed turn (at most 2,000 characters; longer throws RangeError).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void