SwiftOpenAI
SwiftOpenAI copied to clipboard
feat: Implement TTS streaming and improve OpenRouter compatibility
Summary
This pull request introduces streaming audio capabilities for the Text-to-Speech (TTS) API and enhances the Chat Completion parameters with reasoning and streamOptions. These revisions were made mostly through prompt engineering with Claude and OpenAI Codex, and I've done my best to verify that they are cleanly implemented, make sense, and have been tested in my application.
Key Changes
-
Streaming Audio for Text-to-Speech:
- A new
createStreamingSpeechmethod has been added to theOpenAIServiceprotocol, allowing for real-time audio data streaming. - The
AudioSpeechParametersnow include astreamparameter to enable this functionality. - A new
AudioSpeechChunkObjecthas been introduced to represent individual chunks of the audio stream. - The underlying networking components (
AsyncHTTPClientAdapterandURLSessionHTTPClientAdapter) have been updated to handle byte streams for audio data, in addition to the existing line-based streams for text. - New tests have been added in
AudioStreamingTests.swiftto validate the streaming audio functionality.
- A new
-
Chat Completion Enhancements:
- The
ChatCompletionParametersnow supportreasoningandstreamOptions, providing more control over the model's output and compatibility with OpenRouter's API - New tests in
ChatCompletionParametersTests.swiftensure these parameters are correctly encoded.
- The
-
Improved Error Handling:
- Error messages for unsuccessful API responses now include the response body for improved OpenRouter compatibility
-
Documentation:
- The
README.mdhas been updated to reflect these new features and provide usage examples.
- The
These changes enhance the library's capabilitiesfor applications requiring real-time audio generation.