Files
magpie/internal
yetone 49e29de7ba gateway: Gemini TTS models on Vertex AI and Google Gemini speak on /v1/audio/speech (Pedram on Discord)
Pedram (Discord #help, 11-14) added gemini-*-tts models to a Vertex AI
provider by hand: listed, but every speech call failed. magpie sent the
OpenAI body to <base>/audio/speech: Vertex's …/endpoints/openapi/audio/speech
(404; express mode has no OpenAI base at all, a 400), and AI Studio's
…/v1beta/openai/audio/speech (404). Google serves Gemini's speech on
generateContent alone.

serveRetrieval now asks a retrieval for a vendor shape first
(nativeRetrieval). A speech request for a Gemini TTS model (ServesOf
speech, "gemini" in the id) on Vertex AI (not a partner or Claude model),
on AI Studio (its Gemini API beside the OpenAI one, as drawGemini asks),
or on a keys provider with only a Gemini API, goes to the model's
:generateContent, signed for the Gemini API (x-goog-api-key, or the
project's Google token on Vertex) - signing it as Chat sent the key as a
Bearer, which Gemini refuses:
- text: "instructions: input" (Gemini takes style in the prompt); speed
  has no Gemini field and is left out;
- responseModalities ["AUDIO"], prebuiltVoiceConfig.voiceName: a Gemini
  voice by its name in any case (Puck, Charon…), an OpenAI voice by the
  nearest Gemini one (alloy Kore, coral Sulafat, nova Zephyr, onyx
  Algenib, shimmer Achernar…), anything else Kore;
- the answer's 24 kHz 16-bit PCM is given back as a WAV (audio/wav) by
  default and for wav, raw for pcm (audio/pcm). mp3, opus, aac and flac
  are answered as a WAV too, with Content-Type audio/wav: magpie has no
  encoder, OpenAI clients ask mp3 by default so a 400 would fail them
  all, and players read a WAV by its header. Any other format, an empty
  input and stream_format sse are a 400 before anything is sent;
- an answer with no audio is a 502 naming the finish/block reason and
  any text Gemini said instead.
Masking, routing, key and account holds, side records and the usage row
(operation speech, Gemini's promptTokenCount/candidatesTokenCount) are
serveRetrieval's own, as for every speech call. A relay with an
OpenAI-style API of its own, and plugins, are asked as before.
pipeline_check's silentWAV now uses the shared pcmWAV.

The Settings Quick check (2c644da04) finds a hand-added Vertex TTS model
through p.Models and posts voice alloy through this route, so it now
checks it (alloy -> Kore). Found on the way: such a model also stays in
/v1/models and the chat lists as a chat model; #3279 fixed that for
plugins only. Filed as #6970, not changed here.

Tests (speech_gemini_test.go, fake upstreams, no network):
TestGeminiSpeechOnVertex, TestGeminiSpeechFormatsAndVoices,
TestGeminiSpeechWithoutAudio, TestGeminiSpeechOnAIStudio (masking, the
x-goog-api-key, and a relay still on /audio/speech). On origin/main code
all four are red (Vertex/AI Studio answered with the raw JSON or a 404
path).

Run (mote, mote-run): gofmt -l clean; go test -count=1 -timeout 45m ./internal/gateway
./internal/provider ok (gateway 986s, provider 178s) at base f9492fd8e;
GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... ok.
After rebase on b1d5912de (no upstream change to these files): gofmt,
go vet ./internal/gateway ./internal/provider and go test -run
"Speech|TestCheck|Embed|Vertex|Rerank|Transcri" ./internal/gateway ok.

Broken by hand: signing with provider.Chat -> TestGeminiSpeechOnAIStudio
red (auth "Bearer AIzaSy-test", no x-goog-api-key); dropping the OpenAI
voice map -> TestGeminiSpeechOnVertex red (voice Kore, not Sulafat);
restored, green.

Not tried: a real Gemini or Vertex call. The user's magpie config has no
AI Studio key or Vertex provider (its gemini provider is a sign-in), so
Google's real answer shape is taken from its docs. The GUI suite (no GUI
file changed).
2026-11-17 20:18:41 +08:00
..
…
…
…
…
…
…
…
…
2026-11-17 15:09:29 +08:00
…