> ## AI Agent Context > - Full documentation index: https://aistudio.google.com/llms.txt > - Gemini Docs MCP server (consistent live info): https://gemini-api-docs-mcp.dev > - Coding agent skills & setup guide: https://aistudio.google.com/docs/coding-agents.md # Live translation with Gemini Live API The Gemini Live API supports low-latency, real-time speech to speech translation between 70+ languages using the [`gemini-4-live-translate`](/docs/models/gemini-4-live-translate) model. By configuring the Live API with translation settings, you can stream audio in one language and receive translated audio output in another language, enabling seamless real-time voice-to-voice translation. {% button href="https://aistudio.google.com/live?model=gemini-4-live-translate" icon="mic" variant="primary" %}Try in AI Studio{% /button %} {% button href="https://github.com/google-gemini/gemini-live-api-examples" icon="code" variant="primary" %}Clone examples from GitHub{% /button %} {% button href="/docs/coding-agents#gemini-live-api-dev" icon="terminal" variant="primary" %}Use coding agent skills{% /button %} ## Live Agent vs. Live Translation {% id="live-agent-vs-live-translation" %} While both use the Live API, the mental model for Live Translation is different from conversational real-time agent interactions. | Live Agent | Live Translation | | :--- | :--- | | **The model acts as an assistant.** It listens, reasons, and takes actions on your behalf. | **The model acts as an interpreter.** It behaves as a real-time translator pipeline. | | **Uses turn-based interactions.** Relies on pauses, intent detection, and handles interruptions. | **Uses continuous stream processing.** Translates as the speaker talks without waiting for turns. | | **Supports tools and agents.** Native support for function calling, Google Search, and instructions. | **Supports translation only.** Pure low-latency translation; supports system instructions to guide translation, with no support for tools. | | **Fully multimodal.** Supports text, audio, video, and image inputs. | **Audio restricted.** Input is limited to audio to ensure strict real-time latency thresholds. | | **Granular configuration.** Uses generation, speech, tools, and system instructions. | **Simplified configuration.** Set `target_language_code`, `echo_target_language`, optional `speech_config` for preset voices, and optional `system_instruction`. | ## Get started {% id="get-started" %} The following examples demonstrate how to initialize a client and connect to the Live API with a translation configuration. {% tabs %} {% tab filename="live_translate.py" label="Python" %} ```python import asyncio from google import genai from google.genai import types client = genai.Client(http_options={"api_version": "v1beta"}) model = "gemini-4-live-translate" config = types.LiveConnectConfig( response_modalities=["AUDIO"], input_audio_transcription=types.AudioTranscriptionConfig(), output_audio_transcription=types.AudioTranscriptionConfig(), translation_config=types.TranslationConfig( target_language_code="pl", echo_target_language=True ) ) async def main(): async with client.aio.live.connect(model=model, config=config) as session: print("Session started with translation") # Start receiving the translated audio stream async for response in session.receive(): if response.server_content: if response.server_content.input_transcription: print(f"Input transcript: {response.server_content.input_transcription.text}") if response.server_content.output_transcription: print(f"Output transcript: {response.server_content.output_transcription.text}") if response.server_content.model_turn: for part in response.server_content.model_turn.parts: if part.inline_data: audio_data = part.inline_data.data # Play or process the translated audio chunk print(f"Received audio chunk ({len(audio_data)} bytes)") if __name__ == "__main__": asyncio.run(main()) ``` {% /tab %} {% tab filename="live_translate.js" label="JavaScript" %} ```javascript import { GoogleGenAI, Modality } from '@google/genai'; const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } }); const model = 'gemini-4-live-translate'; const config = { responseModalities: [Modality.AUDIO], inputAudioTranscription: {}, outputAudioTranscription: {}, translationConfig: { targetLanguageCode: 'pl', echoTargetLanguage: true } }; async function main() { const session = await ai.live.connect({ model: model, config: config, callbacks: { onopen: () => console.debug('Opened'), onmessage: (message) => { const content = message.serverContent; if (content?.inputTranscription) { console.log('Input transcript:', content.inputTranscription.text); } if (content?.outputTranscription) { console.log('Output transcript:', content.outputTranscription.text); } if (content?.modelTurn?.parts) { for (const part of content.modelTurn.parts) { if (part.inlineData) { const audioData = part.inlineData.data; // Play or process the translated audio chunk (base64 encoded) console.debug(`Received audio chunk (${audioData.length} bytes)`); } } } }, onerror: (e) => console.debug('Error:', e.message), onclose: (e) => console.debug('Close:', e.reason), }, }); console.debug("Session started with translation"); } await main(); ``` {% /tab %} {% tab filename="live_translate.js" label="WebSockets" %} ```javascript const API_KEY = "YOUR_API_KEY"; const MODEL_NAME = "gemini-4-live-translate"; const WS_URL = `wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key=${API_KEY}`; const websocket = new WebSocket(WS_URL); websocket.onopen = () => { console.log('WebSocket Connected'); const setupMessage = { setup: { model: `models/${MODEL_NAME}`, inputAudioTranscription: {}, outputAudioTranscription: {}, generationConfig: { responseModalities: ['AUDIO'], translationConfig: { targetLanguageCode: 'pl', echoTargetLanguage: true } } } }; websocket.send(JSON.stringify(setupMessage)); }; websocket.onmessage = (event) => { const response = JSON.parse(event.data); if (response.serverContent) { const content = response.serverContent; if (content.inputTranscription) { console.log('Input transcript:', content.inputTranscription.text, `(${content.inputTranscription.languageCode})`); } if (content.outputTranscription) { console.log('Output transcript:', content.outputTranscription.text, `(${content.outputTranscription.languageCode})`); } if (content.modelTurn?.parts) { for (const part of content.modelTurn.parts) { if (part.inlineData) { const audioData = part.inlineData.data; // Play or process the translated audio chunk (base64 encoded) console.debug(`Received audio chunk (${audioData.length} bytes)`); } } } } }; ``` {% /tab %} {% /tabs %} ## Sending audio {% id="sending-audio" %} To stream voice inputs for translation, you send raw, little-endian, 16-bit PCM audio. * **Input audio format**: Raw 16-bit PCM at 16kHz (mono, little-endian). * **Output audio format**: Raw 16-bit PCM at 24kHz (mono, little-endian). * **Chunk Size and Latency**: Send audio in chunks of 100ms. {% callout type="note" %} Only audio input is supported for translation. Text input is not supported. {% /callout %} The following examples show how to send audio chunks to the session. {% tabs %} {% tab filename="live_translate.py" label="Python" %} ```python # Assuming 'chunk' is your raw PCM audio bytes await session.send_realtime_input( audio=types.Blob( data=chunk, mime_type="audio/pcm;rate=16000" ) ) ``` {% /tab %} {% tab filename="live_translate.js" label="JavaScript" %} ```javascript // Assuming 'chunk' is a Buffer of raw PCM audio session.sendRealtimeInput({ audio: { data: chunk.toString('base64'), mimeType: 'audio/pcm;rate=16000' } }); ``` {% /tab %} {% tab filename="live_translate.js" label="WebSockets" %} ```javascript // Assuming 'chunk' is a Buffer of raw PCM audio function sendAudioChunk(chunk) { if (websocket.readyState === WebSocket.OPEN) { const audioMessage = { realtimeInput: { audio: { data: chunk.toString('base64'), mimeType: 'audio/pcm;rate=16000' } } }; websocket.send(JSON.stringify(audioMessage)); } } ``` {% /tab %} {% /tabs %} ## Configuration {% id="configuration" %} To enable translation, you must specify the `translationConfig` within the `generationConfig` during the session setup. ### Setup message configuration {% id="setup-message-configuration" %} The `setup` message supports [`systemInstruction`](/docs/live-api/live-translate#system-instructions) to provide custom translation context (such as glossaries, terminology, and register) at the start of the session. The `setup` message also supports the following fields to enable transcripts: * **`inputAudioTranscription`**: An object that, when present, enables the model to send text transcripts of the input audio. * **`outputAudioTranscription`**: An object that, when present, enables the model to send text transcripts of the output (translated) audio. The `translationConfig` supports the following fields: * **`targetLanguageCode`**: The [BCP-47 language code](/docs/live-api/live-translate#supported-languages) of the language you want the model to translate into (e.g., `"pl"` for Polish, `"es"` for Spanish). Defaults to `"en"`. * **`echoTargetLanguage`**: A boolean indicating how input audio that is already in the target language should be handled. If set to `true`, the model will echo (parrot) input audio that is already in the target language. If set to `false`, the model will stay silent when the input speech is already in the target language. Defaults to `false`. As a sibling of `translationConfig` inside `generationConfig`, you can also set `speechConfig`: * **`speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName`** (optional): Name of a preset voice from the extended voice library (over 2,000 preset voices) to use for all translated audio in the session. When omitted, the model uses instant voice replication to mirror each speaker's tone, pacing, and pitch by default. Voices created via the Voices API (`POST /v1beta/voices`) are not supported. Here is an example of the setup message structure: ```json { "setup": { "model": "models/gemini-4-live-translate", "systemInstruction": { "parts": [ { "text": "Translate for a conference audience using formal Spanish (usted/ustedes). Always translate 'deployment pipeline' as 'canalización de despliegue' and keep product names like 'Cloud Run' untranslated." } ] }, "inputAudioTranscription": {}, "outputAudioTranscription": {}, "generationConfig": { "responseModalities": [ "AUDIO" ], "translationConfig": { "targetLanguageCode": "es", "echoTargetLanguage": false } } } } ``` ### Choosing a voice for translated audio {% id="choosing-a-voice" %} By default, Gemini 4 Live Translate uses instant voice replication to mirror each speaker's tone, pacing, and pitch. For a consistent voice across long sessions, pick a preset voice from the extended voice library (over 2,000 preset voices) in `speech_config` (`speechConfig`) during setup. Browse preset voices in [Google AI Studio](https://aistudio.google.com/live?model=gemini-4-live-translate), or list them programmatically with `client.voices.list(type_=["prebuilt"])` (`ai.voices.list({ type: ["prebuilt"] })` / `GET /v1beta/voices?type=prebuilt`). Filtering by `prebuilt` is required because unfiltered `voices.list()` also returns custom voices created via the Voices API (`POST /v1beta/voices`), which `gemini-4-live-translate` does not support (passing a `voice_...` ID or `voicekey_...` fails at session setup with `400 INVALID_ARGUMENT`). When you set a preset voice, the model uses it for every speaker in the session. You cannot change the voice mid-stream. Keep the default instant voice replication when you need to distinguish multiple speakers by voice. Transcripts, `echo_target_language`, and pricing stay the same. {% tabs %} {% tab filename="live_translate_voice.py" label="Python" %} ```python import asyncio from google import genai from google.genai import types client = genai.Client(http_options={"api_version": "v1beta"}) model = "gemini-4-live-translate" config = types.LiveConnectConfig( response_modalities=["AUDIO"], input_audio_transcription=types.AudioTranscriptionConfig(), output_audio_transcription=types.AudioTranscriptionConfig(), translation_config=types.TranslationConfig( target_language_code="es", echo_target_language=False, ), speech_config=types.SpeechConfig( voice_config=types.VoiceConfig( prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Kore") ) ), ) async def main(): async with client.aio.live.connect(model=model, config=config) as session: async for response in session.receive(): if response.server_content and response.server_content.model_turn: for part in response.server_content.model_turn.parts: if part.inline_data: audio_data = part.inline_data.data # 24 kHz PCM in the selected voice if __name__ == "__main__": asyncio.run(main()) ``` {% /tab %} {% tab filename="live_translate_voice.js" label="JavaScript" %} ```javascript import { GoogleGenAI, Modality } from '@google/genai'; const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } }); const model = 'gemini-4-live-translate'; const config = { responseModalities: [Modality.AUDIO], inputAudioTranscription: {}, outputAudioTranscription: {}, translationConfig: { targetLanguageCode: 'es', echoTargetLanguage: false, }, speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: 'Kore' }, }, }, }; const session = await ai.live.connect({ model, config, callbacks: { onmessage: (message) => { const parts = message.serverContent?.modelTurn?.parts ?? []; for (const part of parts) { if (part.inlineData) { // 24 kHz PCM translated audio in the selected voice } } }, }, }); ``` {% /tab %} {% tab filename="live_translate_voice.json" label="WebSockets" %} ```json { "setup": { "model": "models/gemini-4-live-translate", "inputAudioTranscription": {}, "outputAudioTranscription": {}, "generationConfig": { "responseModalities": ["AUDIO"], "speechConfig": { "voiceConfig": { "prebuiltVoiceConfig": { "voiceName": "Kore" } } }, "translationConfig": { "targetLanguageCode": "es", "echoTargetLanguage": false } } } } ``` {% /tab %} {% /tabs %} ### System instructions {% id="system-instructions" %} You can pass `system_instruction` (`systemInstruction` in WebSockets) during session setup to guide how the model translates speech. Use system instructions to specify: * **Custom terminology and glossaries**: Define how specific industry terms, brand names, or technical jargon should be translated (for example, translating `"deployment pipeline"` as `"canalización de despliegue"` or keeping product names like `"Cloud Run"` untranslated). * **Formality and register**: Specify the target tone, pronoun form, or audience setting (for example, using formal singular or plural address in a presentation). * **Speaker and addressee context**: Provide context about the setting and participants so the model preserves direct address accurately. {% callout type="note" %} System instructions can only be set in the initial `setup` message. Updating system instructions mid-session (including via `clientContent` or `realtimeInput` text messages) is not supported; to change system instructions, start a new session. Additionally, only instructions that guide translation behavior and match `target_language_code` are supported—instructions that conflict with `target_language_code`, alter output formatting, or ask the model to perform non-translation tasks are unsupported and may be ignored or degrade translation output. {% /callout %} {% tabs %} {% tab filename="live_translate_si.py" label="Python" %} ```python config = types.LiveConnectConfig( response_modalities=["AUDIO"], system_instruction=( "You are translating a live conference presentation into Spanish. " "Use formal address (usted/ustedes), always translate " "'deployment pipeline' as 'canalización de despliegue', and keep " "product names like 'Cloud Run' untranslated." ), input_audio_transcription=types.AudioTranscriptionConfig(), output_audio_transcription=types.AudioTranscriptionConfig(), translation_config=types.TranslationConfig( target_language_code="es", echo_target_language=False, ), ) ``` {% /tab %} {% tab filename="live_translate_si.js" label="JavaScript" %} ```javascript const config = { responseModalities: [Modality.AUDIO], systemInstruction: "You are translating a live conference presentation into Spanish. " + "Use formal address (usted/ustedes), always translate " + "'deployment pipeline' as 'canalización de despliegue', and keep " + "product names like 'Cloud Run' untranslated.", inputAudioTranscription: {}, outputAudioTranscription: {}, translationConfig: { targetLanguageCode: 'es', echoTargetLanguage: false, }, }; ``` {% /tab %} {% tab filename="live_translate_si_ws.js" label="WebSockets" %} ```javascript const setupMessage = { setup: { model: `models/${MODEL_NAME}`, systemInstruction: { parts: [ { text: "You are translating a live conference presentation into Spanish. " + "Use formal address (usted/ustedes), always translate " + "'deployment pipeline' as 'canalización de despliegue', and keep " + "product names like 'Cloud Run' untranslated.", }, ], }, inputAudioTranscription: {}, outputAudioTranscription: {}, generationConfig: { responseModalities: ['AUDIO'], translationConfig: { targetLanguageCode: 'es', echoTargetLanguage: false, }, }, }, }; websocket.send(JSON.stringify(setupMessage)); ``` {% /tab %} {% /tabs %} ## Use ephemeral tokens in client-side applications {% id="ephemeral-tokens-for-client-side-applications" %} For client-to-server applications, you can use [ephemeral tokens](/docs/live-api/ephemeral-tokens) (currently in `v1beta`) to avoid exposing your API key. When using ephemeral tokens with Live Translation: 1. You must use the `v1beta` endpoint. 2. **Locking configuration:** By default, you should specify the `translationConfig` (and optional `systemInstruction`) in the token creation constraints on your server. When `live_connect_constraints` is set without `lock_additional_fields`, the server locks the entire `setup` configuration and ignores any `system_instruction` or `translationConfig` fields passed by the client at connection time. 3. **Unlocking configuration:** If you want to set `translationConfig` or `system_instruction` on the client-side (for example, to let a user choose their own target language or custom terminology), omit those fields from the token creation request and set `"lock_additional_fields": []` instead. This locks only the fields specified on the server and unlocks the remaining fields to be set on the client-side. ### Create a constrained ephemeral token {% id="creating-a-constrained-ephemeral-token" %} The following examples demonstrate how to create an ephemeral token with translation constraints. {% tabs %} {% tab filename="live_translate.py" label="Python" %} ```python import datetime from google import genai now = datetime.datetime.now(tz=datetime.timezone.utc) client = genai.Client(http_options={"api_version": "v1beta"}) token = client.auth_tokens.create( config = { 'uses': 1, 'expire_time': now + datetime.timedelta(minutes=30), 'live_connect_constraints': { 'model': 'gemini-4-live-translate', 'config': { 'translation_config': { 'target_language_code': 'pl', 'echo_target_language': True } } }, } ) ``` {% /tab %} {% tab filename="live_translate.js" label="JavaScript" %} ```javascript import { GoogleGenAI } from "@google/genai"; const client = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } }); const expireTime = new Date(Date.now() + 30 * 60 * 1000).toISOString(); const token = await client.authTokens.create({ config: { uses: 1, expireTime: expireTime, liveConnectConstraints: { model: 'gemini-4-live-translate', config: { responseModalities: ['AUDIO'], inputAudioTranscription: {}, outputAudioTranscription: {}, translationConfig: { targetLanguageCode: 'pl', echoTargetLanguage: true } } }, }, }); ``` {% /tab %} {% tab filename="live_translate.sh" label="REST" %} ```bash curl -X POST "https://generativelanguage.googleapis.com/v1beta/auth_tokens" \ -H "x-goog-api-key: ${GEMINI_API_KEY}" \ -H "Content-Type: application/json" \ -d '{ "uses": 1, "expireTime": "YYYY-MM-DDTHH:MM:SSZ", "bidiGenerateContentSetup": { "model": "models/gemini-4-live-translate", "inputAudioTranscription": {}, "outputAudioTranscription": {}, "generationConfig": { "responseModalities": ["AUDIO"], "translationConfig": { "targetLanguageCode": "pl", "echoTargetLanguage": true } } } }' ``` {% /tab %} {% /tabs %} ## Limitations {% id="limitations" %} * **Input Modalities**: Only audio input is supported for translation. Text input is not supported. * **System Instructions**: System instructions can only be set in the initial `setup` message. Updating system instructions mid-session (including via `clientContent` or `realtimeInput` text messages) is not supported; start a new session to change instructions. Only instructions that guide translation behavior and match `target_language_code` are supported—instructions that conflict with `target_language_code`, alter output formatting, or request non-translation tasks are unsupported and may be ignored or degrade translation output. * **Instant voice replication**: On-the-fly speaker voice matching can vary after long pauses or during rapid multi-speaker turns. Set a preset voice from the extended voice library in [`speechConfig`](/docs/live-api/live-translate#choosing-a-voice) if you need a consistent voice across a session. {% callout type="note" %} As a reminder, developers are responsible for obtaining consent from all parties, where required. Developers cannot use the API in a manner that violates applicable law, regulation, or third party rights. {% /callout %} * **Language Detection**: Language detection struggles with heavy accents, similar languages (e.g., Spanish vs. Portuguese), or rapid language switches. **Note:** This should only impact the input transcript. Language codes and the final translation should still be accurate. * **Background Audio**: The model is designed to filter out noise and music to produce clean speech, but not all background audio may be ignored. * **Echo Target Language**: When `echoTargetLanguage: true`, background noise or music may introduce artifacts in the translated audio when input audio is already in the target language. ## Supported languages {% id="supported-languages" %} The following languages are supported for Live Translation. | Language | BCP-47 Code | Language | BCP-47 Code | | :--- | :--- | :--- | :--- | | Afrikaans | af | Kazakh | kk | | Akan | ak | Khmer | km | | Albanian | sq | Kinyarwanda | rw | | Amharic | am | Korean | ko | | Arabic | ar | Lao | lo | | Armenian | hy | Latvian | lv | | Azerbaijani | az | Lithuanian | lt | | Basque | eu | Macedonian | mk | | Belarusian | be | Malay | ms | | Bengali | bn | Malayalam | ml | | Bulgarian | bg | Marathi | mr | | Burmese (Myanmar) | my | Mongolian | mn | | Catalan | ca | Nepali | ne | | Chinese (Simplified) | zh-Hans | Norwegian | no, nb | | Chinese (Traditional) | zh-Hant | Persian | fa | | Croatian | hr | Polish | pl | | Czech | cs | Portuguese (Brazil) | pt-BR | | Danish | da | Portuguese (Portugal) | pt-PT | | Dutch | nl | Punjabi | pa | | English | en | Romanian | ro | | Estonian | et | Russian | ru | | Filipino | fil | Serbian | sr | | Finnish | fi | Sindhi | sd | | French | fr | Sinhala | si | | Galician | gl | Slovak | sk | | Georgian | ka | Slovenian | sl | | German | de | Spanish | es | | Greek | el | Sundanese | su | | Gujarati | gu | Swahili | sw | | Hausa | ha | Swedish | sv | | Hebrew | he | Tamil | ta | | Hindi | hi | Telugu | te | | Hungarian | hu | Thai | th | | Icelandic | is | Turkish | tr | | Indonesian | id | Ukrainian | uk | | Italian | it | Urdu | ur | | Japanese | ja | Uzbek | uz | | Javanese | jv | Vietnamese | vi | | Kannada | kn | Zulu | zu | ## What's next {% id="whats-next" %} * Read the full Live API [Capabilities](/docs/live-api/capabilities) guide. * Read the [Get started with the SDK](/docs/live-api/get-started-sdk) guide. * Read the [Get started with WebSockets](/docs/live-api/get-started-websocket) guide. * Read the [Ephemeral tokens](/docs/live-api/ephemeral-tokens) guide for secure authentication in client-to-server applications. * Clone the [Live API examples](https://github.com/google-gemini/gemini-live-api-examples) from GitHub.