Module livekit.plugins.google.beta
Sub-modules
livekit.plugins.google.beta.realtime
Classes
class GeminiTTS (*,
model: GEMINI_TTS_MODELS | str = 'gemini-2.5-flash-preview-tts',
voice_name: GEMINI_VOICES | str = 'Kore',
api_key: NotGivenOr[str] = NOT_GIVEN,
vertexai: NotGivenOr[bool] = NOT_GIVEN,
project: NotGivenOr[str] = NOT_GIVEN,
location: NotGivenOr[str] = NOT_GIVEN,
instructions: NotGivenOr[str | None] = NOT_GIVEN)-
Expand source code
class TTS(tts.TTS): def __init__( self, *, model: GEMINI_TTS_MODELS | str = DEFAULT_MODEL, voice_name: GEMINI_VOICES | str = DEFAULT_VOICE, api_key: NotGivenOr[str] = NOT_GIVEN, vertexai: NotGivenOr[bool] = NOT_GIVEN, project: NotGivenOr[str] = NOT_GIVEN, location: NotGivenOr[str] = NOT_GIVEN, instructions: NotGivenOr[str | None] = NOT_GIVEN, ) -> None: """ Create a new instance of Gemini TTS. Environment Requirements: - For VertexAI: Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of the service account key file. - For Google Gemini API: Set the `api_key` argument or the `GOOGLE_API_KEY` environment variable. Args: model (str, optional): The Gemini TTS model to use. Defaults to "gemini-2.5-flash-preview-tts". voice_name (str, optional): The voice to use for synthesis. Defaults to "Kore". api_key (str, optional): The API key for Google Gemini. If not provided, it attempts to read from the `GOOGLE_API_KEY` environment variable. vertexai (bool, optional): Whether to use VertexAI. Defaults to False. project (str, optional): The Google Cloud project to use (only for VertexAI). location (str, optional): The location to use for VertexAI API requests. Defaults to "us-central1". instructions (str, optional): Control the style, tone, accent, and pace using prompts. See https://ai.google.dev/gemini-api/docs/speech-generation#controllable """ # noqa: E501 super().__init__( capabilities=tts.TTSCapabilities(streaming=False), sample_rate=DEFAULT_SAMPLE_RATE, num_channels=NUM_CHANNELS, ) gcp_project: str | None = ( project if is_given(project) else os.environ.get("GOOGLE_CLOUD_PROJECT") ) gcp_location: str | None = ( location if is_given(location) else os.environ.get("GOOGLE_CLOUD_LOCATION") or "us-central1" ) use_vertexai = ( vertexai if is_given(vertexai) else os.environ.get("GOOGLE_GENAI_USE_VERTEXAI", "0").lower() in ["true", "1"] ) gemini_api_key = api_key if is_given(api_key) else os.environ.get("GOOGLE_API_KEY") if use_vertexai: if not gcp_project: from google.auth._default_async import default_async _, gcp_project = default_async( # type: ignore scopes=["https://www.googleapis.com/auth/cloud-platform"] ) gemini_api_key = None # VertexAI does not require an API key else: gcp_project = None gcp_location = None if not gemini_api_key: raise ValueError( "API key is required for Google API either via api_key or GOOGLE_API_KEY environment variable" # noqa: E501 ) self._opts = _TTSOptions( model=model, voice_name=voice_name, vertexai=use_vertexai, project=gcp_project, location=gcp_location, instructions=instructions if is_given(instructions) else DEFAULT_INSTRUCTIONS, ) self._client = Client( api_key=gemini_api_key, vertexai=use_vertexai, project=gcp_project, location=gcp_location, ) def synthesize( self, text: str, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS ) -> ChunkedStream: return ChunkedStream(tts=self, input_text=text, conn_options=conn_options) def update_options( self, *, voice_name: NotGivenOr[str] = NOT_GIVEN, ) -> None: """ Update the TTS options. Args: voice_name (str, optional): The voice to use for synthesis. """ if is_given(voice_name): self._opts.voice_name = voice_name
Helper class that provides a standard way to create an ABC using inheritance.
Create a new instance of Gemini TTS.
Environment Requirements: - For VertexAI: Set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to the path of the service account key file. - For Google Gemini API: Set theapi_key
argument or theGOOGLE_API_KEY
environment variable.Args
model
:str
, optional- The Gemini TTS model to use. Defaults to "gemini-2.5-flash-preview-tts".
voice_name
:str
, optional- The voice to use for synthesis. Defaults to "Kore".
api_key
:str
, optional- The API key for Google Gemini. If not provided, it attempts to read from the
GOOGLE_API_KEY
environment variable. vertexai
:bool
, optional- Whether to use VertexAI. Defaults to False.
project
:str
, optional- The Google Cloud project to use (only for VertexAI).
location
:str
, optional- The location to use for VertexAI API requests. Defaults to "us-central1".
instructions
:str
, optional- Control the style, tone, accent, and pace using prompts. See https://ai.google.dev/gemini-api/docs/speech-generation#controllable
Ancestors
- livekit.agents.tts.tts.TTS
- abc.ABC
- EventEmitter
- typing.Generic
Methods
def synthesize(self,
text: str,
*,
conn_options: APIConnectOptions = APIConnectOptions(max_retry=3, retry_interval=2.0, timeout=10.0)) ‑> livekit.plugins.google.beta.gemini_tts.ChunkedStream-
Expand source code
def synthesize( self, text: str, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS ) -> ChunkedStream: return ChunkedStream(tts=self, input_text=text, conn_options=conn_options)
def update_options(self, *, voice_name: NotGivenOr[str] = NOT_GIVEN) ‑> None
-
Expand source code
def update_options( self, *, voice_name: NotGivenOr[str] = NOT_GIVEN, ) -> None: """ Update the TTS options. Args: voice_name (str, optional): The voice to use for synthesis. """ if is_given(voice_name): self._opts.voice_name = voice_name
Update the TTS options.
Args
voice_name
:str
, optional- The voice to use for synthesis.
Inherited members