Live API को बुनियादी तौर पर लागू करने पर भी, उपयोगकर्ताओं के लिए दिलचस्प और असरदार इंटरैक्शन बनाए जा सकते हैं. आपके पास इन कॉन्फ़िगरेशन विकल्पों का इस्तेमाल करके, अनुभव को अपनी पसंद के मुताबिक और भी बेहतर बनाने का विकल्प होता है:
जवाब देने की आवाज़ और भाषा
मॉडल को किसी खास आवाज़ में जवाब देने के लिए कहा जा सकता है. साथ ही, मॉडल को अलग-अलग भाषाओं में जवाब देने के लिए भी कहा जा सकता है.
जवाब देने के लिए आवाज़ सेट करना
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
Live API में, सिंथेसाइज़ की गई 30 अलग-अलग एचडी आवाज़ें होती हैं. हर आवाज़ की अपनी अलग विशेषताएं होती हैं. नीचे दिए गए सेक्शन को बड़ा करके, जवाब देने के लिए उपलब्ध आवाज़ों की सूची देखी जा सकती है और हर आवाज़ का डेमो सुना जा सकता है.
अगर आपने जवाब देने के लिए कोई आवाज़ नहीं चुनी है, तो डिफ़ॉल्ट रूप से Puck का इस्तेमाल किया जाएगा.
जवाब देने के लिए आवाज़ तय करने के लिए, speechConfig ऑब्जेक्ट में आवाज़ का नाम सेट करें. यह मॉडल कॉन्फ़िगरेशन का हिस्सा है.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.5-flash-native-audio-preview-12-2025",
// 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.5-flash-native-audio-preview-12-2025",
// Configure the model to use a specific voice for its audio response.
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voice("VOICE_NAME"))
}
)
// ...
Java
// ...
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to use a specific voice for its audio response.
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
.setSpeechConfig(new SpeechConfig(new Voice("VOICE_NAME")))
.build()
);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const liveModel = getLiveGenerativeModel(ai, {
model: "gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to use a specific voice for its audio response.
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: { voiceName: "VOICE_NAME" },
},
},
},
});
// ...
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.5-flash-native-audio-preview-12-2025',
// Configure the model to use a specific voice for its audio response.
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
speechConfig: SpeechConfig(voiceName: 'VOICE_NAME'),
),
);
// ...
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to use a specific voice for its audio response
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("VOICE_NAME")
)
);
// ...
जवाब की भाषा पर असर डालना
Live API मॉडल, जवाब देने के लिए सही भाषा अपने-आप चुन लेते हैं.
अगर आपको मॉडल से अंग्रेज़ी के अलावा किसी अन्य भाषा में जवाब चाहिए या हमेशा किसी खास भाषा में जवाब चाहिए, तो सिस्टम के निर्देशों का इस्तेमाल करके, मॉडल के जवाबों को अपनी पसंद के मुताबिक बनाया जा सकता है. जैसे:
मॉडल को यह बताना कि अंग्रेज़ी के अलावा किसी दूसरी भाषा का इस्तेमाल करना सही हो सकता है
Listen to the speaker carefully. If you detect a non-English language, respond in the language you hear from the speaker. You must respond unmistakably in the speaker's language.मॉडल को हमेशा किसी खास भाषा में जवाब देने के लिए कहना
RESPOND IN LANGUAGE. YOU MUST RESPOND UNMISTAKABLY IN LANGUAGE.
ऑडियो इनपुट और आउटपुट के लिए ट्रांसक्रिप्शन
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
मॉडल के जवाब के तौर पर, आपको ऑडियो इनपुट और मॉडल के ऑडियो जवाब की ट्रांसक्रिप्ट मिल सकती है. इस कॉन्फ़िगरेशन को मॉडल कॉन्फ़िगरेशन के तौर पर सेट किया जाता है.
ऑडियो इनपुट को ट्रांसक्राइब करने के लिए,
inputAudioTranscriptionजोड़ें.मॉडल के ऑडियो रिस्पॉन्स को टेक्स्ट में बदलने के लिए,
outputAudioTranscriptionजोड़ें.
निम्न पर ध्यान दें:
मॉडल को इनपुट और आउटपुट, दोनों के ट्रांसक्रिप्शन दिखाने के लिए कॉन्फ़िगर किया जा सकता है. जैसा कि यहां दिए गए उदाहरण में दिखाया गया है. इसके अलावा, मॉडल को सिर्फ़ एक ट्रांसक्रिप्शन दिखाने के लिए भी कॉन्फ़िगर किया जा सकता है.
ट्रांसक्रिप्ट को ऑडियो के साथ स्ट्रीम किया जाता है. इसलिए, इन्हें उसी तरह इकट्ठा करें जिस तरह हर बारी में टेक्स्ट वाले हिस्से इकट्ठा किए जाते हैं.
बोली को लेख में बदलने की भाषा का पता, ऑडियो इनपुट और मॉडल के ऑडियो जवाब से लगाया जाता है.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to return transcriptions of the audio input and output.
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
inputAudioTranscription: AudioTranscriptionConfig(),
outputAudioTranscription: AudioTranscriptionConfig()
)
)
var inputTranscript: String = ""
var outputTranscript: String = ""
do {
let session = try await liveModel.connect()
for try await response in session.responses {
if case let .content(content) = response.payload {
if let inputText = content.inputAudioTranscription?.text {
// Handle transcription text of the audio input.
inputTranscript += inputText
}
if let outputText = content.outputAudioTranscription?.text {
// Handle transcription text of the audio output.
outputTranscript += outputText
}
if content.isTurnComplete {
// Log the transcripts after the current turn is complete.
print("Input audio: \(inputTranscript)")
print("Output audio: \(outputTranscript)")
// Reset the transcripts for the next turn.
inputTranscript = ""
outputTranscript = ""
}
}
}
} catch {
// Handle error
}
// ...
Kotlin
// ...
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to return transcriptions of the audio input and output.
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
inputAudioTranscription = AudioTranscriptionConfig()
outputAudioTranscription = AudioTranscriptionConfig()
}
)
val liveSession = liveModel.connect()
fun handleTranscription(input: Transcription?, output: Transcription?) {
input?.text?.let { text ->
// Handle transcription text of the audio input.
println("Input Transcription: $text")
}
output?.text?.let { text ->
// Handle transcription text of the audio output.
println("Output Transcription: $text")
}
}
liveSession.startAudioConversation(null, ::handleTranscription)
// ...
Java
// ...
ExecutorService executor = Executors.newFixedThreadPool(1);
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to return transcriptions of the audio input and output.
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
.setInputAudioTranscription(new AudioTranscriptionConfig())
.setOutputAudioTranscription(new AudioTranscriptionConfig())
.build()
);
LiveModelFutures liveModel = LiveModelFutures.from(lm);
ListenableFuture sessionFuture = liveModel.connect();
Futures.addCallback(sessionFuture, new FutureCallback() {
@Override
public void onSuccess(LiveSessionFutures ses) {
LiveSessionFutures session = ses;
session.startAudioConversation((Transcription input, Transcription output) -> {
if (input != null) {
// Handle transcription text of the audio input.
System.out.println("Input Transcription: " + input.getText());
}
if (output != null) {
// Handle transcription text of the audio output.
System.out.println("Output Transcription: " + output.getText());
}
return null;
});
}
@Override
public void onFailure(Throwable t) {
// Handle exceptions
t.printStackTrace();
}
}, executor);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const liveModel = getLiveGenerativeModel(ai, {
model: 'gemini-2.5-flash-native-audio-preview-12-2025',
// Configure the model to return transcriptions of the audio input and output.
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
inputAudioTranscription: {},
outputAudioTranscription: {},
},
});
const liveSession = await liveModel.connect();
liveSession.sendAudioRealtime({ data, mimeType: "audio/pcm" });
const messages = liveSession.receive();
for await (const message of messages) {
switch (message.type) {
case 'serverContent':
if (message.inputTranscription) {
// Handle transcription text of the audio input.
console.log(`Input transcription: ${message.inputTranscription.text}`);
}
if (message.outputTranscription) {
// Handle transcription text of the audio output.
console.log(`Output transcription: ${message.outputTranscription.text}`);
} else {
// Handle other message types (modelTurn, turnComplete, interruption).
}
default:
// Handle other message types (toolCall, toolCallCancellation).
}
}
// ...
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.5-flash-native-audio-preview-12-2025',
// Configure the model to return transcriptions of the audio input and output.
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
inputAudioTranscription: AudioTranscriptionConfig(),
outputAudioTranscription: AudioTranscriptionConfig(),
),
);
final LiveSession _session = _liveModel.connect();
await for (final response in _session.receive()) {
LiveServerContent message = response.message;
if (message.inputTranscription?.text case final inputText?) {
// Handle transcription text of the audio input.
print('Input: $inputText');
}
if (message.outputTranscription?.text case final outputText?) {
// Handle transcription text of the audio output.
print('Output: $outputText');
}
}
// ...
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.5-flash-native-audio-preview-12-2025",
// Configure the model to return transcriptions of the audio input and output
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
inputAudioTranscription: new AudioTranscriptionConfig(),
outputAudioTranscription: new AudioTranscriptionConfig()
)
);
try
{
var session = await liveModel.ConnectAsync();
var stream = session.ReceiveAsync();
await foreach (var response in stream) {
if (response.Message is LiveSessionContent sessionContent) {
if (!string.IsNullOrEmpty(sessionContent.InputTranscription?.Text)) {
// handle transcription text of input audio
}
if (!string.IsNullOrEmpty(sessionContent.OutputTranscription?.Text)) {
// handle transcription text of output audio
}
}
}
}
catch (Exception e)
{
// Handle error
}
// ...
आवाज़ का पता लगाने की तकनीक (वीएडी)
यह मॉडल, ऑडियो इनपुट स्ट्रीम पर लगातार आवाज़ का पता लगाने की सुविधा (वीएडी) अपने-आप लागू करता है. वीएडी की सुविधा डिफ़ॉल्ट रूप से चालू होती है.
सेशन मैनेजमेंट
सेशन से जुड़े इन विषयों के बारे में जानें:
इसमें ये बेहतरीन सुविधाएं मिलती हैं:
सेशन से जुड़ी सीमाएं. इनमें कनेक्शन और सेशन की अवधि से जुड़ी सीमाएं, सेशन के कॉन्टेक्स्ट विंडो की सीमाएं, और दर की सीमाएं शामिल हैं.
सेशन की सीमाओं को मैनेज करने के विकल्प. इनमें ये शामिल हैं: