Skip to content

Add audio chat API support (gpt-4o-audio-preview, gpt-audio-1.5) - #397

Open
BugorBN wants to merge 2 commits into
MacPaw:mainfrom
BugorBN:feature/audio-chat-api
Open

BugorBN wants to merge 2 commits into
MacPaw:mainfrom
BugorBN:feature/audio-chat-api

Conversation

@BugorBN

@BugorBN BugorBN commented Nov 28, 2025

Copy link
Copy Markdown

Summary

This PR implements audio-to-audio chat completion support, replacing the traditional STT→Chat→TTS pipeline with a single API call for 2-3x faster response times.

Supports both gpt-4o-audio-preview / gpt-4o-mini-audio-preview (preview models) and the new gpt-audio-1.5 (recommended by OpenAI for best performance with improved instruction following, tool calling, and multilingual accuracy).

Features

  • Audio Chat API: Direct audio-to-audio conversations with audioChats() and audioChatsStream() methods
  • Type-safe enums: AudioFormat (wav, mp3, flac, opus, pcm16) and Voice (alloy, echo, fable, onyx, nova, shimmer)
  • Streaming support: Real-time audio chunk streaming with AsyncThrowingStream
  • AudioConversationManager: Actor-based utility for managing multi-turn conversations with automatic history tracking and pruning
  • Format requirements:
    • Input audio: wav and mp3 only
    • Output audio: wav, mp3, flac, opus, pcm16 (pcm16 recommended for streaming)
  • Relaxed parsing support: Handles missing fields gracefully, consistent with ChatResult behavior

Implementation Details

  • New models: AudioChatQuery, AudioChatResult, AudioChatStreamResult
  • Model constants: .gpt_4o_audio_preview, .gpt_4o_mini_audio_preview, .gpt_audio_1_5
  • Protocol updates: OpenAIProtocol, OpenAIAsync, with Combine support
  • Comprehensive documentation in README.md with usage examples
  • Full async/await and Combine publisher support

Testing

  • 38 passing tests across 4 test suites with 100% coverage:
    • AudioChatQueryCodingTests (8 tests)
    • AudioChatResultTests (9 tests)
    • AudioChatStreamResultTests (10 tests)
    • AudioConversationManagerTests (11 tests)

Files Changed

  • 14 files changed, 2,072 insertions, 4 deletions

Documentation

Added comprehensive Audio Chat section to README.md including:

  • API overview and benefits
  • Format requirements and recommendations
  • Request/response structure documentation
  • Non-streaming and streaming usage examples
  • AudioConversationManager examples

Breaking Changes

None - this is a purely additive change.

Related

- Add AudioChatQuery, AudioChatResult, AudioChatStreamResult models
- Implement audioChats() and audioChatsStream() methods
- Add type-safe enums: AudioFormat, Voice, Modality
- Add AudioConversationManager for multi-turn conversations
- Add support for gpt-4o-realtime-preview and gpt-4o-mini-realtime-preview models
- Add dated variants: 2024-12-17 snapshots
- Comprehensive test coverage (38 tests across 4 test suites)
- Update README with audio chat documentation and examples
- Format requirements: wav/mp3 for input, pcm16 recommended for streaming output
- Relaxed parsing support for handling missing fields
@BugorBN
BugorBN force-pushed the feature/audio-chat-api branch from 7d5804b to 7d385dd Compare November 29, 2025 09:47
@BugorBN BugorBN changed the title Add audio chat API support for gpt-4o-audio-preview model Add audio chat API support (gpt-4o-audio-preview, gpt-audio-1.5) Apr 3, 2026

@Krivoblotsky Krivoblotsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work here, and apologies for the wait. It merges cleanly with main, builds, and all 217 tests pass. I want to be upfront about the direction, because it affects most of the diff.

ChatQuery already covers audio chat. On main today: ChatQuery.modalities, ChatQuery.audioOptions (11 voices including ash, ballad, coral, sage, verse; formats mp3, opus, flac, wav, pcm16), ContentPartAudioParam for input_audio, ChatResult.Choice.Message.audio (id, expiresAt, data, transcript) and the same on the streaming delta. AudioChatQuery, AudioChatResult and AudioChatStreamResult are a second way to call /chat/completions with a smaller surface (6 voices, fewer parameters), and audioChats / audioChatsStream add four protocol requirements, which the new API-breakage gate flags. The library should have one way to do a chat completion.

AudioConversationManager is conversation state management, which belongs in the app (or the Demo), not in the SDK.

What we would like to take from this PR:

  • the gpt-audio-1.5 constant (plus gpt-audio and gpt-audio-mini), with gpt-4o-audio-preview marked deprecated since it was shut down on 7 May 2026;
  • a README section "Audio input and output with Chat Completions" built on ChatQuery, which the README lacks entirely today; your examples adapt almost one to one;
  • the coding tests, adapted to ChatQuery where they add coverage we do not have.

If you are up for reshaping the PR along those lines, that would be great and it would land quickly. If not, we can open a smaller PR that carries those pieces with you credited as co-author. Either way, thank you for pushing on audio support.

@BugorBN

BugorBN commented Sep 14, 2026

Copy link
Copy Markdown
Author

Thank you for the work here, and apologies for the wait. It merges cleanly with main, builds, and all 217 tests pass. I want to be upfront about the direction, because it affects most of the diff.

ChatQuery already covers audio chat. On main today: ChatQuery.modalities, ChatQuery.audioOptions (11 voices including ash, ballad, coral, sage, verse; formats mp3, opus, flac, wav, pcm16), ContentPartAudioParam for input_audio, ChatResult.Choice.Message.audio (id, expiresAt, data, transcript) and the same on the streaming delta. AudioChatQuery, AudioChatResult and AudioChatStreamResult are a second way to call /chat/completions with a smaller surface (6 voices, fewer parameters), and audioChats / audioChatsStream add four protocol requirements, which the new API-breakage gate flags. The library should have one way to do a chat completion.

AudioConversationManager is conversation state management, which belongs in the app (or the Demo), not in the SDK.

What we would like to take from this PR:

  • the gpt-audio-1.5 constant (plus gpt-audio and gpt-audio-mini), with gpt-4o-audio-preview marked deprecated since it was shut down on 7 May 2026;
  • a README section "Audio input and output with Chat Completions" built on ChatQuery, which the README lacks entirely today; your examples adapt almost one to one;
  • the coding tests, adapted to ChatQuery where they add coverage we do not have.

If you are up for reshaping the PR along those lines, that would be great and it would land quickly. If not, we can open a smaller PR that carries those pieces with you credited as co-author. Either way, thank you for pushing on audio support.

Hey, thanks for the feedback, I'll reshape it in the next couple days

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.

2 participants