NowVoiceCallbacks structure - iOS
Specifies callbacks for voice session lifecycle and content events.
NowVoiceCallbacks - init(onMuteStateChanged: ((Bool) -> Void)?, onMessageReceived: ((NowVoiceTranscriptMessage) -> Void)?, onCallEnded: NowVoiceDismissHandler?)
Creates a NowVoiceCallbacks instance with the specified voice session event handlers.
A NowVoiceAgentError is delivered as the second parameter of the onCallEnded callback.
| Case | Description |
|---|---|
.connectionTimeout |
The connection to the voice agent timed out. |
.connectionFailed |
A connection to the voice agent could not be established. |
.disconnectedUnexpectedly |
The connection dropped during an active session. |
.serverEnded |
The server terminated the session. |
| Name | Type | Description |
|---|---|---|
| onMuteStateChanged | ((Bool) -> Void)? | Called each time the user mutes or unmutes the microphone. The Bool parameter is true when the microphone is muted. |
| onMessageReceived | ((NowVoiceTranscriptMessage) -> Void)? | Called each time a new transcript message arrives during the session. |
| onCallEnded | NowVoiceDismissHandler? | Called when the voice UI is dismissed. Delivers the conversation identifier and an optional error. |
| onCallMinimized | (() -> Void)? | Called when the voice session UI is minimized by the user. |
The following code example shows how to initialize a NowVoiceCallbacks. In each callback function, implement the desired functionality for handling the event.
let callbacks = NowVoiceCallbacks(
onMuteStateChanged: { isMuted in
// Update your UI to reflect the current mute state.
print("Microphone muted: \(isMuted)")
},
onMessageReceived: { message in
// Receive real-time transcript messages during the session.
print("[\(message.role)]: \(message.text)")
},
onCallEnded: { conversationId, error in
// Called when the voice session ends.
if let error {
print("Session ended with error: \(error)")
} else {
print("Session complete. Conversation ID: \(conversationId ?? "unknown")")
}
},
onCallMinimized: {
// Called when the voice UI is minimized.
print("Voice chat is minimized")
}
)