Implement OpenAI-compatible TTS response format with backward compatibility #79
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.speechformat:{ "id": "tts-550e8400-e29b-41d4-a716-446655440000", "object": "audio.speech", "created": 1677858242, "model": "webscout-tts-v1", "voice": "alloy", "response_format": "mp3", "audio_file": "/path/to/generated/audio.mp3", "usage": { "characters": 42, "total_characters": 42 } }Key Features
str(response)returns audio file path for existing codeopenai_compatible=True/Falseparameter 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
TTSResponseclass with OpenAI-compatible structureTTSUsageclass for usage trackingcreate_tts_response()helper functionBaseTTSProviderwithcreate_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.