حتی با پیادهسازی اولیهی Live API ، میتوانید تعاملات جذاب و قدرتمندی برای کاربران خود ایجاد کنید. میتوانید با استفاده از گزینههای پیکربندی زیر، تجربه را حتی بیشتر سفارشی کنید:
صدا و زبان پاسخ
شما میتوانید مدل را وادار کنید که با صدای خاصی پاسخ دهد و او را طوری تنظیم کنید که به زبانهای مختلف پاسخ دهد .
صدای پاسخ را مشخص کنید
برای مشاهده محتوا و کد مخصوص ارائهدهنده در این صفحه، روی ارائهدهنده API Gemini خود کلیک کنید. |
Live API از 30 صدای HD سینت سایز شده مختلف پشتیبانی میکند که هر کدام ویژگیهای متمایزی دارند. میتوانید با باز کردن بخش زیر ، فهرستی از گزینههای صدای پاسخ را مشاهده کرده و دموی هر صدا را بشنوید .
اگر صدای پاسخ را مشخص نکنید، صدای پیشفرض Puck است.
| نام صدا | توضیحات | جنسیت | نسخه آزمایشی |
|---|---|---|---|
Achernar | نرم | زن | |
Achird | دوستانه | مرد | |
Algenib | گراولی | مرد | |
Algieba | صاف | مرد | |
Alnilam | شرکت | مرد | |
Aoede | نسیم ملایم | زن | |
Autonoe | روشن | زن | |
Callirrhoe | آسانگیر | زن | |
Charon | آموزنده | مرد | |
Despina | صاف | زن | |
Enceladus | نفس گیر | مرد | |
Erinome | پاک کردن | زن | |
Fenrir | هیجان انگیز | مرد | |
Gacrux | بالغ | زن | |
Iapetus | پاک کردن | مرد | |
Kore | شرکت | زن | |
Laomedeia | خوشبین | زن | |
Leda | جوان | زن | |
Orus | شرکت | مرد | |
Puck | خوشبین | مرد | |
Pulcherrima | به جلو | زن | |
Rasalgethi | آموزنده | مرد | |
Sadachbia | سرزنده | مرد | |
Sadaltager | آگاه | مرد | |
Schedar | حتی | مرد | |
Sulafat | گرم | زن | |
Umbriel | آسانگیر | مرد | |
Vindemiatrix | ملایم | زن | |
Zephyr | روشن | زن | |
Zubenelgenubi | غیررسمی | مرد |
برای مشخص کردن صدای پاسخ، نام صدا را در شیء speechConfig به عنوان بخشی از پیکربندی مدل تنظیم کنید.
سویفت
// ...
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'),
),
);
// ...
وحدت
// ...
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 به طور خودکار زبان مناسب را برای پاسخهای خود انتخاب میکنند.
زبانهای پشتیبانیشده توسط همه مدلهای تولید صدا
| زبان | کد BCP-47 | زبان | کد BCP-47 |
|---|---|---|---|
| عربی (مصری) | ar-EG | آلمانی (آلمان) | د-DE |
| انگلیسی (آمریکایی) | انگلیسی-آمریکایی | اسپانیایی (آمریکایی) | es-US |
| فرانسوی (فرانسه) | fr-FR | هندی (هند) | سلام-ورودی |
| اندونزیایی (اندونزیایی) | شناسه-شناسه | ایتالیایی (ایتالیا) | فناوری اطلاعات |
| ژاپنی (ژاپن) | جا-جی پی | کرهای (کره) | کو-کیآر |
| پرتغالی (برزیل) | پی تی-بی آر | روسی (روسیه) | ru-RU |
| هلندی (هلند) | nl-NL | لهستانی (لهستان) | پی ال-پی ال |
| تایلندی (تایلند) | ام-ام | ترکی (ترکیه) | تر-تیآر |
| ویتنامی (ویتنام) | vi-VN | رومانیایی (رومانیایی) | ro-RO |
| اوکراینی (اوکراین) | انگلستان-آمریکا | بنگالی (بنگلادش) | بی ان-بی دی |
| انگلیسی (هند) | بسته en-IN و hi-IN | مراتی (هند) | آقای-IN |
| تامیل (هند) | تا-این | تلوگو (هند) | te-IN |
زبانهای اضافی پشتیبانیشده توسط مدلهای ۳.x تولیدکننده صدا
| زبان | کد BCP-47 | زبان | کد BCP-47 |
|---|---|---|---|
| آفریکانس | اف | فیلیپینی | فیل |
| آلبانیایی | مربع | فنلاندی | فی |
| امهری | هستم | گالیسیایی | گل |
| ارمنی | های | گرجی | کا |
| آذربایجانی | آز | یونانی | ال |
| باسک | اتحادیه اروپا | گجراتی | گو |
| بلاروسی | باش | کریول هائیتیایی | اچ تی |
| بلغاری | بی جی | عبری | او |
| برمهای | من | مجارستانی | هو |
| کاتالان | حدود | ایسلندی | است |
| سبوانو | سی بی | جاوه ای | جی وی |
| چینی، ماندارین | سی ام ان | کانارا | کن |
| کرواتی | ساعت | کونکانی | کوک |
| چک | سی اس | لائو | لو |
| دانمارکی | دا | لاتین | لا |
| استونیایی | و | لتونیایی | lv |
| لیتوانیایی | آن | لوکزامبورگی | پوند |
| مقدونی | مک | میثیلی | مای |
| مالاگاسیایی | میلیگرم | مالایی | اماس |
| مالایالامی | میلیلیتر | مغولی | من |
| نپالی | نه | نروژی، بوکمال | توجه |
| نروژی، نینورسک | ان | اودیا | یا |
| پشتو | ص | فارسی | فا |
| پنجابی | پا | صربی | اس آر |
| سندی | اس دی | سینهالی | سی |
| اسلواکی | اسک | اسلوونیایی | اس ال |
| سواحیلی | جنوب غربی | سوئدی | اس وی |
| اردو | تو |
اگر میخواهید مدل به زبانی غیر از انگلیسی یا همیشه به یک زبان خاص پاسخ دهد، میتوانید با استفاده از دستورالعملهای سیستمی مانند این مثالها، پاسخهای مدل را تحت تأثیر قرار دهید:
این مدل را تقویت کنید که یک زبان غیر انگلیسی ممکن است مناسب باشد
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.
رونوشتها برای ورودی و خروجی صدا
برای مشاهده محتوا و کد مخصوص ارائهدهنده در این صفحه، روی ارائهدهنده API Gemini خود کلیک کنید. |
به عنوان بخشی از پاسخ مدل، میتوانید رونوشتهایی از ورودی صوتی و پاسخ صوتی مدل را دریافت کنید. شما این پیکربندی را به عنوان بخشی از پیکربندی مدل تنظیم میکنید.
برای رونویسی از ورودی صدا،
inputAudioTranscriptionرا اضافه کنید.برای رونویسی پاسخ صوتی مدل،
outputAudioTranscriptionرا اضافه کنید.
به موارد زیر توجه کنید:
میتوانید مدل را طوری پیکربندی کنید که رونوشتهایی از هر دو ورودی و خروجی را برگرداند (همانطور که در مثال زیر نشان داده شده است)، یا میتوانید آن را طوری پیکربندی کنید که فقط یکی از آنها را برگرداند.
متنها به همراه صدا پخش میشوند، بنابراین بهتر است آنها را مانند بخشهای متنی در هر نوبت جمعآوری کنید.
زبان رونویسی از ورودی صوتی و پاسخ صوتی مدل استنباط میشود.
سویفت
// ...
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');
}
}
// ...
وحدت
// ...
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
}
// ...
تشخیص فعالیت صوتی (VAD)
این مدل به طور خودکار تشخیص فعالیت صوتی (VAD) را روی یک جریان ورودی صوتی پیوسته انجام میدهد. VAD به طور پیشفرض فعال است.
مدیریت جلسه
درباره مباحث مرتبط با جلسات زیر اطلاعات کسب کنید:
قابلیتهای پیشرفته، از جمله:
محدودیتهای مربوط به جلسه ، شامل محدودیتهای اتصال و طول جلسه، محدودیتهای پنجرهی زمینهی جلسه و محدودیتهای سرعت.
گزینههایی برای مدیریت محدودیتهای جلسه، از جمله: