feat: Implement TTS streaming and improve OpenRouter compatibility #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces streaming audio capabilities for the Text-to-Speech (TTS) API and enhances the Chat Completion parameters with
reasoningandstreamOptions. 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:
createStreamingSpeechmethod has been added to theOpenAIServiceprotocol, allowing for real-time audio data streaming.AudioSpeechParametersnow include astreamparameter to enable this functionality.AudioSpeechChunkObjecthas been introduced to represent individual chunks of the audio stream.AsyncHTTPClientAdapterandURLSessionHTTPClientAdapter) have been updated to handle byte streams for audio data, in addition to the existing line-based streams for text.AudioStreamingTests.swiftto validate the streaming audio functionality.Chat Completion Enhancements:
ChatCompletionParametersnow supportreasoningandstreamOptions, providing more control over the model's output and compatibility with OpenRouter's APIChatCompletionParametersTests.swiftensure these parameters are correctly encoded.Improved Error Handling:
Documentation:
README.mdhas been updated to reflect these new features and provide usage examples.These changes enhance the library's capabilitiesfor applications requiring real-time audio generation.