Skip to content

feat: support streaming API for TTS and STT models#36

Open
thesaadmirza wants to merge 4 commits intogpustack:mainfrom
thesaadmirza:feat/streaming-api
Open

feat: support streaming API for TTS and STT models#36
thesaadmirza wants to merge 4 commits intogpustack:mainfrom
thesaadmirza:feat/streaming-api

Conversation

@thesaadmirza
Copy link

gpustack/gpustack#962

Add streaming support to the TTS and STT endpoints so audio/text can be sent to the client incrementally as it's generated.

TTS (/v1/audio/speech):

  • stream: true + response_format: pcm returns a StreamingResponse of raw PCM int16 chunks
  • CosyVoice backend implements streaming via inference_sft(stream=True)
  • Backends that don't support streaming return 400

STT (/v1/audio/transcriptions):

  • stream: true returns Server-Sent Events with one JSON object per segment
  • FasterWhisper backend yields segments incrementally
  • Backends that don't support streaming return 400

Non-streaming behavior is unchanged.

Add streaming support to TTS (speech) and STT (transcriptions) endpoints.

TTS streaming:
- Add is_stream_supported() and speech_stream() to TTSBackend base class
- Implement streaming in CosyVoice backend via inference_sft(stream=True)
- Stream raw PCM int16 audio chunks (response_format=pcm required)

STT streaming:
- Add is_stream_supported() and transcribe_stream() to STTBackend base class
- Implement streaming in FasterWhisper backend, yielding segments as JSON
- Use Server-Sent Events format for text streaming

API changes:
- Add stream field to SpeechRequest (default: false)
- Parse stream from transcription form data
- Return StreamingResponse for streaming requests
- Extract _parse_transcription_form() to keep endpoint complexity in check
- Add sse_stream() helper for SSE formatting

Ref: gpustack/gpustack#962
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces streaming capabilities to the Text-to-Speech (TTS) and Speech-to-Text (STT) API endpoints. This enhancement allows for the incremental delivery of audio or text as it is generated, significantly improving responsiveness for real-time applications by providing partial results sooner.

Highlights

  • TTS Streaming Support: The /v1/audio/speech endpoint now supports streaming when stream: true and response_format: pcm are specified, returning raw PCM int16 audio chunks via StreamingResponse.
  • CosyVoice Backend Integration: The CosyVoice backend has been updated to leverage its inference_sft(stream=True) method for real-time TTS streaming.
  • STT Streaming Support: The /v1/audio/transcriptions endpoint now supports streaming via Server-Sent Events (SSE) when stream: true, delivering JSON objects for each transcribed segment.
  • FasterWhisper Backend Integration: The FasterWhisper backend has been adapted to yield transcription segments incrementally for STT streaming.
  • Backend Compatibility Handling: Backends that do not explicitly support streaming will now return a 400 error if a streaming request is made.
  • Non-Streaming Behavior Unchanged: Existing non-streaming functionalities for both TTS and STT remain unchanged.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • vox_box/backends/stt/base.py
    • Introduced is_stream_supported method, defaulting to False.
    • Added transcribe_stream method, raising NotImplementedError for non-streaming backends.
  • vox_box/backends/stt/faster_whisper.py
    • Overrode is_stream_supported to return True.
    • Implemented transcribe_stream to yield JSON-formatted text segments incrementally.
  • vox_box/backends/tts/base.py
    • Introduced is_stream_supported method, defaulting to False.
    • Added speech_stream method, raising NotImplementedError for non-streaming backends.
  • vox_box/backends/tts/cosyvoice.py
    • Overrode is_stream_supported to return True.
    • Implemented speech_stream to yield raw PCM audio chunks from the model output.
  • vox_box/server/routers.py
    • Imported StreamingResponse from fastapi.responses.
    • Added a stream boolean field to the SpeechRequest Pydantic model.
    • Implemented conditional logic in the /v1/audio/speech endpoint to handle streaming requests, validating response_format and returning StreamingResponse.
    • Extracted transcription form parsing into a new asynchronous helper function _parse_transcription_form.
    • Added stream parameter parsing to the transcription form.
    • Implemented conditional logic in the /v1/audio/transcriptions endpoint to handle streaming requests, validating backend support and returning StreamingResponse with SSE.
    • Added sse_stream utility function to format generator output as Server-Sent Events.
    • Adjusted exception handling to re-raise HTTPException directly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces streaming capabilities for both Text-to-Speech (TTS) and Speech-to-Text (STT) endpoints, which is a significant feature enhancement. For TTS, streaming is enabled via stream: true on the /v1/audio/speech endpoint, returning raw PCM data, with the CosyVoice backend updated to support this. For STT, the /v1/audio/transcriptions endpoint now supports streaming through Server-Sent Events, with an implementation provided for the FasterWhisper backend. The changes are well-structured, including necessary updates to base classes and a helpful refactoring of the form parsing logic in the router. My review includes a couple of suggestions to improve robustness and performance.

Saad ur Rehman and others added 3 commits February 27, 2026 00:15
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant