Repository navigation
feat: openai tts support streaming realtime audio - #2086
Conversation
WalkthroughIntroduces a streaming helper function Changes
Sequence DiagramsequenceDiagram
participant Client
participant OpenaiTTSHandler
participant streamTTSResponse
participant HTTPResponseWriter
Client->>OpenaiTTSHandler: Request TTS
OpenaiTTSHandler->>OpenaiTTSHandler: Check ContentLength
alt Streaming Response (ContentLength == 0)
OpenaiTTSHandler->>streamTTSResponse: Call streamTTSResponse()
loop For each chunk
streamTTSResponse->>HTTPResponseWriter: Write chunk
streamTTSResponse->>HTTPResponseWriter: Flush
end
streamTTSResponse->>Client: Stream delivered
else Non-Streaming Response
OpenaiTTSHandler->>HTTPResponseWriter: WriteHeader
OpenaiTTSHandler->>HTTPResponseWriter: Copy body
OpenaiTTSHandler->>Client: Response sent
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Single file with localized changes introducing a new helper function and conditional branching. The modification is straightforward: detecting streaming capability and routing to appropriate handler. Clear separation of concerns between streaming and non-streaming paths minimizes review complexity. Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
relay/channel/openai/relay-openai.go (2)
292-292: Remove commented-out debug code.The commented-out log line should be removed before merging to production.
- //logger.LogInfo(c, fmt.Sprintf("streamTTSResponse read %d bytes", n))
325-334: Consider checking Transfer-Encoding header for more robust streaming detection.The OpenAI TTS API uses chunk transfer encoding for streaming, and the standard HTTP way to indicate this is via the
Transfer-Encoding: chunkedheader. While the current logic should work for most cases, consider making it more robust:- isStreaming := resp.ContentLength == -1 || resp.Header.Get("Content-Length") == "" + isStreaming := resp.ContentLength == -1 || + resp.Header.Get("Content-Length") == "" || + resp.Header.Get("Transfer-Encoding") == "chunked"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/channel/openai/relay-openai.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
relay/channel/openai/relay-openai.go (1)
logger/logger.go (2)
LogWarn(61-63)LogError(65-67)
🔇 Additional comments (1)
relay/channel/openai/relay-openai.go (1)
276-307: Solid implementation of streaming TTS support.The implementation correctly handles both streaming and non-streaming responses with appropriate buffering, flushing, and error handling. The changes maintain backward compatibility and follow the existing patterns in the codebase.
Key strengths:
- Proper header management and flushing for streaming
- Graceful fallback when flusher is not available
- Correct EOF handling (not logged as error)
- Error logging at appropriate places
- Reasonable buffer size (4096 bytes) for streaming
Also applies to: 325-334
…ream feat: openai tts support streaming realtime audio
…ream feat: openai tts support streaming realtime audio
…ream feat: openai tts support streaming realtime audio
OpenAI TTS支持流式实时音频
Summary by CodeRabbit