حتی با پیادهسازی پایه برای Live API، میتوانید تعاملهای جذاب و قدرتمندی برای کاربران خود ایجاد کنید. درصورت تمایل میتوانید بااستفاده از گزینههای پیکربندی زیر، تجربه را بیشتر سفارشیسازی کنید:
تشخیص فعالیت گفتاری (VAD) (برای مثال، برای مدیریت وقفهها)
زبان و صدای پاسخ
میتوانید مدل را وادار کنید با صدای خاصی پاسخ دهد و بر مدل تأثیر بگذارید تا به زبانهای مختلف پاسخ دهد.
مشخص کردن صدای پاسخ
|
روی ارائهدهنده Gemini API کلیک کنید تا محتوا و کد مختص ارائهدهنده را در این صفحه ببینید. |
Live API از ۳۰ صدای HD ترکیبی مختلف پشتیبانی میکند که هرکدام ویژگیهای متمایزی دارند. با ازهم باز کردن بخش زیر میتوانید فهرست گزینههای صدای پاسخ را مشاهده کنید و نمونههای هر صدا را بشنوید.
اگر صدای پاسخ را مشخص نکنید، صدای پیشفرض 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
}
// ...
تشخیص فعالیت گفتاری (VAD)
تشخیص فعالیت گفتاری (VAD) به مدل امکان میدهد تشخیص دهد که فردی درحال صحبت کردن است. این ویژگی برای ایجاد مکالمههای طبیعی ضروری است، زیرا به شما امکان میدهد هرزمان خواستید صحبت مدل را قطع کنید. «تحویل مجازی برنامهها» بهطور پیشفرض فعال است.
میتوانید رفتار VAD را سفارشیسازی کنید، ازجمله مدیریت وقفهها. همچنین میتوانید «تحویل مجازی برنامهها» خودکار را غیرفعال کنید تا کنترل دستی کامل بر نوبتهای مکالمه داشته باشید (مثلاً برای میانای مکالمه رادیویی).
پیکربندی تشخیص فعالیت گفتاری (VAD)
|
روی ارائهدهنده Gemini API کلیک کنید تا محتوا و کد مختص ارائهدهنده را در این صفحه ببینید. |
مثال زیر نشان میدهد که چگونه میتوانید رفتار VAD را با تنظیم
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 |
مدت به میلیثانیه (پیشفرض: هیچ (۰ میلیثانیه)) |
مقدار صدایی را که باید قبلاز تشخیص گفتار گنجانده شود تعریف میکند. این میانگیر «بازنگری» تضمین میکند که مدل کل شروع گفتار را ضبط میکند، ازجمله اولین هجا که اغلب قبلاز فعال شدن آشکارساز شروع میشود.
|
silenceDuration |
مدتزمان به میلیثانیه (پیشفرض: ~۸۰۰ میلیثانیه) |
تعیین میکند که سرور چه مدت در سکوت منتظر بماند تا نوبت گفتار را پایان دهد. این تنظیم تعیین میکند که سیستم چقدر نسبتبه مکثهای طبیعی در میان جمله (مانند فکر کردن، نفس کشیدن، یا مرزهای بند) تحمل دارد.
|
رفتار وقفه (activityHandling)
|
||
activityHandling |
|
تعریف میکند که سرور چگونه فعالیت کاربر ورودی را هنگام تولید پاسخ مدیریت میکند:
|
پوشش بافت نوبت (turnCoverage)
|
||
turnCoverage |
|
تعیین میکند که چه ورودی جاریای در بافت نوبت مکالمه گنجانده شود:
|
مدیریت وقفهها
اگر سرور گفتار ورودی کاربر را درحین تولید پاسخ توسط مدل تشخیص دهد و activityHandling روی INTERRUPT (پیشفرض) تنظیم شده باشد، از رفتارهای زیر آگاه باشید:
تولید لغو میشود: مدل بلافاصله پاسخ خود را متوقف میکند و هرگونه فراخوانی ابزار معلق را نادیده میگیرد.
سابقه جلسه کوتاه شده است: فقط محتوایی که قبلاً قبلاز وقفه به برنامه شما منتقل شده است در پنجره بافت جلسه حفظ میشود.
سیگنال وقفه ارسال میشود: سرور پیام پاسخی ارسال میکند که نشان میدهد تولید قطع شده است (مانند
wasInterruptedدر Swift یاinterruptedدر Kotlin، Java، Web، Flutter، و Unity).
غیرفعال کردن تشخیص خودکار فعالیت گفتاری (VAD)
برای کنترل کامل دستی بر نوبتهای مکالمه (مثلاً برای رابط «فشار دادن برای صحبت»)، میتوانید تشخیص خودکار فعالیت گفتاری (VAD) را بهجای پیکربندی پارامترهای حساسیت غیرفعال کنید.
وقتی تشخیص خودکار غیرفعال باشد، سرور بهطور خودکار گفتار را تشخیص نمیدهد یا براساس سکوت صوتی پاسخها را راهاندازی نمیکند. درعوض، برنامهتان باید مرزهای فعالیت کاربر را درطول جلسه فعال بهصورت دستی علامتگذاری کند.
۱. غیرفعال کردن VAD خودکار در پیکربندی مدل
|
روی ارائهدهنده 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()
)
)
);
۲. مرزهای فعالیت کاربر را بهصورت دستی علامتگذاری کنید
اگر «تحویل مجازی برنامهها» را غیرفعال کنید، برنامهتان باید بهطور دستی مرزهای هر نوبت فعالیت کاربر را مشخص کند:
شروع فعالیت سیگنال: قبلاز ارسال دادههای صوتی، با
sendStartActivityRealtimeتماس بگیرید (برای مثال، وقتی کاربر دکمه «فشار دادن برای صحبت» را فشار میدهد).جاریسازی ورودی کاربر: جاریسازی مداوم دادههای صوتی (یا ویدیویی) بااستفاده از
sendAudioRealtime.پایان فعالیت سیگنال: وقتی کاربر صحبت کردن را تمام میکند (برای مثال، وقتی کاربر دکمه «فشار برای صحبت» را رها میکند)،
sendStopActivityRealtimeرا فراخوانی کنید. این کار نشاندهنده پایان نوبت کاربر است و پاسخ مدل را راهاندازی میکند.
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();
مدیریت جلسه
با موضوعات زیر که مربوط به جلسهها است آشنا شوید:
قابلیتهای پیشرفته، ازجمله:
محدودیتهای مربوط به جلسه، ازجمله محدودیتهای اتصال و طول جلسه، محدودیتهای پنجره بافت جلسه، و محدودیتهای نرخ.
گزینههایی برای مدیریت محدودیتهای جلسه، ازجمله: