-
Notifications
You must be signed in to change notification settings - Fork 309
feat(google): add Gemini 3.1 Flash TTS support #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rosetta-livekit-bot
wants to merge
1
commit into
1.5.0
Choose a base branch
from
port-gemini-31-flash-tts
base: 1.5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−28
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@livekit/agents-plugin-google': patch | ||
| --- | ||
|
|
||
| Update Gemini TTS to default to Gemini 3.1 Flash TTS preview and stream generated audio chunks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-FileCopyrightText: 2026 LiveKit, Inc. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { type JobContext, ServerOptions, cli, defineAgent, voice } from '@livekit/agents'; | ||
| import * as deepgram from '@livekit/agents-plugin-deepgram'; | ||
| import * as google from '@livekit/agents-plugin-google'; | ||
| import { BackgroundVoiceCancellation } from '@livekit/noise-cancellation-node'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| class GeminiTTSAgent extends voice.Agent { | ||
| async onEnter() { | ||
| this.session.generateReply({ instructions: 'greet the user and introduce yourself' }); | ||
| } | ||
| } | ||
|
|
||
| export default defineAgent({ | ||
| entry: async (ctx: JobContext) => { | ||
| const agent = new GeminiTTSAgent({ | ||
| instructions: 'Your name is Kelly. Respond briefly and concisely using voice conversation.', | ||
| }); | ||
|
|
||
| const session = new voice.AgentSession({ | ||
| stt: new deepgram.STT(), | ||
| llm: new google.LLM({ model: 'gemini-2.5-flash' }), | ||
| tts: new google.beta.TTS({ | ||
| apiKey: process.env.GOOGLE_API_KEY, | ||
| voiceName: 'Kore', | ||
| model: 'gemini-3.1-flash-tts-preview', | ||
| }), | ||
| }); | ||
|
|
||
| await session.start({ | ||
| agent, | ||
| room: ctx.room, | ||
| inputOptions: { | ||
| noiseCancellation: BackgroundVoiceCancellation(), | ||
| }, | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| cli.runApp(new ServerOptions({ agent: fileURLToPath(import.meta.url) })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 AudioByteStream.flush() produces 0-sample frame when buffer is empty
When all audio data aligns perfectly with the AudioByteStream frame size (bytesPerFrame = 4800 bytes for 24kHz mono at 100ms), the internal buffer is empty at flush time.
AudioByteStream.flush()atagents/src/audio.ts:76-93doesn't guard against an empty buffer — it always returns an array with one frame, even if that frame has 0 samples. This 0-sample frame becomeslastFrameand is emitted as thefinal: trueframe. The resemble plugin guards against this (plugins/resemble/src/tts.ts:155:if (frame.samplesPerChannel === 0) continue), but most other plugins don't. This is a pre-existing issue not introduced by this PR — the old Gemini code had the same exposure.Was this helpful? React with 👍 or 👎 to provide feedback.