Gemini Live API की मदद से, Gemini के साथ कम समय में दोनों तरीकों से टेक्स्ट और आवाज़ का इस्तेमाल करके बातचीत की जा सकती है. Live API का इस्तेमाल करके, लोगों को इंसानों जैसी आवाज़ में बातचीत करने का अनुभव दिया जा सकता है. साथ ही, उन्हें टेक्स्ट या बोलकर दिए जाने वाले निर्देशों का इस्तेमाल करके, मॉडल के जवाबों को बीच में रोकने की सुविधा दी जा सकती है. यह मॉडल, टेक्स्ट और ऑडियो इनपुट को प्रोसेस कर सकता है. वीडियो इनपुट को प्रोसेस करने की सुविधा जल्द ही उपलब्ध होगी. साथ ही, यह टेक्स्ट और ऑडियो आउटपुट दे सकता है.
प्रॉम्प्ट और Live API Google AI Studio या Vertex AI Studio की मदद से प्रोटोटाइप बनाया जा सकता है.
Live API एक स्टेटफ़ुल एपीआई है. यह क्लाइंट और Gemini सर्वर के बीच सेशन शुरू करने के लिए, WebSocket कनेक्शन बनाता है. ज़्यादा जानकारी के लिए, Live API का रेफ़रंस दस्तावेज़ (Gemini Developer API | Vertex AI Gemini API) देखें.
शुरू करने से पहले
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API सेवा देने वाली कंपनी पर क्लिक करें. |
अगर आपने अब तक शुरुआती गाइड नहीं पढ़ी है, तो इसे पढ़ें. इसमें बताया गया है कि Firebase प्रोजेक्ट कैसे सेट अप करें, अपने ऐप्लिकेशन को Firebase से कैसे कनेक्ट करें, एसडीके कैसे जोड़ें, चुने गए Gemini API प्रोवाइडर के लिए बैकएंड सेवा को कैसे शुरू करें, और LiveModel इंस्टेंस कैसे बनाएं.
इस सुविधा के साथ काम करने वाले मॉडल
Live API की सुविधा देने वाले मॉडल, आपके चुने गए Gemini API सेवा देने वाले व्यक्ति या कंपनी पर निर्भर करते हैं.
Gemini Developer API
gemini-live-2.5-flash(private GA*)gemini-live-2.5-flash-previewgemini-2.0-flash-live-001gemini-2.0-flash-live-preview-04-09
Vertex AI Gemini API
gemini-live-2.5-flash(private GA*)gemini-2.0-flash-live-preview-04-09(सिर्फ़us-central1में ऐक्सेस करने के लिए उपलब्ध है)
ध्यान दें कि Live API के लिए 2.5 मॉडल के नामों में, live सेगमेंट, gemini सेगमेंट के तुरंत बाद आता है.
* ऐक्सेस का अनुरोध करने के लिए, अपनी Google Cloud खाता टीम के प्रतिनिधि से संपर्क करें.
Live API की स्टैंडर्ड सुविधाओं का इस्तेमाल करना
इस सेक्शन में, Live API की स्टैंडर्ड सुविधाओं का इस्तेमाल करने का तरीका बताया गया है. खास तौर पर, अलग-अलग तरह के इनपुट और आउटपुट को स्ट्रीम करने के लिए:
स्ट्रीम किए गए टेक्स्ट इनपुट से स्ट्रीम किया गया टेक्स्ट जनरेट करना
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिए गए निर्देशों को पूरा करें. इससे आपको अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करने में मदद मिलेगी. उस सेक्शन में, आपको Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर भी क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
स्ट्रीम किए गए टेक्स्ट इनपुट को भेजा जा सकता है और स्ट्रीम किए गए टेक्स्ट आउटपुट को पाया जा सकता है. पक्का करें कि आपने liveModel इंस्टेंस बनाया हो और जवाब देने का तरीका Text पर सेट किया हो.
Swift
import FirebaseAI
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
let model = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
generationConfig: LiveGenerationConfig(
responseModalities: [.text]
)
)
do {
let session = try await model.connect()
// Provide a text prompt
let text = "tell a short story"
await session.sendTextRealtime(text)
var outputText = ""
for try await message in session.responses {
if case let .content(content) = message.payload {
content.modelTurn?.parts.forEach { part in
if let part = part as? TextPart {
outputText += part.text
}
}
// Optional: if you don't require to send more requests.
if content.isTurnComplete {
await session.close()
}
}
}
// Output received from the server.
print(outputText)
} catch {
fatalError(error.localizedDescription)
}
Kotlin
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.TEXT
}
)
val session = model.connect()
// Provide a text prompt
val text = "tell a short story"
session.send(text)
var outputText = ""
session.receive().collect {
if(it.turnComplete) {
// Optional: if you don't require to send more requests.
session.stopReceiving();
}
outputText = outputText + it.text
}
// Output received from the server.
println(outputText)
Java
ExecutorService executor = Executors.newFixedThreadPool(1);
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
new LiveGenerationConfig.Builder()
.setResponseModalities(ResponseModality.TEXT)
.build()
);
LiveModelFutures model = LiveModelFutures.from(lm);
ListenableFuture<LiveSession> sessionFuture = model.connect();
class LiveContentResponseSubscriber implements Subscriber<LiveContentResponse> {
@Override
public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE); // Request an unlimited number of items
}
@Override
public void onNext(LiveContentResponse liveContentResponse) {
// Handle the response from the server.
System.out.println(liveContentResponse.getText());
}
@Override
public void onError(Throwable t) {
System.err.println("Error: " + t.getMessage());
}
@Override
public void onComplete() {
System.out.println("Done receiving messages!");
}
}
Futures.addCallback(sessionFuture, new FutureCallback<LiveSession>() {
@Override
public void onSuccess(LiveSession ses) {
LiveSessionFutures session = LiveSessionFutures.from(ses);
// Provide a text prompt
String text = "tell me a short story?";
session.send(text);
Publisher<LiveContentResponse> publisher = session.receive();
publisher.subscribe(new LiveContentResponseSubscriber());
}
@Override
public void onFailure(Throwable t) {
// Handle exceptions
}
}, executor);
Web
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `LiveGenerativeModel` instance with the flash-live model (only model that supports the Live API)
const model = getLiveGenerativeModel(ai, {
model: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
generationConfig: {
responseModalities: [ResponseModality.TEXT],
},
});
const session = await model.connect();
// Provide a text prompt
const prompt = "tell a short story";
session.send(prompt);
// Collect text from model's turn
let text = "";
const messages = session.receive();
for await (const message of messages) {
switch (message.type) {
case "serverContent":
if (message.turnComplete) {
console.log(text);
} else {
const parts = message.modelTurn?.parts;
if (parts) {
text += parts.map((part) => part.text).join("");
}
}
break;
case "toolCall":
// Ignore
case "toolCallCancellation":
// Ignore
}
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
late LiveModelSession _session;
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
final model = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.0-flash-live-preview-04-09',
// Configure the model to respond with text
liveGenerationConfig: LiveGenerationConfig(responseModalities: [ResponseModalities.text]),
);
_session = await model.connect();
// Provide a text prompt
final prompt = Content.text('tell a short story');
await _session.send(input: prompt, turnComplete: true);
// In a separate thread, receive the response
await for (final message in _session.receive()) {
// Process the received message
}
Unity
using Firebase;
using Firebase.AI;
async Task SendTextReceiveText() {
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Text })
);
LiveSession session = await model.ConnectAsync();
// Provide a text prompt
var prompt = ModelContent.Text("tell a short story");
await session.SendAsync(content: prompt, turnComplete: true);
// Receive the response
await foreach (var message in session.ReceiveAsync()) {
// Process the received message
if (!string.IsNullOrEmpty(message.Text)) {
UnityEngine.Debug.Log("Received message: " + message.Text);
}
}
}
स्ट्रीम किए गए ऑडियो इनपुट से स्ट्रीम किया गया ऑडियो जनरेट करना
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिए गए निर्देशों को पूरा करें. इससे आपको अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करने में मदद मिलेगी. उस सेक्शन में, आपको Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर भी क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
स्ट्रीम किए गए ऑडियो इनपुट को भेजा जा सकता है और स्ट्रीम किए गए ऑडियो आउटपुट को रिसीव किया जा सकता है. पक्का करें कि आपने LiveModel इंस्टेंस बनाया हो और जवाब देने का तरीका Audio पर सेट किया हो.
इस पेज पर आगे, जवाब देने वाली आवाज़ को कॉन्फ़िगर और कस्टमाइज़ करने का तरीका जानें.
Swift
import FirebaseAI
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
let model = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with audio
generationConfig: LiveGenerationConfig(
responseModalities: [.audio]
)
)
do {
let session = try await model.connect()
// Load the audio file, or tap a microphone
guard let audioFile = NSDataAsset(name: "audio.pcm") else {
fatalError("Failed to load audio file")
}
// Provide the audio data
await session.sendAudioRealtime(audioFile.data)
var outputText = ""
for try await message in session.responses {
if case let .content(content) = message.payload {
content.modelTurn?.parts.forEach { part in
if let part = part as? InlineDataPart, part.mimeType.starts(with: "audio/pcm") {
// Handle 16bit pcm audio data at 24khz
playAudio(part.data)
}
}
// Optional: if you don't require to send more requests.
if content.isTurnComplete {
await session.close()
}
}
}
} catch {
fatalError(error.localizedDescription)
}
Kotlin
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
}
)
val session = model.connect()
// This is the recommended way.
// However, you can create your own recorder and handle the stream.
session.startAudioConversation()
Java
ExecutorService executor = Executors.newFixedThreadPool(1);
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with text
new LiveGenerationConfig.Builder()
.setResponseModalities(ResponseModality.TEXT)
.build()
);
LiveModelFutures model = LiveModelFutures.from(lm);
ListenableFuture<LiveSession> sessionFuture = model.connect();
Futures.addCallback(sessionFuture, new FutureCallback<LiveSession>() {
@Override
public void onSuccess(LiveSession ses) {
LiveSessionFutures session = LiveSessionFutures.from(ses);
session.startAudioConversation();
}
@Override
public void onFailure(Throwable t) {
// Handle exceptions
}
}, executor);
Web
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `LiveGenerativeModel` instance with the flash-live model (only model that supports the Live API)
const model = getLiveGenerativeModel(ai, {
model: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with audio
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
},
});
const session = await model.connect();
// Start the audio conversation
const audioConversationController = await startAudioConversation(session);
// ... Later, to stop the audio conversation
// await audioConversationController.stop()
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import 'package:your_audio_recorder_package/your_audio_recorder_package.dart';
late LiveModelSession _session;
final _audioRecorder = YourAudioRecorder();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
final model = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.0-flash-live-preview-04-09',
// Configure the model to respond with audio
liveGenerationConfig: LiveGenerationConfig(responseModalities: [ResponseModalities.audio]),
);
_session = await model.connect();
final audioRecordStream = _audioRecorder.startRecordingStream();
// Map the Uint8List stream to InlineDataPart stream
final mediaChunkStream = audioRecordStream.map((data) {
return InlineDataPart('audio/pcm', data);
});
await _session.startMediaStream(mediaChunkStream);
// In a separate thread, receive the audio response from the model
await for (final message in _session.receive()) {
// Process the received message
}
Unity
using Firebase;
using Firebase.AI;
async Task SendTextReceiveAudio() {
// Initialize the Gemini Developer API backend service
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to respond with audio
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio })
);
LiveSession session = await model.ConnectAsync();
// Start a coroutine to send audio from the Microphone
var recordingCoroutine = StartCoroutine(SendAudio(session));
// Start receiving the response
await ReceiveAudio(session);
}
IEnumerator SendAudio(LiveSession liveSession) {
string microphoneDeviceName = null;
int recordingFrequency = 16000;
int recordingBufferSeconds = 2;
var recordingClip = Microphone.Start(microphoneDeviceName, true,
recordingBufferSeconds, recordingFrequency);
int lastSamplePosition = 0;
while (true) {
if (!Microphone.IsRecording(microphoneDeviceName)) {
yield break;
}
int currentSamplePosition = Microphone.GetPosition(microphoneDeviceName);
if (currentSamplePosition != lastSamplePosition) {
// The Microphone uses a circular buffer, so we need to check if the
// current position wrapped around to the beginning, and handle it
// accordingly.
int sampleCount;
if (currentSamplePosition > lastSamplePosition) {
sampleCount = currentSamplePosition - lastSamplePosition;
} else {
sampleCount = recordingClip.samples - lastSamplePosition + currentSamplePosition;
}
if (sampleCount > 0) {
// Get the audio chunk
float[] samples = new float[sampleCount];
recordingClip.GetData(samples, lastSamplePosition);
// Send the data, discarding the resulting Task to avoid the warning
_ = liveSession.SendAudioAsync(samples);
lastSamplePosition = currentSamplePosition;
}
}
// Wait for a short delay before reading the next sample from the Microphone
const float MicrophoneReadDelay = 0.5f;
yield return new WaitForSeconds(MicrophoneReadDelay);
}
}
Queue audioBuffer = new();
async Task ReceiveAudio(LiveSession liveSession) {
int sampleRate = 24000;
int channelCount = 1;
// Create a looping AudioClip to fill with the received audio data
int bufferSamples = (int)(sampleRate * channelCount);
AudioClip clip = AudioClip.Create("StreamingPCM", bufferSamples, channelCount,
sampleRate, true, OnAudioRead);
// Attach the clip to an AudioSource and start playing it
AudioSource audioSource = GetComponent();
audioSource.clip = clip;
audioSource.loop = true;
audioSource.Play();
// Start receiving the response
await foreach (var message in liveSession.ReceiveAsync()) {
// Process the received message
foreach (float[] pcmData in message.AudioAsFloat) {
lock (audioBuffer) {
foreach (float sample in pcmData) {
audioBuffer.Enqueue(sample);
}
}
}
}
}
// This method is called by the AudioClip to load audio data.
private void OnAudioRead(float[] data) {
int samplesToProvide = data.Length;
int samplesProvided = 0;
lock(audioBuffer) {
while (samplesProvided < samplesToProvide && audioBuffer.Count > 0) {
data[samplesProvided] = audioBuffer.Dequeue();
samplesProvided++;
}
}
while (samplesProvided < samplesToProvide) {
data[samplesProvided] = 0.0f;
samplesProvided++;
}
}
ज़्यादा दिलचस्प और इंटरैक्टिव अनुभव बनाना
इस सेक्शन में, Live API की ज़्यादा दिलचस्प या इंटरैक्टिव सुविधाओं को बनाने और मैनेज करने का तरीका बताया गया है.
जवाब देने वाली आवाज़ बदलना
Live API, बोलकर जवाब देने की सुविधा के लिए Chirp 3 का इस्तेमाल करता है. Firebase AI Logic का इस्तेमाल करते समय, ऑडियो को अलग-अलग एचडी आवाज़ों में भेजा जा सकता है. आवाज़ों की पूरी सूची और हर आवाज़ का डेमो देखने के लिए, Chirp 3: एचडी क्वालिटी की आवाज़ें पर जाएं.
आवाज़ तय करने के लिए, speechConfig ऑब्जेक्ट में आवाज़ का नाम सेट करें. यह मॉडल कॉन्फ़िगरेशन का हिस्सा होता है.
अगर आपने कोई आवाज़ नहीं चुनी है, तो डिफ़ॉल्ट रूप से Puck को चुना जाता है.
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिए गए निर्देशों को पूरा करें. इससे आपको अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करने में मदद मिलेगी. उस सेक्शन में, आपको Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर भी क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
Swift
import FirebaseAI
// ...
let model = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to use a specific voice for its audio response
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
speech: SpeechConfig(voiceName: "VOICE_NAME")
)
)
// ...
Kotlin
// ...
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
// Configure the model to use a specific voice for its audio response
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voice("VOICE_NAME"))
}
)
// ...
Java
// ...
LiveModel model = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.0-flash-live-preview-04-09",
// Configure the model to use a specific voice for its audio response
new LiveGenerationConfig.Builder()
.setResponseModalities(ResponseModality.AUDIO)
.setSpeechConfig(new SpeechConfig(new Voice("VOICE_NAME")))
.build()
);
// ...
Web
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `LiveModel` instance with the flash-live model (only model that supports the Live API)
const model = getLiveGenerativeModel(ai, {
model: "gemini-2.0-flash-live-preview-04-09",
// Configure the model to use a specific voice for its audio response
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: { voiceName: "VOICE_NAME" },
},
},
},
});
Dart
// ...
final model = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.0-flash-live-preview-04-09',
// Configure the model to use a specific voice for its audio response
liveGenerationConfig: LiveGenerationConfig(
responseModalities: ResponseModalities.audio,
speechConfig: SpeechConfig(voiceName: 'VOICE_NAME'),
),
);
// ...
Unity
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.0-flash-live-preview-04-09",
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("VOICE_NAME"))
);
अगर आपको मॉडल से किसी दूसरी भाषा में जवाब चाहिए, तो बेहतर नतीजे पाने के लिए, सिस्टम के निर्देशों में यह जानकारी शामिल करें:
RESPOND IN LANGUAGE. YOU MUST RESPOND UNMISTAKABLY IN LANGUAGE.
सभी सेशन और अनुरोधों में कॉन्टेक्स्ट बनाए रखना
सेशन और अनुरोधों के बीच संदर्भ बनाए रखने के लिए, चैट स्ट्रक्चर का इस्तेमाल किया जा सकता है. ध्यान दें कि यह सुविधा सिर्फ़ टेक्स्ट इनपुट और टेक्स्ट आउटपुट के लिए काम करती है.
यह तरीका छोटे कॉन्टेक्स्ट के लिए सबसे अच्छा है. इवेंट के सटीक क्रम को दिखाने के लिए, बारी-बारी से इंटरैक्शन भेजे जा सकते हैं. ज़्यादा बड़े कॉन्टेक्स्ट के लिए, हमारा सुझाव है कि एक ही मैसेज की खास जानकारी दी जाए, ताकि बाद में होने वाली बातचीत के लिए कॉन्टेक्स्ट विंडो खाली हो जाए.
रुकावटों को मैनेज करना
Firebase AI Logic में, अभी तक रुकावटों को हैंडल करने की सुविधा नहीं है. जल्द ही वापस जाँचें!
फ़ंक्शन कॉलिंग (टूल) का इस्तेमाल करना
लाइव एपीआई के साथ इस्तेमाल करने के लिए, उपलब्ध फ़ंक्शन जैसे टूल तय किए जा सकते हैं. ऐसा कॉन्टेंट जनरेट करने के स्टैंडर्ड तरीकों के साथ भी किया जा सकता है. इस सेक्शन में, फ़ंक्शन कॉलिंग के साथ Live API का इस्तेमाल करते समय ध्यान रखने वाली कुछ बातों के बारे में बताया गया है. फ़ंक्शन कॉलिंग के बारे में पूरी जानकारी और उदाहरणों के लिए, फ़ंक्शन कॉलिंग गाइड देखें.
एक ही प्रॉम्प्ट से, मॉडल कई फ़ंक्शन कॉल जनरेट कर सकता है. साथ ही, उनके आउटपुट को एक साथ जोड़ने के लिए ज़रूरी कोड भी जनरेट कर सकता है. यह कोड, सैंडबॉक्स एनवायरमेंट में काम करता है. इससे BidiGenerateContentToolCall मैसेज जनरेट होते हैं. हर फ़ंक्शन कॉल के नतीजे उपलब्ध होने तक, एक्ज़ीक्यूशन रुक जाता है. इससे यह पक्का होता है कि प्रोसेसिंग क्रम से हो.
इसके अलावा, फ़ंक्शन कॉलिंग के साथ Live API का इस्तेमाल करना खास तौर पर फ़ायदेमंद होता है. इसकी वजह यह है कि मॉडल, उपयोगकर्ता से फ़ॉलो-अप या ज़्यादा जानकारी का अनुरोध कर सकता है. उदाहरण के लिए, अगर मॉडल के पास किसी फ़ंक्शन को कॉल करने के लिए, पैरामीटर की वैल्यू देने के लिए ज़रूरी जानकारी नहीं है, तो मॉडल उपयोगकर्ता से ज़्यादा या साफ़ तौर पर जानकारी देने के लिए कह सकता है.
क्लाइंट को BidiGenerateContentToolResponse के साथ जवाब देना चाहिए.
सीमाएं और ज़रूरी शर्तें
Live API की इन सीमाओं और ज़रूरी शर्तों का ध्यान रखें.
लिप्यंतरण
Firebase AI Logic में, फ़िलहाल ट्रांसक्रिप्शन की सुविधा उपलब्ध नहीं है. जल्द ही वापस जाँचें!
भाषाएं
- इनपुट की भाषाएं: Gemini मॉडल के लिए, इनपुट की भाषाओं की पूरी सूची देखें
- आउटपुट की भाषाएं: Chirp 3: एचडी वॉइस में, आउटपुट के लिए उपलब्ध भाषाओं की पूरी सूची देखें
ऑडियो फ़ॉर्मैट
Live API फ़ंक्शन इन ऑडियो फ़ॉर्मैट के साथ काम करता है:
- इनपुट ऑडियो फ़ॉर्मैट: रॉ 16 बिट पीसीएम ऑडियो, 16 किलोहर्ट्ज़ लिटिल-एंडियन पर
- आउटपुट ऑडियो फ़ॉर्मैट: रॉ 16 बिट पीसीएम ऑडियो, 24 किलोहर्ट्ज़ लिटिल-एंडियन पर
तय सीमाएं
Live API में, हर Firebase प्रोजेक्ट के लिए एक साथ चल रहे सेशन और हर मिनट के टोकन (टीपीएम) की दर की सीमाएं होती हैं.
Gemini Developer API:
- सीमाएं, आपके प्रोजेक्ट के Gemini Developer API"इस्तेमाल के टियर" के आधार पर अलग-अलग होती हैं. इसके बारे में जानने के लिए, दर की सीमाओं से जुड़ा दस्तावेज़ देखें
Vertex AI Gemini API:
- हर Firebase प्रोजेक्ट के लिए, एक साथ 5,000 सेशन
- हर मिनट 40 लाख टोकन
सेशन की अवधि
किसी सेशन की डिफ़ॉल्ट अवधि 10 मिनट होती है. सेशन की अवधि तय सीमा से ज़्यादा होने पर, कनेक्शन बंद कर दिया जाता है.
मॉडल, कॉन्टेक्स्ट के साइज़ के हिसाब से भी काम करता है. एक साथ बहुत ज़्यादा इनपुट भेजने पर, पिछले सेशन को बंद किया जा सकता है.
आवाज़ की गतिविधि का पता लगाने की सुविधा (वीएडी)
यह मॉडल, ऑडियो इनपुट स्ट्रीम पर लगातार वॉइस ऐक्टिविटी का पता लगाने (वीएडी) की सुविधा अपने-आप लागू करता है. वीएडी की सुविधा डिफ़ॉल्ट रूप से चालू होती है.
टोकन की गिनती
Live API के साथ CountTokens एपीआई का इस्तेमाल नहीं किया जा सकता.
Firebase AI Logic के साथ अपने अनुभव के बारे में सुझाव/राय दें या शिकायत करें