Live API को बुनियादी तौर पर लागू करके भी, उपयोगकर्ताओं के लिए दिलचस्प और असरदार इंटरैक्शन बनाए जा सकते हैं. कॉन्फ़िगरेशन के इन विकल्पों का इस्तेमाल करके, अनुभव को और भी ज़्यादा पसंद के मुताबिक बनाया जा सकता है:
आवाज़ का पता लगाने की तकनीक (वीएडी) (उदाहरण के लिए, रुकावटों को मैनेज करने के लिए)
जवाब देने की आवाज़ और भाषा
मॉडल को किसी ख़ास आवाज़ में जवाब देने के लिए कहा जा सकता है. साथ ही, उसे अलग-अलग भाषाओं में जवाब देने के लिए भी कहा जा सकता है.
जवाब देने के लिए कोई आवाज़ चुनें
|
इस पेज पर, Gemini API की सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, सेवा देने वाली कंपनी के नाम पर क्लिक करें. |
Live API में, 30 अलग-अलग तरह की सिंथसाइज़ की गई एचडी आवाज़ें उपलब्ध हैं. हर आवाज़ की अपनी खासियत है. नीचे दिए गए सेक्शन को बड़ा करके, जवाब देने के लिए उपलब्ध आवाज़ों की सूची देखी जा सकती है और हर आवाज़ का डेमो सुना जा सकता है.
अगर आपने जवाब देने के लिए कोई आवाज़ नहीं चुनी है, तो डिफ़ॉल्ट रूप से Puck का इस्तेमाल किया जाएगा.
जवाब देने वाली आवाज़ तय करने के लिए, मॉडल कॉन्फ़िगरेशन के हिस्से के तौर पर, speechConfig ऑब्जेक्ट में आवाज़ का नाम सेट करें.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME',
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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_LIVE_API_MODEL_NAME",
// 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<LiveSessionFutures> sessionFuture = liveModel.connect();
Futures.addCallback(sessionFuture, new FutureCallback<LiveSessionFutures>() {
@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_LIVE_API_MODEL_NAME',
// 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_LIVE_API_MODEL_NAME',
// Configure the model to return transcriptions of the audio input and output.
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
inputAudioTranscription: AudioTranscriptionConfig(),
outputAudioTranscription: AudioTranscriptionConfig(),
),
);
final LiveSession _session = await _liveModel.connect();
await for (final response in _session.receive()) {
if (response.message case LiveServerContent 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_LIVE_API_MODEL_NAME",
// 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
}
// ...
आवाज़ का पता लगाने की तकनीक (वीएडी)
आवाज़ का पता लगाने की तकनीक (वीएडी) की मदद से, मॉडल यह पहचान पाता है कि कोई व्यक्ति कब बोल रहा है. यह सुविधा, बातचीत को नैचुरल बनाने के लिए ज़रूरी है. इसकी मदद से, मॉडल को किसी भी समय रोका जा सकता है. वीएडी की सुविधा डिफ़ॉल्ट रूप से चालू होती है.
वीएडी के काम करने के तरीके को पसंद के मुताबिक़ बनाया जा सकता है. इसमें रुकावटों को हैंडल करना भी शामिल है. इसके अलावा, बातचीत के दौरान बोलने की बारी को मैन्युअल तरीके से कंट्रोल करने के लिए, वीएडी की सुविधा को बंद किया जा सकता है. जैसे, पुश-टू-टॉक इंटरफ़ेस के लिए.
आवाज़ का पता लगाने की तकनीक (वीएडी) को कॉन्फ़िगर करना
|
इस पेज पर, Gemini API की सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, सेवा देने वाली कंपनी के नाम पर क्लिक करें. |
यहां दिए गए उदाहरण में बताया गया है कि मॉडल कॉन्फ़िगरेशन के हिस्से के तौर पर realtimeInputConfig को सेट करके, वीएडी के व्यवहार को अपनी पसंद के मुताबिक कैसे बनाया जा सकता है.
इस सेक्शन में आगे दी गई टेबल में, इस कॉन्फ़िगरेशन के लिए उपलब्ध सेटिंग के बारे में जानें.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_API_MODEL_NAME",
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
// Configure voice activity detection (VAD), interruption handling, and turn coverage.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
realtimeInputConfig: RealtimeInputConfig(
automaticActivityDetection: ActivityDetectionConfig(
startSensitivity: .low,
endSensitivity: .low,
prefixPadding: .milliseconds(20),
silenceDuration: .milliseconds(500)
),
activityHandling: .interrupt,
turnCoverage: .onlyActivity
)
)
)
Kotlin
// ...
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "GEMINI_LIVE_API_MODEL_NAME",
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
// Configure voice activity detection (VAD), interruption handling, and turn coverage.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
realtimeInputConfig = realtimeInputConfig {
automaticActivityDetection = ActivityDetectionConfig.builder()
.setStartSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
.setEndSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
.setPrefixPaddingMs(20)
.setSilenceDurationMs(500)
.build()
activityHandling = RealtimeInputConfig.ActivityHandling.INTERRUPT
turnCoverage = RealtimeInputConfig.TurnCoverage.ONLY_ACTIVITY
}
}
)
Java
// ...
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"GEMINI_LIVE_API_MODEL_NAME",
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
// Configure voice activity detection (VAD), interruption handling, and turn coverage.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
.setRealtimeInputConfig(RealtimeInputConfig.builder()
.setAutomaticActivityDetection(ActivityDetectionConfig.builder()
.setStartSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
.setEndSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
.setPrefixPaddingMs(20)
.setSilenceDurationMs(500)
.build())
.setActivityHandling(RealtimeInputConfig.ActivityHandling.INTERRUPT)
.setTurnCoverage(RealtimeInputConfig.TurnCoverage.ONLY_ACTIVITY)
.build())
.build()
);
Web
Not yet supported for Web apps - check back soon!
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'GEMINI_LIVE_API_MODEL_NAME',
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
// Configure voice activity detection (VAD), interruption handling, and turn coverage.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
realtimeInputConfig: RealtimeInputConfig(
automaticActivityDetection: ActivityDetectionConfig(
startSensitivity: Sensitivity.low,
endSensitivity: Sensitivity.low,
prefixPaddingMS: 20,
silenceDurationMS: 500,
),
activityHandling: ActivityHandling.interrupt,
turnCoverage: TurnCoverage.onlyActivity,
),
),
);
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "GEMINI_LIVE_API_MODEL_NAME",
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
// Configure voice activity detection (VAD), interruption handling, and turn coverage.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
realtimeInputConfig: new RealtimeInputConfig(
automaticActivityDetection: new ActivityDetectionConfig(
startSensitivity: ActivityDetectionConfig.Sensitivity.Low,
endSensitivity: ActivityDetectionConfig.Sensitivity.Low,
prefixPaddingMS: 20,
silenceDurationMS: 500
),
activityHandling: RealtimeInputConfig.ActivityHandling.Interrupt,
turnCoverage: RealtimeInputConfig.TurnCoverage.OnlyActivity
)
)
);
वीएडी के लिए उपलब्ध कॉन्फ़िगरेशन सेटिंग
| सेटिंग | इस्तेमाल की जा सकने वाली वैल्यू | ब्यौरा |
|---|---|---|
गतिविधि का अपने-आप पता लगाने की सुविधा (automaticActivityDetection)
|
||
startSensitivity |
|
इससे यह तय होता है कि जब कोई उपयोगकर्ता बोलना शुरू करता है, तो सर्वर कितनी जल्दी उसका पता लगाता है:
|
endSensitivity |
|
इससे यह तय होता है कि जब कोई उपयोगकर्ता बोलना बंद करता है, तो सर्वर कितनी जल्दी इसका पता लगाता है:
|
prefixPadding |
मिलीसेकंड में अवधि (डिफ़ॉल्ट: कोई नहीं (0 मि॰से॰)) |
इससे यह तय होता है कि बोली का पता चलने से पहले, कितने ऑडियो को शामिल करना है. यह "लुक-बैक" बफ़र यह पक्का करता है कि मॉडल, बोली की शुरुआत को पूरी तरह से कैप्चर करे. इसमें पहला सिलेबल भी शामिल है, जो अक्सर डिटेक्टर के ट्रिगर होने से पहले शुरू होता है.
|
silenceDuration |
मिलीसेकंड में अवधि (डिफ़ॉल्ट: ~800 मिलीसेकंड) |
इससे यह तय होता है कि सर्वर, बोलने की बारी खत्म करने से पहले, कितने समय तक इंतज़ार करे. इससे यह तय होता है कि सिस्टम, वाक्य के बीच में आने वाले नैचुरल पॉज़ को कितनी देर तक सहन कर सकता है. जैसे, सोचने, सांस लेने या क्लॉज़ की सीमाओं के लिए.
|
रुकावट का व्यवहार (activityHandling)
|
||
activityHandling |
|
इससे यह तय होता है कि जवाब जनरेट करते समय, सर्वर उपयोगकर्ता गतिविधि को कैसे मैनेज करता है:
|
कॉन्टेक्स्ट कवरेज (turnCoverage)
|
||
turnCoverage |
|
इससे यह तय होता है कि बातचीत के दौरान, स्ट्रीम किए गए किस इनपुट को कॉन्टेक्स्ट में शामिल किया जाएगा:
|
रुकावटों को मैनेज करना
अगर मॉडल के जवाब जनरेट करने के दौरान, सर्वर को उपयोगकर्ता की आवाज़ का पता चलता है और activityHandling को INTERRUPT (डिफ़ॉल्ट) पर सेट किया गया है, तो इन बातों का ध्यान रखें:
जवाब जनरेट करने की प्रोसेस रद्द हो जाती है: मॉडल तुरंत जवाब देना बंद कर देता है और टूल के लिए किए गए किसी भी कॉल को खारिज कर देता है.
सेशन का इतिहास छोटा कर दिया जाता है: सेशन की कॉन्टेक्स्ट विंडो में सिर्फ़ वह कॉन्टेंट सेव किया जाता है जो रुकावट आने से पहले आपके ऐप्लिकेशन को भेजा जा चुका है.
जवाब जनरेट होने में रुकावट आने का सिग्नल भेजा जाता है: सर्वर, जवाब जनरेट होने में रुकावट आने का मैसेज भेजता है. जैसे, Swift में
wasInterruptedया Kotlin, Java, Web, Flutter, और Unity मेंinterrupted.
आवाज़ का पता लगाने की तकनीक (वीएडी) को बंद करना
बातचीत के दौरान, मैन्युअल तरीके से पूरा कंट्रोल पाने के लिए (जैसे, पुश-टू-टॉक इंटरफ़ेस के लिए), आवाज़ का पता लगाने की सुविधा (वीएडी) को बंद किया जा सकता है. इसके लिए, आपको संवेदनशीलता के पैरामीटर कॉन्फ़िगर करने की ज़रूरत नहीं है.
अपने-आप पहचान होने की सुविधा बंद होने पर, सर्वर अपने-आप बोली की पहचान नहीं करेगा. इसके अलावा, ऑडियो में चुप्पी के आधार पर जवाब ट्रिगर नहीं करेगा. इसके बजाय, आपके ऐप्लिकेशन को सक्रिय सेशन के दौरान, उपयोगकर्ता की गतिविधि की सीमाओं को मैन्युअल तरीके से सिग्नल करना होगा.
1. मॉडल कॉन्फ़िगरेशन में, अपने-आप वीएडी होने की सुविधा बंद करना
|
इस पेज पर, Gemini API की सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, सेवा देने वाली कंपनी के नाम पर क्लिक करें. |
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_API_MODEL_NAME",
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
// Disable automatic voice activity detection (VAD).
realtimeInputConfig: RealtimeInputConfig(
automaticActivityDetection: .disabled()
)
)
)
Kotlin
// ...
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "GEMINI_LIVE_API_MODEL_NAME",
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
// Disable automatic voice activity detection (VAD).
realtimeInputConfig = realtimeInputConfig {
automaticActivityDetection = ActivityDetectionConfig.disabled()
}
}
)
Java
// ...
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"GEMINI_LIVE_API_MODEL_NAME",
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
// Disable automatic voice activity detection (VAD).
.setRealtimeInputConfig(RealtimeInputConfig.builder()
.setAutomaticActivityDetection(ActivityDetectionConfig.disabled())
.build())
.build()
);
Web
Not yet supported for Web apps - check back soon!
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'GEMINI_LIVE_API_MODEL_NAME',
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
// Disable automatic voice activity detection (VAD).
realtimeInputConfig: RealtimeInputConfig(
automaticActivityDetection: ActivityDetectionConfig.disabled(),
),
),
);
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "GEMINI_LIVE_API_MODEL_NAME",
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
// Disable automatic voice activity detection (VAD).
realtimeInputConfig: new RealtimeInputConfig(
automaticActivityDetection: ActivityDetectionConfig.Disabled()
)
)
);
2. उपयोगकर्ता गतिविधि की सीमाओं को मैन्युअल तरीके से सिग्नल करना
अगर वीएडी की सुविधा बंद की जाती है, तो आपके ऐप्लिकेशन को उपयोगकर्ता की हर गतिविधि की सीमाओं को मैन्युअल तरीके से तय करना होगा:
गतिविधि शुरू होने का सिग्नल: ऑडियो डेटा भेजने से पहले
sendStartActivityRealtimeको कॉल करें. उदाहरण के लिए, जब कोई उपयोगकर्ता पुश-टू-टॉक बटन दबाता है.उपयोगकर्ता के इनपुट को स्ट्रीम करना:
sendAudioRealtimeका इस्तेमाल करके, ऑडियो (या वीडियो) डेटा को लगातार स्ट्रीम करें.गतिविधि खत्म होने का सिग्नल: जब उपयोगकर्ता बोलना बंद कर दे, तब
sendStopActivityRealtimeको कॉल करें. उदाहरण के लिए, जब उपयोगकर्ता, पुश-टू-टॉक बटन को रिलीज़ कर दे. इससे पता चलता है कि उपयोगकर्ता ने अपनी बात पूरी कर ली है और मॉडल को जवाब देना शुरू करना चाहिए.
Swift
// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.
// Signal the start of user activity (for example, on push-to-talk button press).
await session.sendStartActivityRealtime()
// Stream user audio data while the user speaks.
await session.sendAudioRealtime(audioData)
// Signal the end of user activity (for example, on button release) to trigger model response.
await session.sendStopActivityRealtime()
Kotlin
// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.
// Signal the start of user activity (for example, on push-to-talk button press).
session.sendStartActivityRealtime()
// Stream user audio data while the user speaks.
session.sendAudioRealtime(audioData)
// Signal the end of user activity (for example, on button release) to trigger model response.
session.sendStopActivityRealtime()
Java
// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.
// Signal the start of user activity (for example, on push-to-talk button press).
session.sendStartActivityRealtime();
// Stream user audio data while the user speaks.
session.sendAudioRealtime(audioData);
// Signal the end of user activity (for example, on button release) to trigger model response.
session.sendStopActivityRealtime();
Web
Not yet supported for Web apps - check back soon!
Dart
// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.
// Signal the start of user activity (for example, on push-to-talk button press).
await session.sendStartActivityRealtime();
// Stream user audio data while the user speaks.
await session.sendAudioRealtime(audioData);
// Signal the end of user activity (for example, on button release) to trigger model response.
await session.sendStopActivityRealtime();
Unity
// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.
// Signal the start of user activity (for example, on push-to-talk button press).
await session.SendStartActivityRealtimeAsync();
// Stream user audio data while the user speaks.
await session.SendAudioRealtimeAsync(audio: audioData);
// Signal the end of user activity (for example, on button release) to trigger model response.
await session.SendStopActivityRealtimeAsync();
सेशन मैनेजमेंट
सेशन से जुड़े इन विषयों के बारे में जानें:
बेहतरीन सुविधाएं, जैसे:
सेशन से जुड़ी सीमाएं. इनमें कनेक्शन और सेशन की अवधि की सीमाएं, सेशन की कॉन्टेक्स्ट विंडो की सीमाएं, और अनुरोध संख्या सीमित करने की सुविधा शामिल है.
सेशन की सीमाओं को मैनेज करने के विकल्प, जिनमें ये शामिल हैं: