Live API capabilities guide

यह एक पूरी गाइड है. इसमें Live API के साथ उपलब्ध सुविधाओं और कॉन्फ़िगरेशन के बारे में बताया गया है. लाइव एपीआई के बारे में खास जानकारी और इस्तेमाल के सामान्य उदाहरणों के लिए सैंपल कोड देखने के लिए, लाइव एपीआई का इस्तेमाल शुरू करें पेज पर जाएं.

शुरू करने से पहले

  • बुनियादी कॉन्सेप्ट के बारे में जानें: अगर आपने अब तक ऐसा नहीं किया है, तो सबसे पहले Live API का इस्तेमाल शुरू करना पेज पढ़ें. इससे आपको Live API के बुनियादी सिद्धांतों के बारे में पता चलेगा. साथ ही, यह भी पता चलेगा कि यह कैसे काम करता है और इसे लागू करने के अलग-अलग तरीके क्या हैं.
  • AI Studio में Live API आज़माएं: ऐप्लिकेशन बनाने से पहले, Google AI Studio में Live API आज़माना आपके लिए फ़ायदेमंद हो सकता है. Google AI Studio में Live API का इस्तेमाल करने के लिए, स्ट्रीम करें को चुनें.

कनेक्शन सेट अप करना

यहां दिए गए उदाहरण में, एपीआई पासकोड की मदद से कनेक्शन बनाने का तरीका बताया गया है:

Python

import asyncio
from google import genai

client = genai.Client()

model = "gemini-2.5-flash-native-audio-preview-09-2025"
config = {"response_modalities": ["AUDIO"]}

async def main():
    async with client.aio.live.connect(model=model, config=config) as session:
        print("Session started")
        # Send content...

if __name__ == "__main__":
    asyncio.run(main())

JavaScript

import { GoogleGenAI, Modality } from '@google/genai';

const ai = new GoogleGenAI({});
const model = 'gemini-2.5-flash-native-audio-preview-09-2025';
const config = { responseModalities: [Modality.AUDIO] };

async function main() {

  const session = await ai.live.connect({
    model: model,
    callbacks: {
      onopen: function () {
        console.debug('Opened');
      },
      onmessage: function (message) {
        console.debug(message);
      },
      onerror: function (e) {
        console.debug('Error:', e.message);
      },
      onclose: function (e) {
        console.debug('Close:', e.reason);
      },
    },
    config: config,
  });

  console.debug("Session started");
  // Send content...

  session.close();
}

main();

इंटरैक्शन के तरीके

यहां दिए गए सेक्शन में, Live API में उपलब्ध अलग-अलग इनपुट और आउटपुट मोड के उदाहरण दिए गए हैं. साथ ही, इनके बारे में ज़रूरी जानकारी दी गई है.

ऑडियो भेजना और पाना

सबसे आम ऑडियो उदाहरण, ऑडियो-टू-ऑडियो, के बारे में शुरुआत करना गाइड में बताया गया है.

ऑडियो फ़ॉर्मैट

लाइव एपीआई में ऑडियो डेटा हमेशा रॉ, लिटिल-एंडियन, 16-बिट पीसीएम होता है. ऑडियो आउटपुट हमेशा 24 किलोहर्ट्ज़ के सैंपल रेट का इस्तेमाल करता है. इनपुट ऑडियो मूल रूप से 16 किलोहर्ट्ज़ (kHz) का होता है. हालांकि, अगर ज़रूरत होती है, तो Live API इसे फिर से सैंपल करता है. इसलिए, कोई भी सैंपल रेट भेजा जा सकता है. इनपुट ऑडियो की सैंपल दर बताने के लिए, ऑडियो वाले हर Blob के MIME टाइप को audio/pcm;rate=16000 जैसे किसी वैल्यू पर सेट करें.

टेक्स्ट भेजा जा रहा है

टेक्स्ट भेजने का तरीका यहां बताया गया है:

Python

message = "Hello, how are you?"
await session.send_client_content(turns=message, turn_complete=True)

JavaScript

const message = 'Hello, how are you?';
session.sendClientContent({ turns: message, turnComplete: true });

कॉन्टेंट में धीरे-धीरे किए जाने वाले अपडेट

टेक्स्ट इनपुट भेजने, सेशन का कॉन्टेक्स्ट सेट अप करने या सेशन का कॉन्टेक्स्ट वापस लाने के लिए, इंक्रीमेंटल अपडेट का इस्तेमाल करें. छोटे कॉन्टेक्स्ट के लिए, इवेंट के सटीक क्रम को दिखाने के लिए, बारी-बारी से इंटरैक्शन भेजे जा सकते हैं:

Python

turns = [
    {"role": "user", "parts": [{"text": "What is the capital of France?"}]},
    {"role": "model", "parts": [{"text": "Paris"}]},
]

await session.send_client_content(turns=turns, turn_complete=False)

turns = [{"role": "user", "parts": [{"text": "What is the capital of Germany?"}]}]

await session.send_client_content(turns=turns, turn_complete=True)

JavaScript

let inputTurns = [
  { "role": "user", "parts": [{ "text": "What is the capital of France?" }] },
  { "role": "model", "parts": [{ "text": "Paris" }] },
]

session.sendClientContent({ turns: inputTurns, turnComplete: false })

inputTurns = [{ "role": "user", "parts": [{ "text": "What is the capital of Germany?" }] }]

session.sendClientContent({ turns: inputTurns, turnComplete: true })

ज़्यादा बड़े कॉन्टेक्स्ट के लिए, यह सुझाव दिया जाता है कि एक मैसेज की खास जानकारी दी जाए, ताकि बाद की बातचीत के लिए कॉन्टेक्स्ट विंडो खाली हो जाए. सेशन के कॉन्टेक्स्ट को लोड करने के किसी दूसरे तरीके के लिए, सेशन फिर से शुरू करना देखें.

ऑडियो ट्रांसक्रिप्शन

मॉडल के जवाब के अलावा, आपको ऑडियो आउटपुट और ऑडियो इनपुट, दोनों की ट्रांसक्रिप्ट भी मिल सकती हैं.

मॉडल के ऑडियो आउटपुट को टेक्स्ट में बदलने की सुविधा चालू करने के लिए, सेटअप कॉन्फ़िगरेशन में output_audio_transcription भेजें. बोले जा रहे शब्दों को टेक्स्ट में बदलने के लिए, भाषा का अनुमान मॉडल के जवाब से लगाया जाता है.

Python

import asyncio
from google import genai
from google.genai import types

client = genai.Client()
model = "gemini-2.5-flash-native-audio-preview-09-2025"

config = {
    "response_modalities": ["AUDIO"],
    "output_audio_transcription": {}
}

async def main():
    async with client.aio.live.connect(model=model, config=config) as session:
        message = "Hello? Gemini are you there?"

        await session.send_client_content(
            turns={"role": "user", "parts": [{"text": message}]}, turn_complete=True
        )

        async for response in session.receive():
            if response.server_content.model_turn:
                print("Model turn:", response.server_content.model_turn)
            if response.server_content.output_transcription:
                print("Transcript:", response.server_content.output_transcription.text)

if __name__ == "__main__":
    asyncio.run(main())

JavaScript

import { GoogleGenAI, Modality } from '@google/genai';

const ai = new GoogleGenAI({});
const model = 'gemini-2.5-flash-native-audio-preview-09-2025';

const config = {
  responseModalities: [Modality.AUDIO],
  outputAudioTranscription: {}
};

async function live() {
  const responseQueue = [];

  async function waitMessage() {
    let done = false;
    let message = undefined;
    while (!done) {
      message = responseQueue.shift();
      if (message) {
        done = true;
      } else {
        await new Promise((resolve) => setTimeout(resolve, 100));
      }
    }
    return message;
  }

  async function handleTurn() {
    const turns = [];
    let done = false;
    while (!done) {
      const message = await waitMessage();
      turns.push(message);
      if (message.serverContent && message.serverContent.turnComplete) {
        done = true;
      }
    }
    return turns;
  }

  const session = await ai.live.connect({
    model: model,
    callbacks: {
      onopen: function () {
        console.debug('Opened');
      },
      onmessage: function (message) {
        responseQueue.push(message);
      },
      onerror: function (e) {
        console.debug('Error:', e.message);
      },
      onclose: function (e) {
        console.debug('Close:', e.reason);
      },
    },
    config: config,
  });

  const inputTurns = 'Hello how are you?';
  session.sendClientContent({ turns: inputTurns });

  const turns = await handleTurn();

  for (const turn of turns) {
    if (turn.serverContent && turn.serverContent.outputTranscription) {
      console.debug('Received output transcription: %s\n', turn.serverContent.outputTranscription.text);
    }
  }

  session.close();
}

async function main() {
  await live().catch((e) => console.error('got error', e));
}

main();

मॉडल के ऑडियो इनपुट को टेक्स्ट में बदलने की सुविधा चालू करने के लिए, सेटअप कॉन्फ़िगरेशन में input_audio_transcription भेजें.

Python

import asyncio
from pathlib import Path
from google import genai
from google.genai import types

client = genai.Client()
model = "gemini-2.5-flash-native-audio-preview-09-2025"

config = {
    "response_modalities": ["AUDIO"],
    "input_audio_transcription": {},
}

async def main():
    async with client.aio.live.connect(model=model, config=config) as session:
        audio_data = Path("16000.pcm").read_bytes()

        await session.send_realtime_input(
            audio=types.Blob(data=audio_data, mime_type='audio/pcm;rate=16000')
        )

        async for msg in session.receive():
            if msg.server_content.input_transcription:
                print('Transcript:', msg.server_content.input_transcription.text)

if __name__ == "__main__":
    asyncio.run(main())

JavaScript

import { GoogleGenAI, Modality } from '@google/genai';
import * as fs from "node:fs";
import pkg from 'wavefile';
const { WaveFile } = pkg;

const ai = new GoogleGenAI({});
const model = 'gemini-2.5-flash-native-audio-preview-09-2025';

const config = {
  responseModalities: [Modality.AUDIO],
  inputAudioTranscription: {}
};

async function live() {
  const responseQueue = [];

  async function waitMessage() {
    let done = false;
    let message = undefined;
    while (!done) {
      message = responseQueue.shift();
      if (message) {
        done = true;
      } else {
        await new Promise((resolve) => setTimeout(resolve, 100));
      }
    }
    return message;
  }

  async function handleTurn() {
    const turns = [];
    let done = false;
    while (!done) {
      const message = await waitMessage();
      turns.push(message);
      if (message.serverContent && message.serverContent.turnComplete) {
        done = true;
      }
    }
    return turns;
  }

  const session = await ai.live.connect({
    model: model,
    callbacks: {
      onopen: function () {
        console.debug('Opened');
      },
      onmessage: function (message) {
        responseQueue.push(message);
      },
      onerror: function (e) {
        console.debug('Error:', e.message);
      },
      onclose: function (e) {
        console.debug('Close:', e.reason);
      },
    },
    config: config,
  });

  // Send Audio Chunk
  const fileBuffer = fs.readFileSync("16000.wav");

  // Ensure audio conforms to API requirements (16-bit PCM, 16kHz, mono)
  const wav = new WaveFile();
  wav.fromBuffer(fileBuffer);
  wav.toSampleRate(16000);
  wav.toBitDepth("16");
  const base64Audio = wav.toBase64();

  // If already in correct format, you can use this:
  // const fileBuffer = fs.readFileSync("sample.pcm");
  // const base64Audio = Buffer.from(fileBuffer).toString('base64');

  session.sendRealtimeInput(
    {
      audio: {
        data: base64Audio,
        mimeType: "audio/pcm;rate=16000"
      }
    }
  );

  const turns = await handleTurn();
  for (const turn of turns) {
    if (turn.text) {
      console.debug('Received text: %s\n', turn.text);
    }
    else if (turn.data) {
      console.debug('Received inline data: %s\n', turn.data);
    }
    else if (turn.serverContent && turn.serverContent.inputTranscription) {
      console.debug('Received input transcription: %s\n', turn.serverContent.inputTranscription.text);
    }
  }

  session.close();
}

async function main() {
  await live().catch((e) => console.error('got error', e));
}

main();

ऑडियो और वीडियो स्ट्रीम करना

आवाज़ और भाषा बदलना

नेटिव ऑडियो आउटपुट मॉडल, लिखाई को बोली में बदलने (टीटीएस) वाले हमारे मॉडल के लिए उपलब्ध किसी भी आवाज़ के साथ काम करते हैं. AI Studio में जाकर, सभी आवाज़ें सुनी जा सकती हैं.

आवाज़ तय करने के लिए, सेशन कॉन्फ़िगरेशन के हिस्से के तौर पर, speechConfig ऑब्जेक्ट में आवाज़ का नाम सेट करें:

Python

config = {
    "response_modalities": ["AUDIO"],
    "speech_config": {
        "voice_config": {"prebuilt_voice_config": {"voice_name": "Kore"}}
    },
}

JavaScript

const config = {
  responseModalities: [Modality.AUDIO],
  speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: "Kore" } } }
};

Live API, कई भाषाओं में काम करता है. नेटिव ऑडियो आउटपुट वाले मॉडल, सही भाषा को अपने-आप चुनते हैं. साथ ही, ये भाषा कोड को साफ़ तौर पर सेट करने की सुविधा के साथ काम नहीं करते.

नेटिव ऑडियो की सुविधाएं

हमारे नए मॉडल में नेटिव ऑडियो आउटपुट की सुविधा है. इससे आपको स्वाभाविक और असली आवाज़ में ऑडियो मिलता है. साथ ही, यह कई भाषाओं में बेहतर परफ़ॉर्म करता है. नेटिव ऑडियो की मदद से, भावनाओं को समझने वाले (इमोशन-अवेयर) डायलॉग, प्रोऐक्टिव ऑडियो (इसमें मॉडल यह तय करता है कि इनपुट का जवाब कब देना है), और "सोचने"; जैसी ऐडवांस सुविधाएँ भी मिलती हैं.

अफ़ेक्टिव डायलॉग

इस सुविधा की मदद से, Gemini अपने जवाब देने के तरीके को इनपुट एक्सप्रेशन और टोन के हिसाब से बदल सकता है.

भावनाओं से जुड़े डायलॉग का इस्तेमाल करने के लिए, एपीआई वर्शन को v1alpha पर सेट करें. साथ ही, सेटअप मैसेज में enable_affective_dialog को true पर सेट करें:

Python

client = genai.Client(http_options={"api_version": "v1alpha"})

config = types.LiveConnectConfig(
    response_modalities=["AUDIO"],
    enable_affective_dialog=True
)

JavaScript

const ai = new GoogleGenAI({ httpOptions: {"apiVersion": "v1alpha"} });

const config = {
  responseModalities: [Modality.AUDIO],
  enableAffectiveDialog: true
};

प्रोऐक्टिव ऑडियो

इस सुविधा के चालू होने पर, Gemini यह तय कर सकता है कि अगर कॉन्टेंट काम का नहीं है, तो जवाब न दिया जाए.

इसका इस्तेमाल करने के लिए, एपीआई वर्शन को v1alpha पर सेट करें. इसके बाद, सेटअप मैसेज में proactivity फ़ील्ड को कॉन्फ़िगर करें और proactive_audio को true पर सेट करें:

Python

client = genai.Client(http_options={"api_version": "v1alpha"})

config = types.LiveConnectConfig(
    response_modalities=["AUDIO"],
    proactivity={'proactive_audio': True}
)

JavaScript

const ai = new GoogleGenAI({ httpOptions: {"apiVersion": "v1alpha"} });

const config = {
  responseModalities: [Modality.AUDIO],
  proactivity: { proactiveAudio: true }
}

खोजा जा रहा है

नेटिव ऑडियो आउटपुट का नया मॉडल gemini-2.5-flash-native-audio-preview-09-2025 सोचने की क्षमताओं के साथ काम करता है. इसमें डाइनैमिक थिंकिंग की सुविधा डिफ़ॉल्ट रूप से चालू होती है.

thinkingBudget पैरामीटर, मॉडल को यह जानकारी देता है कि जवाब जनरेट करते समय कितने थिंकिंग टोकन का इस्तेमाल करना है. thinkingBudget को 0 पर सेट करके, सोचने की सुविधा को बंद किया जा सकता है. मॉडल के thinkingBudget कॉन्फ़िगरेशन के बारे में ज़्यादा जानने के लिए, थिंकिंग बजट का दस्तावेज़ देखें.

Python

model = "gemini-2.5-flash-native-audio-preview-09-2025"

config = types.LiveConnectConfig(
    response_modalities=["AUDIO"]
    thinking_config=types.ThinkingConfig(
        thinking_budget=1024,
    )
)

async with client.aio.live.connect(model=model, config=config) as session:
    # Send audio input and receive audio

JavaScript

const model = 'gemini-2.5-flash-native-audio-preview-09-2025';
const config = {
  responseModalities: [Modality.AUDIO],
  thinkingConfig: {
    thinkingBudget: 1024,
  },
};

async function main() {

  const session = await ai.live.connect({
    model: model,
    config: config,
    callbacks: ...,
  });

  // Send audio input and receive audio

  session.close();
}

main();

इसके अलावा, अपने कॉन्फ़िगरेशन में includeThoughts को true पर सेट करके, सोच के बारे में खास जानकारी देने वाली सुविधा चालू की जा सकती है. ज़्यादा जानकारी के लिए, सोच के बारे में खास जानकारी देखें:

Python

model = "gemini-2.5-flash-native-audio-preview-09-2025"

config = types.LiveConnectConfig(
    response_modalities=["AUDIO"]
    thinking_config=types.ThinkingConfig(
        thinking_budget=1024,
        include_thoughts=True
    )
)

JavaScript

const model = 'gemini-2.5-flash-native-audio-preview-09-2025';
const config = {
  responseModalities: [Modality.AUDIO],
  thinkingConfig: {
    thinkingBudget: 1024,
    includeThoughts: true,
  },
};

आवाज़ का पता लगाने की सुविधा (वीएडी)

आवाज़ की पहचान करने वाली सुविधा (वीएडी) की मदद से, मॉडल यह पहचान पाता है कि कोई व्यक्ति कब बोल रहा है. यह सुविधा, बातचीत को स्वाभाविक बनाने के लिए ज़रूरी है. इससे उपयोगकर्ता को मॉडल को किसी भी समय रोकने की अनुमति मिलती है.

जब VAD को किसी रुकावट का पता चलता है, तो जनरेट हो रहे कॉन्टेंट को रद्द कर दिया जाता है और उसे खारिज कर दिया जाता है. सिर्फ़ वह जानकारी सेशन के इतिहास में सेव की जाती है जो क्लाइंट को पहले ही भेजी जा चुकी है. इसके बाद, सर्वर BidiGenerateContentServerContent मैसेज भेजकर, रुकावट की सूचना देता है.

इसके बाद, Gemini सर्वर फ़ंक्शन कॉल के सभी अनुरोधों को खारिज कर देता है. साथ ही, रद्द किए गए कॉल के आईडी के साथ BidiGenerateContentServerContent मैसेज भेजता है.

Python

async for response in session.receive():
    if response.server_content.interrupted is True:
        # The generation was interrupted

        # If realtime playback is implemented in your application,
        # you should stop playing audio and clear queued playback here.

JavaScript

const turns = await handleTurn();

for (const turn of turns) {
  if (turn.serverContent && turn.serverContent.interrupted) {
    // The generation was interrupted

    // If realtime playback is implemented in your application,
    // you should stop playing audio and clear queued playback here.
  }
}

ऑटोमैटिक वीएडी

डिफ़ॉल्ट रूप से, मॉडल लगातार ऑडियो इनपुट स्ट्रीम पर वीएडी की प्रोसेस अपने-आप करता है. VAD को सेटअप कॉन्फ़िगरेशन के realtimeInputConfig.automaticActivityDetection फ़ील्ड की मदद से कॉन्फ़िगर किया जा सकता है.

अगर ऑडियो स्ट्रीम को एक सेकंड से ज़्यादा समय के लिए रोका जाता है (उदाहरण के लिए, क्योंकि उपयोगकर्ता ने माइक्रोफ़ोन बंद कर दिया है), तो audioStreamEnd इवेंट भेजा जाना चाहिए, ताकि कैश मेमोरी में सेव किए गए ऑडियो को हटाया जा सके. क्लाइंट, ऑडियो डेटा भेजना किसी भी समय फिर से शुरू कर सकता है.

Python

# example audio file to try:
# URL = "https://storage.googleapis.com/generativeai-downloads/data/hello_are_you_there.pcm"
# !wget -q $URL -O sample.pcm
import asyncio
from pathlib import Path
from google import genai
from google.genai import types

client = genai.Client()
model = "gemini-live-2.5-flash-preview"

config = {"response_modalities": ["TEXT"]}

async def main():
    async with client.aio.live.connect(model=model, config=config) as session:
        audio_bytes = Path("sample.pcm").read_bytes()

        await session.send_realtime_input(
            audio=types.Blob(data=audio_bytes, mime_type="audio/pcm;rate=16000")
        )

        # if stream gets paused, send:
        # await session.send_realtime_input(audio_stream_end=True)

        async for response in session.receive():
            if response.text is not None:
                print(response.text)

if __name__ == "__main__":
    asyncio.run(main())

JavaScript

// example audio file to try:
// URL = "https://storage.googleapis.com/generativeai-downloads/data/hello_are_you_there.pcm"
// !wget -q $URL -O sample.pcm
import { GoogleGenAI, Modality } from '@google/genai';
import * as fs from "node:fs";

const ai = new GoogleGenAI({});
const model = 'gemini-live-2.5-flash-preview';
const config = { responseModalities: [Modality.TEXT] };

async function live() {
  const responseQueue = [];

  async function waitMessage() {
    let done = false;
    let message = undefined;
    while (!done) {
      message = responseQueue.shift();
      if (message) {
        done = true;
      } else {
        await new Promise((resolve) => setTimeout(resolve, 100));
      }
    }
    return message;
  }

  async function handleTurn() {
    const turns = [];
    let done = false;
    while (!done) {
      const message = await waitMessage();
      turns.push(message);
      if (message.serverContent && message.serverContent.turnComplete) {
        done = true;
      }
    }
    return turns;
  }

  const session = await ai.live.connect({
    model: model,
    callbacks: {
      onopen: function () {
        console.debug('Opened');
      },
      onmessage: function (message) {
        responseQueue.push(message);
      },
      onerror: function (e) {
        console.debug('Error:', e.message);
      },
      onclose: function (e) {
        console.debug('Close:', e.reason);
      },
    },
    config: config,
  });

  // Send Audio Chunk
  const fileBuffer = fs.readFileSync("sample.pcm");
  const base64Audio = Buffer.from(fileBuffer).toString('base64');

  session.sendRealtimeInput(
    {
      audio: {
        data: base64Audio,
        mimeType: "audio/pcm;rate=16000"
      }
    }

  );

  // if stream gets paused, send:
  // session.sendRealtimeInput({ audioStreamEnd: true })

  const turns = await handleTurn();
  for (const turn of turns) {
    if (turn.text) {
      console.debug('Received text: %s\n', turn.text);
    }
    else if (turn.data) {
      console.debug('Received inline data: %s\n', turn.data);
    }
  }

  session.close();
}

async function main() {
  await live().catch((e) => console.error('got error', e));
}

main();

send_realtime_input की मदद से, एपीआई वीएडी के आधार पर ऑडियो का जवाब अपने-आप देगा. send_client_content, मॉडल के कॉन्टेक्स्ट में मैसेज जोड़ता है. वहीं, send_realtime_input को जवाब देने के लिए ऑप्टिमाइज़ किया गया है. हालांकि, इससे जवाबों के क्रम पर असर पड़ता है.

वीएडी को अपने-आप कॉन्फ़िगर होने की सुविधा

वीएडी की गतिविधि को बेहतर तरीके से कंट्रोल करने के लिए, यहां दिए गए पैरामीटर कॉन्फ़िगर किए जा सकते हैं. ज़्यादा जानकारी के लिए, एपीआई के बारे में जानकारी देखें.

Python

from google.genai import types

config = {
    "response_modalities": ["TEXT"],
    "realtime_input_config": {
        "automatic_activity_detection": {
            "disabled": False, # default
            "start_of_speech_sensitivity": types.StartSensitivity.START_SENSITIVITY_LOW,
            "end_of_speech_sensitivity": types.EndSensitivity.END_SENSITIVITY_LOW,
            "prefix_padding_ms": 20,
            "silence_duration_ms": 100,
        }
    }
}

JavaScript

import { GoogleGenAI, Modality, StartSensitivity, EndSensitivity } from '@google/genai';

const config = {
  responseModalities: [Modality.TEXT],
  realtimeInputConfig: {
    automaticActivityDetection: {
      disabled: false, // default
      startOfSpeechSensitivity: StartSensitivity.START_SENSITIVITY_LOW,
      endOfSpeechSensitivity: EndSensitivity.END_SENSITIVITY_LOW,
      prefixPaddingMs: 20,
      silenceDurationMs: 100,
    }
  }
};

अपने-आप वीएडी की सुविधा बंद करना

इसके अलावा, सेटअप मैसेज में realtimeInputConfig.automaticActivityDetection.disabled को true पर सेट करके, अपने-आप वीएडी होने की सुविधा बंद की जा सकती है. इस कॉन्फ़िगरेशन में, क्लाइंट की यह ज़िम्मेदारी होती है कि वह उपयोगकर्ता की आवाज़ का पता लगाए और सही समय पर activityStart और activityEnd मैसेज भेजे. इस कॉन्फ़िगरेशन में audioStreamEnd नहीं भेजा जाता है. इसके बजाय, स्ट्रीम में किसी भी तरह की रुकावट को activityEnd मैसेज से मार्क किया जाता है.

Python

config = {
    "response_modalities": ["TEXT"],
    "realtime_input_config": {"automatic_activity_detection": {"disabled": True}},
}

async with client.aio.live.connect(model=model, config=config) as session:
    # ...
    await session.send_realtime_input(activity_start=types.ActivityStart())
    await session.send_realtime_input(
        audio=types.Blob(data=audio_bytes, mime_type="audio/pcm;rate=16000")
    )
    await session.send_realtime_input(activity_end=types.ActivityEnd())
    # ...

JavaScript

const config = {
  responseModalities: [Modality.TEXT],
  realtimeInputConfig: {
    automaticActivityDetection: {
      disabled: true,
    }
  }
};

session.sendRealtimeInput({ activityStart: {} })

session.sendRealtimeInput(
  {
    audio: {
      data: base64Audio,
      mimeType: "audio/pcm;rate=16000"
    }
  }

);

session.sendRealtimeInput({ activityEnd: {} })

टोकन की संख्या

इस्तेमाल किए गए टोकन की कुल संख्या, सर्वर से मिले मैसेज के usageMetadata फ़ील्ड में देखी जा सकती है.

Python

async for message in session.receive():
    # The server will periodically send messages that include UsageMetadata.
    if message.usage_metadata:
        usage = message.usage_metadata
        print(
            f"Used {usage.total_token_count} tokens in total. Response token breakdown:"
        )
        for detail in usage.response_tokens_details:
            match detail:
                case types.ModalityTokenCount(modality=modality, token_count=count):
                    print(f"{modality}: {count}")

JavaScript

const turns = await handleTurn();

for (const turn of turns) {
  if (turn.usageMetadata) {
    console.debug('Used %s tokens in total. Response token breakdown:\n', turn.usageMetadata.totalTokenCount);

    for (const detail of turn.usageMetadata.responseTokensDetails) {
      console.debug('%s\n', detail);
    }
  }
}

मीडिया रिज़ॉल्यूशन

सेशन कॉन्फ़िगरेशन के हिस्से के तौर पर mediaResolution फ़ील्ड सेट करके, इनपुट मीडिया के लिए मीडिया रिज़ॉल्यूशन तय किया जा सकता है:

Python

from google.genai import types

config = {
    "response_modalities": ["AUDIO"],
    "media_resolution": types.MediaResolution.MEDIA_RESOLUTION_LOW,
}

JavaScript

import { GoogleGenAI, Modality, MediaResolution } from '@google/genai';

const config = {
    responseModalities: [Modality.TEXT],
    mediaResolution: MediaResolution.MEDIA_RESOLUTION_LOW,
};

सीमाएं

अपना प्रोजेक्ट प्लान करते समय, Live API की इन सीमाओं को ध्यान में रखें.

जवाब देने के तरीके

सेशन कॉन्फ़िगरेशन में, हर सेशन के लिए सिर्फ़ एक जवाब मोड (TEXT या AUDIO) सेट किया जा सकता है. दोनों को सेट करने पर, कॉन्फ़िगरेशन से जुड़ी गड़बड़ी का मैसेज दिखता है. इसका मतलब है कि मॉडल को टेक्स्ट या ऑडियो, दोनों में से किसी एक के ज़रिए जवाब देने के लिए कॉन्फ़िगर किया जा सकता है. हालाँकि, एक ही सेशन में दोनों के ज़रिए जवाब देने के लिए कॉन्फ़िगर नहीं किया जा सकता.

क्लाइंट प्रमाणीकरण

Live API, डिफ़ॉल्ट रूप से सिर्फ़ सर्वर-टू-सर्वर पुष्टि करने की सुविधा देता है. अगर आपको क्लाइंट-टू-सर्वर अप्रोच का इस्तेमाल करके, Live API ऐप्लिकेशन लागू करना है, तो आपको सुरक्षा से जुड़े जोखिमों को कम करने के लिए, कुछ समय के लिए मान्य टोकन का इस्तेमाल करना होगा.

सत्र की अवधि

सिर्फ़ ऑडियो वाले सेशन 15 मिनट तक किए जा सकते हैं. वहीं, ऑडियो और वीडियो, दोनों वाले सेशन सिर्फ़ दो मिनट तक किए जा सकते हैं. हालांकि, सेशन की अवधि के दौरान असीमित एक्सटेंशन के लिए, अलग-अलग सेशन मैनेजमेंट तकनीकें कॉन्फ़िगर की जा सकती हैं.

कॉन्टेक्स्ट विंडो

किसी सेशन के लिए कॉन्टेक्स्ट विंडो की सीमा यह होती है:

इस्तेमाल की जा सकने वाली भाषाएं

लाइव एपीआई, इन भाषाओं में काम करता है.

भाषा BCP-47 कोड भाषा BCP-47 कोड
जर्मन (जर्मनी) de-DE अंग्रेज़ी (ऑस्ट्रेलिया)* en-AU
अंग्रेज़ी (यूके)* en-GB अंग्रेज़ी (भारत) en-IN
अंग्रेज़ी (यूएस) en-US स्पैनिश (अमेरिका) es-US
फ़्रेंच (फ़्रांस) fr-FR हिन्दी (भारत) hi-IN
पॉर्चुगीज़ (ब्राज़ील) pt-BR अरबी (सामान्य) ar-XA
स्पैनिश (स्पेन)* es-ES फ़्रेंच (कनाडा)* fr-CA
इंडोनेशियन (इंडोनेशिया) id-ID इटैलियन (इटली) it-IT
जैपनीज़ (जापान) ja-JP टर्किश (तुर्किये) tr-TR
वियतनामीज़ (वियतनाम) vi-VN बांग्ला (भारत) bn-IN
गुजराती (भारत)* gu-IN कन्नड़ (भारत)* kn-IN
मराठी (भारत) mr-IN मलयालम (भारत)* ml-IN
तमिल (भारत) ta-IN तेलुगू (भारत) te-IN
डच (नीदरलैंड्स) nl-NL कोरियन (दक्षिण कोरिया) ko-KR
मैंडरिन चाइनीज़ (चीन)* cmn-CN पोलिश (पोलैंड) pl-PL
रशियन (रूस) ru-RU थाई (थाईलैंड) th-TH

जिन भाषाओं पर तारे का निशान (*) है उनमें नेटिव ऑडियो की सुविधा उपलब्ध नहीं है.

आगे क्या करना है