Skip to content

feat: add OpenRouter as a speech (TTS) provider#1302

Open
monolithic827 wants to merge 2 commits intomoeru-ai:mainfrom
monolithic827:openrouter-tts
Open

feat: add OpenRouter as a speech (TTS) provider#1302
monolithic827 wants to merge 2 commits intomoeru-ai:mainfrom
monolithic827:openrouter-tts

Conversation

@monolithic827
Copy link

Summary

  • Add OpenRouter as a built-in speech provider, using the /chat/completions API with audio modality (modalities: ["text", "audio"]) since OpenRouter does not support the /audio/speech endpoint
  • Fetches available audio models dynamically from /models?output_modality=audio
  • Fix a race condition in the speech store where provider selection was reset on startup before async validation completed (affects all speech providers, not just OpenRouter)

Details

OpenRouter supports audio output through its chat completions API with streaming. The provider bridges this into the existing SpeechProvider interface using a custom fetch that:

  1. Sends a streaming chat completion request with modalities: ["text", "audio"] and format: "pcm16"
  2. Parses SSE chunks, collecting base64-encoded delta.audio.data
  3. Wraps the decoded PCM16 data in a WAV header so the browser can play it

Files changed

  • packages/stage-ui/src/stores/providers.ts - new openrouter-audio-speech provider metadata entry; expose providerRuntimeState
  • packages/stage-pages/src/pages/settings/providers/speech/openrouter-audio-speech.vue - settings page with model selector and speech playground
  • packages/i18n/src/locales/en/settings.yaml - i18n entries
  • packages/stage-ui/src/stores/modules/speech.ts - fix startup race condition that cleared persisted speech provider selection before validation ran

@gemini-code-assist
Copy link
Contributor

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 a significant enhancement by adding OpenRouter as a new speech provider, expanding the platform's text-to-speech capabilities. It ensures a robust and dynamic integration by fetching models on the fly and includes a crucial fix to prevent an existing race condition from affecting provider selection stability.

Highlights

  • New Speech Provider: OpenRouter has been integrated as a new built-in speech (Text-to-Speech) provider, leveraging its /chat/completions API with audio modality.
  • Dynamic Model Fetching: The OpenRouter speech provider dynamically fetches available audio models from the /models?output_modality=audio endpoint, ensuring up-to-date model selection.
  • Race Condition Fix: A race condition in the speech store was resolved, preventing the premature resetting of the selected speech provider before asynchronous validation of credentials could complete.
  • Audio Processing: The OpenRouter integration handles streaming SSE responses, decodes base64-encoded PCM16 audio data, and wraps it in a WAV header for direct browser playback.
Changelog
  • packages/stage-pages/src/pages/settings/providers/speech/openrouter-audio-speech.vue
    • Added a new Vue component for OpenRouter speech provider settings, including model selection and a speech playground.
  • packages/stage-ui/src/stores/modules/speech.ts
    • Fixed a race condition in the speech store that prevented premature resetting of the active speech provider before async validation completed.
  • packages/stage-ui/src/stores/providers.ts
    • Integrated OpenRouter as a new speech provider, including API interaction for streaming audio, dynamic model fetching, and voice listing.
    • Exposed providerRuntimeState from the providers store to support robust state management.
Ignored Files
  • Ignored by pattern: packages/i18n/src/** (1)
    • packages/i18n/src/locales/en/settings.yaml
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
Contributor

@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 OpenRouter as a new text-to-speech provider, which is a great addition. The implementation cleverly uses the chat completions endpoint with audio modality to generate speech, including constructing a WAV header on the fly. The PR also includes a fix for a race condition in the speech store during provider validation.

My review focuses on improving code maintainability and robustness. I've suggested simplifying duplicated logic for handling the base URL, adding logging for silently handled errors, and improving the readability of the WAV header creation code. These changes should make the new provider implementation easier to understand and maintain.

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