Implement OpenAI-compatible TTS response format with backward compatibility #79
+280
−21
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.
This PR implements OpenAI-compatible response formats for TTS providers, improving interoperability with tools and applications that expect OpenAI's standardized API responses while maintaining 100% backward compatibility.
🎯 What Changed
New OpenAI-Compatible Response Structure
TTS providers now return structured response objects that match OpenAI's
audio.speech
format:Key Features
str(response)
returns audio file path for existing codeopenai_compatible=True/False
parameter for response format control📝 Usage Examples
OpenAI-Compatible Mode (Default)
Legacy Mode
Zero Breaking Changes
🔧 Technical Implementation
Files Added/Modified
webscout/Provider/TTS/openai_utils.py
- Core response structureswebscout/Provider/TTS/base.py
- Updated base provider with OpenAI supportwebscout/Provider/TTS/openai_fm.py
- Updated to use new response formatwebscout/Provider/TTS/streamElements.py
- Updated to use new response formatwebscout/Provider/TTS/__init__.py
- Export new response classesCore Components
TTSResponse
class with OpenAI-compatible structureTTSUsage
class for usage trackingcreate_tts_response()
helper functionBaseTTSProvider
withcreate_response()
method__str__()
and utility methods🎁 Benefits
For Developers
For Tools & Applications
🧪 Testing
Comprehensive test suite validates:
🔄 Migration Path
Immediate (No Action Required)
All existing code continues to work without modification.
Optional Enhancement
Developers can gradually adopt new features:
This implementation significantly improves Webscout's TTS capabilities' interoperability while ensuring zero disruption to existing codebases.
Fixes #74.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.