Skip to content

Modernize Realtime API and full-duplex conversation flow - #195

Merged
jamesrochabrun merged 2 commits into
mainfrom
jroch-test-v1-fast
Jul 10, 2026
Merged

Modernize Realtime API and full-duplex conversation flow#195
jamesrochabrun merged 2 commits into
mainfrom
jroch-test-v1-fast

Conversation

@jamesrochabrun

Copy link
Copy Markdown
Owner

Summary

  • update the Realtime WebSocket client and session configuration for the GA event and payload shapes
  • buffer session events from creation and model expected item, audio, transcription, function-call, MCP, and rate-limit lifecycle events explicitly
  • add client-secret, function-output, item-truncation, and MCP approval request types
  • add a migration-oriented SwiftUI Realtime demo with stable transcript reduction and response-ID-aware tool continuation
  • implement full-duplex capture, playback interruption, and heard-audio truncation

Root cause

The previous demo coupled UI state to an incomplete event switch and did not preserve stable server item identity. Audio capture and playback also had an unsafe lifecycle: starting the audio engine before installing the voice-processing input tap could leave microphone capture silent, while using separate capture and playback graphs prevented reliable echo cancellation. Tool continuations were not bound to their originating response, allowing cancelled work to race with a new user turn.

Impact

Realtime conversations now keep microphone capture active for barge-in, stop local playback immediately on user speech, and truncate the assistant item to the duration actually heard. Capture and playback share one voice-processing graph, and the UI only reports Listening after the first microphone buffer arrives. A startup watchdog surfaces silent capture instead of leaving the demo in a misleading state.

The event reducer and coordinator are separated from SwiftUI rendering so the same lifecycle can be moved into other applications.

Validation

  • swiftformat --config rules.swiftformat --lint .
  • swift test — 93 tests passed
  • iOS Simulator SwiftOpenAIExampleTests — 10 tests passed
  • portable Realtime example parsed with swiftc -frontend -parse
  • git diff --check

@jamesrochabrun
jamesrochabrun marked this pull request as ready for review July 10, 2026 18:21
@jamesrochabrun
jamesrochabrun merged commit 4edec2b into main Jul 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant