Gemini टीटीएस मॉडल से, टेक्स्ट प्रॉम्प्ट के आधार पर स्पीच (ऑडियो) आउटपुट जनरेट करने के लिए कहा जा सकता है. Firebase AI Logic का इस्तेमाल करते समय, सीधे अपने ऐप्लिकेशन से यह अनुरोध किया जा सकता है.
लिखे गए शब्दों को सुनने की सुविधा (टीटीएस) को कंट्रोल किया जा सकता है. इसका मतलब है कि आपको ठीक वही टेक्स्ट देना होगा जिसे बोली में बदलना है. इसके अलावा, ऑडियो आउटपुट की स्टाइल, लहजे, गति, और टोन को तय करने के लिए, अपने प्रॉम्प्ट में सामान्य भाषा का इस्तेमाल किया जा सकता है. टीटीएस को ट्रांसक्रिप्शन (बोली को टेक्स्ट में बदलना) की सुविधा के उलट माना जा सकता है.
इस सुविधा का इस्तेमाल, Gemini -tts मॉडल में से किसी भी मॉडल के साथ किया जा सकता है. ये मॉडल, अच्छी क्वालिटी और कम समय में स्पीच जनरेट करने के लिए ऑप्टिमाइज़ किए गए हैं.
इस सुविधा की मदद से, ये काम किए जा सकते हैं:
इंटरैक्टिव तरीके से कहानी सुनाना: ऑडियो बुक या रोल-प्लेइंग गेम बनाएं. इनमें मॉडल, अलग-अलग किरदारों के लिए आवाज़ बदलता है या कहानी के हिसाब से अपनी टोन बदलता है. जैसे, सस्पेंस के दौरान फुसफुसाना या किसी चुटकुले पर हंसना.
भाषा सीखना: उच्चारण से जुड़ी गाइड बनाएं. इनमें टेक्स्ट को किसी खास क्षेत्र के लहज़े में या धीमी गति से पढ़ा जा सकता है, ताकि सीखने वाले लोग मुश्किल शब्दों का उच्चारण कर सकें.
कॉन्टेक्स्ट के हिसाब से कॉन्टेंट पढ़ने की सुविधा: इस सुविधा की मदद से, खबरों, रेसिपी या ब्लॉग पोस्ट को बोलकर सुनाया जा सकता है. इसके लिए, आवाज़ और भावनात्मक टोन का इस्तेमाल किया जाता है, जो कॉन्टेंट के हिसाब से होती है. जैसे, ब्रेकिंग न्यूज़ के लिए गंभीर टोन या खाना बनाने के निर्देशों के लिए, प्यार भरी और धैर्य वाली टोन.
इस गाइड में, एक या एक से ज़्यादा स्पीकर की मदद से, टेक्स्ट इनपुट से स्पीच जनरेट करने का तरीका बताया गया है. साथ ही, इसमें ऑडियो रिस्पॉन्स को स्ट्रीम करने का तरीका भी बताया गया है.
एक स्पीकर के लिए कोड पर जाएं एक से ज़्यादा स्पीकर के लिए कोड पर जाएं स्ट्रीम किए गए जवाबों के लिए कोड पर जाएं
TTS और Live API के बीच तुलना
लिखे हुए शब्दों को बोली में बदलने वाले (टीटीएस) मॉडल और Live API मॉडल, दोनों ही कम समय में काम करते हैं. ये ऐसे मॉडल हैं जो बोली जनरेट करते हैं. इन्हें जवाब देने के लिए अलग-अलग आवाज़ों और भाषाओं के लिए कॉन्फ़िगर किया जा सकता है. हालांकि, इनका इस्तेमाल अलग-अलग कामों के लिए किया जाता है.
लिखे गए शब्दों को सुनने की सुविधा (टीटीएस), अनुरोध-जवाब के बीच होने वाली एकतरफ़ा बातचीत है. इसमें टेक्स्ट इनपुट के तौर पर दिया जाता है और ऑडियो आउटपुट के तौर पर मिलता है. इसे उन स्थितियों के लिए बनाया गया है जिनमें दिए गए टेक्स्ट को सटीक तरीके से सुनाने की ज़रूरत होती है. साथ ही, स्टाइल और आवाज़ को बारीकी से कंट्रोल करने की ज़रूरत होती है. जैसे, पॉडकास्ट में सुनाई जाने वाली कहानी, ऑडियो बुक या लेख को तेज़ आवाज़ में पढ़ना.
Live API जनरेशन में, रीयल-टाइम में बोलकर बातचीत करने (बोलकर इनपुट देना, बोलकर आउटपुट पाना) के लिए, दोनों दिशाओं में स्ट्रीमिंग की सुविधा उपलब्ध है. यह डाइनैमिक कॉन्टेक्स्ट में बातचीत करने के लिए सबसे अच्छा है. इसमें मॉडल यह तय करता है कि जवाब देने के लिए कौनसी स्पीच का इस्तेमाल करना है. ध्यान दें कि Live APIके नए मॉडल में, वीडियो और इमेज को भी इनपुट के तौर पर इस्तेमाल किया जा सकता है.
शुरू करने से पहले
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
अगर आपने अब तक शुरुआती गाइड नहीं पढ़ी है, तो इसे पढ़ें. इसमें बताया गया है कि Firebase प्रोजेक्ट कैसे सेट अप करें, अपने ऐप्लिकेशन को Firebase से कैसे कनेक्ट करें, एसडीके कैसे जोड़ें, चुने गए Gemini API प्रोवाइडर के लिए बैकएंड सेवा को कैसे शुरू करें, और GenerativeModel इंस्टेंस कैसे बनाएं.
अपने प्रॉम्प्ट को टेस्ट करने और उनमें सुधार करने के लिए, हमारा सुझाव है कि आप Google AI Studio का इस्तेमाल करें.
इस सुविधा के साथ काम करने वाले मॉडल
gemini-3.1-flash-tts-preview
टेक्स्ट को बोली में बदलना
Gemini टीटीएस मॉडल का इस्तेमाल करके, दिए गए टेक्स्ट से स्पीच जनरेट की जा सकती है.
किसी एक स्पीकर की आवाज़ में स्पीच जनरेट करना
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिया गया तरीका अपनाकर, अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करें. उस सेक्शन में, आपको अपनी चुनी गई Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
मॉडल को एक ही आवाज़ में ऑडियो आउटपुट देने के लिए कॉन्फ़िगर किया जा सकता है.
अपनी GenerationConfig में यह जानकारी शामिल करें:
responseModalitiesकोAUDIOपर सेट करें.SpeechConfigको इन सेटिंग के साथ कॉन्फ़िगर करें:(ज़रूरी है) जवाब देने वाली आवाज़ का नाम (उदाहरण के लिए,
Kore)(ज़रूरी नहीं) भाषा कोड.
अगर आपने कोई भाषा नहीं चुनी है, तो Gemini टीटीएस मॉडल, प्रॉम्ट में भाषा की पहचान अपने-आप कर सकते हैं.
टेक्स्ट प्रॉम्प्ट का इस्तेमाल करके generateContent को कॉल करें. मॉडल, जवाब के हिस्सों में रॉ पीसीएम ऑडियो डेटा दिखाता है.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
let config = GenerationConfig(
responseModalities: [.audio],
speechConfig: SpeechConfig(voiceName: "Kore", languageCode: "en-US")
)
// Create a `GenerativeModel` instance with a model that supports speech generation.
let model = ai.generativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
)
// Provide a text prompt.
let prompt = "Say cheerfully: Have a wonderful day!"
// Call `generateContent` to generate the speech output based on your text prompt.
let response = try await model.generateContent(prompt)
// Extract the audio data and handle it for downstream use. For example:
for part in response.inlineDataParts {
let data = part.data // Raw PCM audio bytes (24kHz, 1 channel, 16-bit)
let mimeType = part.mimeType // for example: "audio/pcm"
print("Received audio data with MIME type: \(mimeType)")
// To play back raw PCM audio bytes, you'll need to write your own `playRawPcm` function.
playRawPcm(data: data)
}
Kotlin
Kotlin के लिए, इस एसडीके में मौजूद तरीके सस्पेंड फ़ंक्शन हैं. इन्हें कोरूटीन स्कोप से कॉल करना ज़रूरी है.
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
val config = generationConfig {
responseModalities = listOf(ResponseModality.AUDIO)
speechConfig = SpeechConfig(
voice = Voice("Kore"),
languageCode = "en-US"
)
}
// Initialize the Gemini Developer API backend service.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3.1-flash-tts-preview",
generationConfig = config
)
// Provide a text prompt.
val prompt = "Say cheerfully: Have a wonderful day!"
// Call `generateContent` to generate the speech output based on your text prompt.
val response = model.generateContent(prompt)
// Extract the audio data and handle it for downstream use. For example:
val part = response.candidates.firstOrNull()?.content?.parts?.firstOrNull()
if (part is InlineDataPart) {
val pcmData = part.inlineData // Raw PCM bytes (24kHz, 1 channel, 16-bit)
val mimeType = part.mimeType // for example: "audio/pcm"
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData)
}
Java
Java के लिए, इस एसडीके में स्ट्रीमिंग के तरीके, Reactive Streams लाइब्रेरी सेPublisher टाइप दिखाते हैं.
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
GenerationConfig config = new GenerationConfig.Builder()
.setResponseModalities(Collections.singletonList(ResponseModality.AUDIO))
.setSpeechConfig(new SpeechConfig(new Voice("Kore"), "en-US"))
.build();
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-3.1-flash-tts-preview", config);
// Use the GenerativeModelFutures Java compatibility layer.
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt.
String prompt = "Say cheerfully: Have a wonderful day!";
Content content = new Content.Builder().addText(prompt).build();
Executor executor = Executors.newSingleThreadExecutor();
// Call `generateContent` to generate the speech output based on your text prompt.
// Extract the audio data and handle it for downstream use.
ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
Part part = result.getCandidates().get(0).getContent().getParts().get(0);
if (part instanceof InlineDataPart) {
byte[] pcmData = ((InlineDataPart) part).getInlineData();
String mimeType = ((InlineDataPart) part).getMimeType();
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData);
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace with your app's Firebase configuration
const firebaseConfig = { /* ... */ };
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
const generationConfig = {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: { prebuiltVoiceConfig: { voiceName: "Kore" } },
languageCode: "en-US"
}
};
// Create a `GenerativeModel` instance with a model that supports speech generation.
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-tts-preview",
generationConfig
});
// Provide a text prompt.
const prompt = "Say cheerfully: Have a wonderful day!";
// Call `generateContent` to generate the speech output based on your text prompt.
const result = await model.generateContent(prompt);
const inlineDataParts = result.response.inlineDataParts();
// Extract the audio data and handle it for downstream use. For example:
if (inlineDataParts?.[0]) {
const pcmBase64 = inlineDataParts[0].inlineData.data;
// Decode base64 to ArrayBuffer
const pcmBuffer = Uint8Array.from(atob(pcmBase64), c => c.charCodeAt(0)).buffer;
// To play back a PCM buffer, you'll need to write your own `playAudio` function.
playAudio(pcmBuffer);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
final config = GenerationConfig(
responseModalities: [ResponseModality.audio],
speechConfig: SpeechConfig(voiceName: 'Kore', languageCode: 'en-US'),
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-tts-preview',
config: config,
);
// Provide a text prompt.
final prompt = 'Say cheerfully: Have a wonderful day!';
// Call `generateContent` to generate the speech output based on your text prompt.
final response = await model.generateContent([Content.text(prompt)]);
// Extract the audio data and handle it for downstream use. For example:
final part = response.candidates.first.content.parts.first;
if (part is InlineDataPart && part.mimeType.startsWith('audio/')) {
final Uint8List pcmData = part.bytes; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// To play back PCM audio data, you'll need to write your own `playAudio` function.
await playAudio(pcmData);
}
Unity
using Firebase.AI;
// Set `responseModalities` to include `Audio`.
// Configure a `SpeechConfig` with your chosen voice name and language code.
var config = new GenerationConfig(
responseModalities: new System.Collections.Generic.List<ResponseModality> { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("Kore", "en-US")
);
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports speech generation.
var model = ai.GetGenerativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
);
// Provide a text prompt.
var prompt = "Say cheerfully: Have a wonderful day!";
// Call `GenerateContentAsync` to generate the speech output based on your text prompt.
var response = await model.GenerateContentAsync(prompt);
// Extract the audio data and handle it for downstream use. For example:
if (response.Candidates.Count > 0) {
foreach (var part in response.Candidates[0].Content.Parts) {
if (part is ModelContent.InlineDataPart inlineData) {
byte[] pcmData = inlineData.Data; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData);
}
}
}
एक से ज़्यादा लोगों की आवाज़ में स्पीच जनरेट करना
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिया गया तरीका अपनाकर, अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करें. उस सेक्शन में, आपको अपनी चुनी गई Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
मॉडल को कॉन्फ़िगर करके, टेक्स्ट में मौजूद अलग-अलग स्पीकर के लिए अलग-अलग आवाज़ों का इस्तेमाल किया जा सकता है. यह सुविधा, डायलॉग या बातचीत के लिए ऑडियो जनरेट करने में मददगार होती है.
एक
MultiSpeakerVoiceConfigबनाएं, जो स्पीकर के नामों (जिन्हें आपको अपने प्रॉम्प्ट में इस्तेमाल करना है) को खास जवाब देने वाले वॉइस नेम (उदाहरण के लिए,Kore) से मैप करता हो.एक से ज़्यादा स्पीकर वाले कॉन्फ़िगरेशन में, सिर्फ़ दो स्पीकर इस्तेमाल किए जा सकते हैं.
अपनी
GenerationConfigमें यह जानकारी शामिल करें:responseModalitiesकोAUDIOपर सेट करें.SpeechConfigको इन सेटिंग के साथ कॉन्फ़िगर करें:(ज़रूरी है) अपना
MultiSpeakerVoiceConfigपास करें.(ज़रूरी नहीं) भाषा कोड.
अगर आपने कोई भाषा नहीं चुनी है, तो Gemini टीटीएस मॉडल, प्रॉम्ट में भाषा की पहचान अपने-आप कर सकते हैं.
अपने प्रॉम्प्ट में, यह बताएं कि कौन बोल रहा है. इसके लिए, स्पीकर के नामों को प्रीफ़िक्स के तौर पर इस्तेमाल करें. उदाहरण के लिए,
Joe: Hello. Jane: Hi..
टेक्स्ट प्रॉम्प्ट का इस्तेमाल करके generateContent को कॉल करें. मॉडल, जवाब के हिस्सों में रॉ पीसीएम ऑडियो डेटा दिखाता है.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
let multiSpeechConfig = SpeechConfig(
multiSpeakerVoiceConfig: MultiSpeakerVoiceConfig(
speakerVoiceConfigs: [
SpeakerVoiceConfig(speaker: "Joe", voiceName: "Puck"),
SpeakerVoiceConfig(speaker: "Jane", voiceName: "Kore")
]
),
languageCode: "en-US"
)
// Set `responseModalities` to include `audio`.
let config = GenerationConfig(
responseModalities: [.audio],
speechConfig: multiSpeechConfig
)
// Create a `GenerativeModel` instance with a model that supports speech generation.
let model = ai.generativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
)
// Provide a text prompt that includes the names of the speakers.
let prompt = """
Joe: How's it going today Jane?
Jane: Not too bad, how about you?
"""
// Call `generateContent` to generate the speech output based on your text prompt.
let response = try await model.generateContent(prompt)
// Extract the audio data and handle it for downstream use. For example:
for part in response.inlineDataParts {
let data = part.data // Raw PCM audio bytes (24kHz, 1 channel, 16-bit)
let mimeType = part.mimeType // for example: "audio/pcm"
print("Received audio data with MIME type: \(mimeType)")
// To play back raw PCM audio bytes, you'll need to write your own `playRawPcm` function.
playRawPcm(data: data)
}
Kotlin
Kotlin के लिए, इस एसडीके में मौजूद तरीके सस्पेंड फ़ंक्शन हैं. इन्हें कोरूटीन स्कोप से कॉल करना ज़रूरी है.
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
val multiSpeechConfig = SpeechConfig(
multiSpeakerVoiceConfig = MultiSpeakerVoiceConfig(
speakerVoiceConfigs = listOf(
SpeakerVoiceConfig(speaker = "Joe", voice = Voice("Puck")),
SpeakerVoiceConfig(speaker = "Jane", voice = Voice("Kore"))
)
),
languageCode = "en-US"
)
// Set `responseModalities` to include `AUDIO`.
val config = generationConfig {
responseModalities = listOf(ResponseModality.AUDIO)
speechConfig = multiSpeechConfig
}
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3.1-flash-tts-preview",
generationConfig = config
)
// Provide a text prompt that includes the names of the speakers.
val prompt = """
Joe: How's it going today Jane?
Jane: Not too bad, how about you?
"""
// Call `generateContent` to generate the speech output based on your text prompt.
val response = model.generateContent(prompt)
// Extract the audio data and handle it for downstream use. For example:
val part = response.candidates.firstOrNull()?.content?.parts?.firstOrNull()
if (part is InlineDataPart) {
val pcmData = part.inlineData // Raw PCM bytes (24kHz, 1 channel, 16-bit)
val mimeType = part.mimeType // for example: "audio/pcm"
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData)
}
Java
Java के लिए, इस एसडीके में स्ट्रीमिंग के तरीके, Reactive Streams लाइब्रेरी सेPublisher टाइप दिखाते हैं.
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
MultiSpeakerVoiceConfig multiSpeakerVoiceConfig = new MultiSpeakerVoiceConfig(
Arrays.asList(
new SpeakerVoiceConfig("Joe", new Voice("Puck")),
new SpeakerVoiceConfig("Jane", new Voice("Kore"))
)
);
SpeechConfig multiSpeechConfig = new SpeechConfig(multiSpeakerVoiceConfig);
// Set `responseModalities` to include `AUDIO`.
GenerationConfig config = new GenerationConfig.Builder()
.setResponseModalities(Collections.singletonList(ResponseModality.AUDIO))
.setSpeechConfig(multiSpeechConfig)
.build();
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-3.1-flash-tts-preview", config);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt that includes the names of the speakers.
String prompt = "Joe: How's it going today Jane?\nJane: Not too bad, how about you?";
Content content = new Content.Builder().addText(prompt).build();
Executor executor = Executors.newSingleThreadExecutor();
// Call `generateContent` to generate the speech output based on your text prompt.
// Extract the audio data and handle it for downstream use.
ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
Part part = result.getCandidates().get(0).getContent().getParts().get(0);
if (part instanceof InlineDataPart) {
byte[] pcmData = ((InlineDataPart) part).getInlineData(); // Raw PCM bytes (24kHz, 1 channel, 16-bit)
String mimeType = ((InlineDataPart) part).getMimeType(); // for example: "audio/pcm"
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData);
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace with your app's Firebase configuration
const firebaseConfig = { /* ... */ };
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
const generationConfig = {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
multiSpeakerVoiceConfig: {
speakerVoiceConfigs: [
{ speaker: "Joe", voiceConfig: { prebuiltVoiceConfig: { voiceName: "Puck" } } },
{ speaker: "Jane", voiceConfig: { prebuiltVoiceConfig: { voiceName: "Kore" } } }
]
},
languageCode: "en-US"
}
};
// Create a `GenerativeModel` instance with a model that supports speech generation.
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-tts-preview",
generationConfig
});
// Provide a text prompt that includes the names of the speakers.
const prompt = `
Joe: How's it going today Jane?
Jane: Not too bad, how about you?
`;
// Call `generateContent` to generate the speech output based on your text prompt.
const result = await model.generateContent(prompt);
const inlineDataParts = result.response.inlineDataParts();
// Extract the audio data and handle it for downstream use. For example:
if (inlineDataParts?.[0]) {
const pcmBase64 = inlineDataParts[0].inlineData.data; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
const pcmBuffer = Uint8Array.from(atob(pcmBase64), c => c.charCodeAt(0)).buffer;
// To play back a PCM buffer, you'll need to write your own `playAudio` function.
playAudio(pcmBuffer);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
final multiSpeechConfig = SpeechConfig.multiSpeaker(
multiSpeakerVoiceConfig: MultiSpeakerVoiceConfig(
speakerVoiceConfigs: [
SpeakerVoiceConfig(speaker: 'Joe', voiceName: 'Puck'),
SpeakerVoiceConfig(speaker: 'Jane', voiceName: 'Kore'),
],
),
languageCode: 'en-US',
);
// Set `responseModalities` to include `audio`.
final config = GenerationConfig(
responseModalities: [ResponseModality.audio],
speechConfig: multiSpeechConfig,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-tts-preview',
config: config,
);
// Provide a text prompt that includes the names of the speakers.
final prompt = '''
Joe: How's it going today Jane?
Jane: Not too bad, how about you?
''';
// Call `generateContent` to generate the speech output based on your text prompt.
final response = await model.generateContent([Content.text(prompt)]);
// Extract the audio data and handle it for downstream use. For example:
final part = response.candidates.first.content.parts.first;
if (part is InlineDataPart && part.mimeType.startsWith('audio/')) {
final Uint8List pcmData = part.bytes; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// To play back PCM audio data, you'll need to write your own `playAudio` function.
await playAudio(pcmData);
}
Unity
using Firebase.AI;
// Configure a `SpeechConfig` for multiple speakers, assigning a voice to each speaker.
var multiSpeakerVoiceConfig = new MultiSpeakerVoiceConfig(
new System.Collections.Generic.List<SpeakerVoiceConfig> {
SpeakerVoiceConfig.UsePrebuiltVoice("Joe", "Puck"),
SpeakerVoiceConfig.UsePrebuiltVoice("Jane", "Kore")
}
);
var multiSpeechConfig = SpeechConfig.UseMultiSpeakerVoice(multiSpeakerVoiceConfig);
// Set `responseModalities` to include `Audio`.
var config = new GenerationConfig(
responseModalities: new System.Collections.Generic.List<ResponseModality> { ResponseModality.Audio },
speechConfig: multiSpeechConfig
);
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports speech generation.
var model = ai.GetGenerativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
);
// Provide a text prompt that includes the names of the speakers.
var prompt = "Joe: How's it going today Jane?\nJane: Not too bad, how about you?";
// Call `GenerateContentAsync` to generate the speech output based on your text prompt.
var response = await model.GenerateContentAsync(prompt);
// Extract the audio data and handle it for downstream use. For example:
if (response.Candidates.Count > 0) {
foreach (var part in response.Candidates[0].Content.Parts) {
if (part is ModelContent.InlineDataPart inlineData) {
byte[] pcmData = inlineData.Data; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// To play back PCM audio data, you'll need to write your own `playAudio` function.
playAudio(pcmData);
}
}
}
जवाब को स्ट्रीम करना
|
इस सैंपल को आज़माने से पहले, इस गाइड के शुरू करने से पहले सेक्शन में दिया गया तरीका अपनाकर, अपना प्रोजेक्ट और ऐप्लिकेशन सेट अप करें. उस सेक्शन में, आपको अपनी चुनी गई Gemini API सेवा देने वाली कंपनी के लिए एक बटन पर क्लिक करना होगा, ताकि आपको इस पेज पर सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट दिखे. |
ऑडियो फ़ाइल के पूरी तरह से जनरेट होने का इंतज़ार करने के बजाय, जनरेट होते ही ऑडियो रिस्पॉन्स को स्ट्रीम करके, तेज़ी से इंटरैक्शन किया जा सकता है और लेटेंसी को कम किया जा सकता है.
जनरेट की गई स्पीच को स्ट्रीम करने की सुविधा, सिंगल-स्पीकर और मल्टी-स्पीकर, दोनों कॉन्फ़िगरेशन के लिए उपलब्ध है. यह सुविधा सिर्फ़ Gemini 3.x TTS मॉडल इस्तेमाल करने पर काम करती है.
बोलकर दिए गए जवाब को स्ट्रीम करने के लिए, generateContent के बजाय generateContentStream को कॉल करें. साथ ही, जवाब के हिस्सों को मिलते ही हैंडल करें. यहां दिए गए उदाहरणों में, एक स्पीकर से मिलने वाले जवाब को स्ट्रीम करने का तरीका बताया गया है:
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Set `responseModalities` to include `audio`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
let config = GenerationConfig(
responseModalities: [.audio],
speechConfig: SpeechConfig(voiceName: "Kore")
)
// Create a `GenerativeModel` instance with a model that supports speech generation.
let model = ai.generativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
)
// Provide a text prompt.
let prompt = "Tell me a story about a brave knight."
// Call `generateContentStream` to generate the speech output stream based on your text prompt.
let responseStream = try model.generateContentStream(prompt)
// Extract the audio data and handle it for downstream use. For example:
for try await chunk in responseStream {
for part in chunk.inlineDataParts {
let data = part.data // Raw PCM audio bytes (24kHz, 1 channel, 16-bit)
let mimeType = part.mimeType // for example: "audio/pcm"
// Append the audio chunk to your audio queue/buffer for playback.
appendAudioChunk(data)
}
}
Kotlin
Kotlin के लिए, इस एसडीके में मौजूद तरीके सस्पेंड फ़ंक्शन हैं. इन्हें कोरूटीन स्कोप से कॉल करना ज़रूरी है.
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
val config = generationConfig {
responseModalities = listOf(ResponseModality.AUDIO)
speechConfig = SpeechConfig(voice = Voice("Kore"))
}
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3.1-flash-tts-preview",
generationConfig = config
)
// Provide a text prompt.
val prompt = "Tell me a story about a brave knight."
// Call `generateContentStream` to generate the speech output stream based on your text prompt.
// Extract the audio data and handle it for downstream use.
model.generateContentStream(prompt).collect { chunk ->
val part = chunk.candidates.firstOrNull()?.content?.parts?.firstOrNull()
if (part is InlineDataPart) {
val pcmChunk = part.inlineData // Raw PCM bytes (24kHz, 1 channel, 16-bit)
val mimeType = part.mimeType // for example: "audio/pcm"
// Append the audio chunk to your audio queue/buffer for playback.
appendAudioChunk(pcmChunk)
}
}
Java
Java के लिए, इस एसडीके में स्ट्रीमिंग के तरीके, Reactive Streams लाइब्रेरी सेPublisher टाइप दिखाते हैं.
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
GenerationConfig config = new GenerationConfig.Builder()
.setResponseModalities(Collections.singletonList(ResponseModality.AUDIO))
.setSpeechConfig(new SpeechConfig(new Voice("Kore")))
.build();
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-3.1-flash-tts-preview", config);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt.
String prompt = "Tell me a story about a brave knight.";
Content content = new Content.Builder().addText(prompt).build();
// Call `generateContentStream` to generate the speech output stream based on your text prompt.
Publisher<GenerateContentResponse> streamingResponse =
model.generateContentStream(content);
// Extract the audio data and handle it for downstream use.
streamingResponse.subscribe(new Subscriber<GenerateContentResponse>() {
@Override
public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
@Override
public void onNext(GenerateContentResponse chunk) {
Part part = chunk.getCandidates().get(0).getContent().getParts().get(0);
if (part instanceof InlineDataPart) {
byte[] pcmChunk = ((InlineDataPart) part).getInlineData(); // Raw PCM bytes (24kHz, 1 channel, 16-bit)
String mimeType = ((InlineDataPart) part).getMimeType(); // for example: "audio/pcm"
// Append the audio chunk to your audio queue/buffer for playback.
appendAudioChunk(pcmChunk);
}
}
@Override
public void onComplete() {
// Audio stream complete.
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
});
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace with your app's Firebase configuration
const firebaseConfig = { /* ... */ };
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set `responseModalities` to include `AUDIO`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
const generationConfig = {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: { prebuiltVoiceConfig: { voiceName: "Kore" } }
}
};
// Create a `GenerativeModel` instance with a model that supports speech generation.
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-tts-preview",
generationConfig
});
// Provide a text prompt.
const prompt = "Tell me a story about a brave knight.";
// Call `generateContentStream` to generate the speech output stream based on your text prompt.
const result = await model.generateContentStream(prompt);
// Extract the audio data and handle it for downstream use. For example:
const playbackQueue = [];
for await (const chunk of result.stream) {
const inlineDataParts = chunk.inlineDataParts();
if (inlineDataParts?.[0]) {
const pcmBase64 = inlineDataParts[0].inlineData.data; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
const pcmBuffer = Uint8Array.from(atob(pcmBase64), c => c.charCodeAt(0)).buffer;
// Append the audio chunk to your audio queue/buffer for playback.
playbackQueue.push(pcmBuffer);
}
}
// To play back an array of PCM buffers in sequence, you'll need to write your own `processPlaybackQueue` function.
processPlaybackQueue(playbackQueue);
Dart
import 'package:firebase_ai/firebase_ai.dart';
// Set `responseModalities` to include `audio`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
final config = GenerationConfig(
responseModalities: [ResponseModality.audio],
speechConfig: SpeechConfig(voiceName: 'Kore'),
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports speech generation.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-tts-preview',
config: config,
);
// Provide a text prompt.
final prompt = 'Tell me a story about a brave knight.';
// Call `generateContentStream` to generate the speech output stream based on your text prompt.
final responseStream = model.generateContentStream([Content.text(prompt)]);
// Extract the audio data and handle it for downstream use. For example:
await for (final chunk in responseStream) {
final part = chunk.candidates.first.content.parts.first;
if (part is InlineDataPart && part.mimeType.startsWith('audio/')) {
final Uint8List pcmChunk = part.bytes; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// Append the audio chunk to your audio queue/buffer for playback.
appendAudioChunk(pcmChunk);
}
}
Unity
using System.Collections.Generic;
using System.Linq;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Set `ResponseModalities` to include `Audio`.
// Configure a `SpeechConfig` with your chosen voice name (and optionally a language code).
var config = new GenerationConfig(
responseModalities: new List<ResponseModality> { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("Kore")
);
// Create a `GenerativeModel` instance with a model that supports speech generation.
var model = ai.GetGenerativeModel(
modelName: "gemini-3.1-flash-tts-preview",
generationConfig: config
);
// Provide a text prompt.
var prompt = "Tell me a story about a brave knight.";
// Call `GenerateContentStreamAsync` to generate the speech output stream based on your text prompt.
var responseStream = model.GenerateContentStreamAsync(prompt);
// Extract the audio data and handle it for downstream use. For example:
await foreach (var response in responseStream)
{
var audioParts = response.Candidates.FirstOrDefault().Content.Parts
.OfType<ModelContent.InlineDataPart>();
foreach (var part in audioParts)
{
byte[] pcmChunk = part.Data; // Raw PCM bytes (24kHz, 1 channel, 16-bit)
// Append the audio chunk to your audio queue/buffer for playback.
appendAudioChunk(pcmChunk);
}
}
प्रॉम्प्ट की मदद से, बोलकर जवाब देने की सुविधा को कंट्रोल करना
प्रॉम्प्ट देने की खास तकनीकों का इस्तेमाल करके, जनरेट की गई स्पीच की टोन, गति, और स्टाइल को बदला जा सकता है.
प्रॉम्प्ट स्ट्रक्चर और ऑडियो टैग के बारे में यहां दिए गए उप-अनुभागों में, सामान्य दिशा-निर्देश दिए गए हैं. ज़्यादा जानकारी के लिए, इस प्रॉम्प्ट के लिए गाइड देखें.
प्रॉम्प्ट का स्ट्रक्चर
सबसे बेहतर नतीजे पाने के लिए, अपने प्रॉम्प्ट को इन कॉम्पोनेंट के साथ स्ट्रक्चर करें:
Audio Profile: स्पीकर की पर्सोना, मुख्य पहचान, और आर्केटाइप के बारे में बताएं (उदाहरण के लिए,A warm, professional narrator).Scene: माहौल और इमोशनल वाइब के बारे में बताएं. उदाहरण के लिए,In a quiet libraryयाAmidst a noisy crowd.Director's Notes: भावना, गति, स्टाइल, और लहजे के बारे में बताएं. उदाहरण के लिए,Speak slowly and with mystery.Sample Context: मॉडल को शुरुआती जानकारी दें. उदाहरण के लिए,The speaker is greeting a close friend.ट्रांसक्रिप्ट: यह वह टेक्स्ट है जिसे सुनाया जाना है. बेहतर परफ़ॉर्मेंस के लिए, पक्का करें कि टेक्स्ट का टोन और कॉन्टेक्स्ट, आवाज़ की प्रोफ़ाइल और डायरेक्टर के नोट के मुताबिक हो.
प्रॉम्प्ट का उदाहरण:
[Audio Profile: A young, energetic voice]
[Scene: A lively sports broadcast]
[Director's Notes: Speak fast, with high energy and excitement]
[Sample Context: The game just ended with a last-second touchdown]
Welcome back fans! What an incredible game we're witnessing today!
ऑडियो टैग
मॉडल की परफ़ॉर्मेंस को बेहतर बनाने के लिए, टेक्स्ट प्रॉम्प्ट में सीधे तौर पर फ़ॉर्मैटिंग टैग डाले जा सकते हैं.
ऑडियो टैग सिर्फ़ Gemini 3.x TTS मॉडल का इस्तेमाल करने पर काम करते हैं.
आम तौर पर इस्तेमाल किए जाने वाले टैग में ये शामिल हैं:
[whispers]: धीरे बोलने के लिए[laughs]: हंसने की आवाज़ जोड़ने के लिए[giggles]: हंसी की आवाज़ जोड़ने के लिए[sighs]: आह भरने के लिए[gasp]: 'आश्चर्य से मुंह खुला रह जाना' वाला इमोजी जोड़ने के लिए[shouting]: ज़ोर से बोलें[excited]: उत्साह के साथ बोलने के लिए[serious]: गंभीरता से बात करने के लिए[sighs whispers]: एक से ज़्यादा भावनाएं (टैग को आपस में जोड़ा जा सकता है)
ऑडियो टैग का उपयोग करते समय निम्नलिखित बातों का ध्यान रखें:
पूरी सूची नहीं: इस्तेमाल किए जा सकने वाले टैग की कोई तय सूची नहीं है. आउटपुट में बदलाव देखने के लिए, अलग-अलग भावनाओं और एक्सप्रेशन (जैसे कि
[bored],[sarcastically]या[like dracula]) के साथ एक्सपेरिमेंट किया जा सकता है.अंग्रेज़ी के अलावा किसी और भाषा में टेक्स्ट प्रॉम्प्ट: अगर आपका टेक्स्ट प्रॉम्प्ट अंग्रेज़ी में नहीं है, तो भी आपको बेहतर नतीजों के लिए अंग्रेज़ी ऑडियो टैग का इस्तेमाल करना चाहिए.
प्रॉम्प्ट का उदाहरण:
I have a secret to tell you. [whispers] I found the hidden treasure. [laughs] I can't believe it!
सीमाएं और ज़रूरी शर्तें
बोलकर कॉन्टेंट जनरेट करने की सुविधा का इस्तेमाल करते समय, इन सीमाओं और ज़रूरी शर्तों के बारे में जानें:
एक से ज़्यादा स्पीकर वाले कॉन्फ़िगरेशन में, सिर्फ़ दो स्पीकर इस्तेमाल किए जा सकते हैं.
इन सुविधाओं का इस्तेमाल सिर्फ़ Gemini 3.x TTS मॉडल के साथ किया जा सकता है: स्ट्रीमिंग, ऑडियो टैग, और अपने-आप पहचानी गई अन्य भाषाएं.
gemini-3.1-flash-tts-preview के लिए ज़रूरी शर्तें
- आवाज़ में अंतर होना: ऐसा हो सकता है कि मॉडल का आउटपुट, हमेशा चुने गए स्पीकर की आवाज़ से मेल न खाए. ऐसा तब होता है, जब आपके प्रॉम्प्ट का टोन और कॉन्टेक्स्ट, स्पीकर की प्रोफ़ाइल से मेल न खाए. उदाहरण के लिए, किसी पुरुष की गहरी आवाज़ का किसी छोटी लड़की की तरह बोलने की कोशिश करना. पक्का करें कि आपके प्रॉम्प्ट का कॉन्टेक्स्ट, आवाज़ से मेल खाता हो.
- लंबे आउटपुट: कुछ मिनटों से ज़्यादा लंबे ऑडियो के लिए, स्पीच की क्वालिटी और एकरूपता में बदलाव हो सकता है. हमारा सुझाव है कि लंबे टेक्स्ट प्रॉम्प्ट को छोटे-छोटे हिस्सों में बांट लें.
- कभी-कभी टेक्स्ट टोकन मिलते हैं: मॉडल कभी-कभी ऑडियो टोकन के बजाय टेक्स्ट टोकन देता है. इस वजह से, अनुरोध पूरा नहीं हो पाता और
500गड़बड़ी का मैसेज दिखता है. यह समस्या, अनुरोधों के कुछ ही हिस्से में होती है. इसलिए, आपको अपने ऐप्लिकेशन में फिर से कोशिश करने की सुविधा लागू करनी चाहिए. - क्लासिफ़ायर के ज़रिए गलत तरीके से अस्वीकार किए गए अनुरोध: अस्पष्ट प्रॉम्प्ट, स्पीच सिंथेसिस क्लासिफ़ायर की जांच में पास नहीं हो सकते. इस वजह से, अनुरोध अस्वीकार किया जा सकता है (
PROHIBITED_CONTENT) या मॉडल, स्टाइल से जुड़े निर्देशों को पढ़कर सुना सकता है. इससे बचने के लिए, प्रॉम्प्ट की शुरुआत मेंAudio ProfileऔरDirector's Notesजैसे शब्दों का इस्तेमाल करके, प्रॉम्प्ट को स्ट्रक्चर्ड तरीके से लिखें.
इस सुविधा के साथ काम करने वाली आवाज़ें और भाषाएं
Gemini टीटीएस मॉडल, टेक्स्ट इनपुट लेते हैं और ऑडियो आउटपुट जनरेट करते हैं. इसलिए, जवाब सिंथेसाइज़ की गई स्पीच होती है. नीचे दिए गए सब-सेक्शन में, उन भाषाओं और आवाज़ों की सूची दी गई है जिनमें Gemini टीटीएस मॉडल "बोल" सकते हैं (या जवाब दे सकते हैं).
आवाज़ें कई भाषाओं में उपलब्ध हैं. इसका मतलब है कि किसी भी भाषा में टेक्स्ट को ऑडियो में बदलने के लिए, एक ही आवाज़ का इस्तेमाल किया जा सकता है. उदाहरण के लिए, Kore की आवाज़ सेट की जा सकती है. इसके बाद, स्पैनिश, हिन्दी, और वियतनामीज़ में टेक्स्ट प्रॉम्प्ट का सेट भेजा जा सकता है. जवाब, कोर की आवाज़ में ही दिए जाएंगे. हालांकि, ये जवाब अलग-अलग भाषाओं में होंगे.
आवाज़ों के नाम
Gemini टीटीएस मॉडल, सिंथेसाइज़ की गई 30 अलग-अलग एचडी आवाज़ों के साथ काम करते हैं. हर आवाज़ की अपनी अलग विशेषताएं होती हैं. नीचे दिए गए सेक्शन को बड़ा करके, जवाब देने के लिए उपलब्ध आवाज़ों की सूची देखी जा सकती है और हर आवाज़ का डेमो सुना जा सकता है.
भाषाएं
Gemini टीटीएस मॉडल, आपके टेक्स्ट प्रॉम्प्ट में मौजूद इन भाषाओं का पता अपने-आप लगा सकते हैं. जनरेट की गई आवाज़ उसी भाषा में होगी.
ध्यान दें कि आपके पास स्पीच कॉन्फ़िगरेशन में, भाषा का कोड साफ़ तौर पर सेट करने का विकल्प होता है.
ऑडियो जनरेट करने वाले सभी मॉडल के साथ काम करने वाली भाषाएं
| भाषा | BCP-47 कोड | भाषा | BCP-47 कोड |
|---|---|---|---|
| ऐरेबिक (मिस्र) | ar-EG | जर्मन (जर्मनी) | de-DE |
| अंग्रेज़ी (यूएस) | en-US | स्पेनिश (यूएस) | es-US |
| फ़्रांसीसी (फ़्रांस) | fr-FR | हिन्दी (भारत) | hi-IN |
| इंडोनेशियन (इंडोनेशिया) | id-ID | इतालवी (इटली) | it-IT |
| जैपनीज़ (जापान) | ja-JP | कोरियाई (कोरिया) | ko-KR |
| पॉर्चुगीज़ (ब्राज़ील) | pt-BR | रूसी (रूस) | ru-RU |
| डच (नीदरलैंड्स) | nl-NL | पोलिश (पोलैंड) | pl-PL |
| थाई (थाईलैंड) | th-TH | टर्किश (तुर्की) | tr-TR |
| वियतनामीज़ (वियतनाम) | vi-VN | रोमेनियन (रोमानिया) | ro-RO |
| यूक्रेनियन (यूक्रेन) | uk-UA | बांग्ला (बांग्लादेश) | bn-BD |
| अंग्रेज़ी (भारत) | en-IN और hi-IN बंडल | मराठी (भारत) | mr-IN |
| तमिल (भारत) | ta-IN | तेलुगु (भारत) | te-IN |
आवाज़ जनरेट करने वाले 3.x मॉडल के साथ काम करने वाली अन्य भाषाएं
| भाषा | BCP-47 कोड | भाषा | BCP-47 कोड |
|---|---|---|---|
| अफ़्रीकान्स | af | फ़िलिपिनो | fil |
| अल्बेनियन | sq | फ़िनिश | fi |
| ऐमहैरिक | am | गैलिशियन | gl |
| आर्मीनियन | hy | जॉर्जियन | ka |
| अज़रबैजानी | az | ग्रीक | el |
| बैस्क | eu | गुजराती | gu |
| Belarusian | be | हैतियन क्रियोल | ht |
| बल्गैरियन | bg | हीब्रू | वह |
| बर्मीज़ | my | हंगेरियन | hu |
| कैटलैन | ca | आइसलैंडिक | है |
| सेबुआनो | ceb | जावानीज़ | jv |
| चाइनीज़, मैंडरिन | cmn | कन्नड़ | kn |
| क्रोएशियन | घंटा | कोंकणी | kok |
| चेक | cs | लाओ | lo |
| डेनिश | da | लैटिन | la |
| एस्टोनियन | et | लातवियन | lv |
| Lithuanian | lt | लक्ज़मबर्गिश | पाउंड |
| मेसिडोनियन | mk | मैथिली | mai |
| मालागासी | मि॰ग्रा॰ | मलय | ms |
| Malayalam | ml | मंगोलियन | mn |
| Nepali | ne | नॉर्वीजन, बुकमॉल | nb |
| नॉर्वीजन, नायनॉर्स्क | nn | ओड़िया | या |
| पश्तो | ps | फ़ारसी | fa |
| पंजाबी | pa | सर्बियन | sr |
| सिंधी | sd | सिंहला | si |
| Slovak | sk | Slovenian | sl |
| स्वाहिली | sw | Swedish | sv |
| उर्दू | ur |
(ज़रूरी नहीं) भाषा कोड को साफ़ तौर पर सेट करना
यदि आप अपने स्पीच कॉन्फ़िगरेशन में भाषा कोड निर्दिष्ट नहीं करते हैं, तो मॉडलभाषा का स्वतः पता लगाता है आपके टेक्स्ट प्रॉम्प्ट में.
हालांकि, भाषा को साफ़ तौर पर सेट किया जा सकता है. इसके लिए, स्पीच कॉन्फ़िगरेशन में languageCode पैरामीटर का इस्तेमाल करें. इसके लिए, आपको बीसीपी-47 के इन स्टैंडर्ड वाले भाषा कोड में से किसी एक का इस्तेमाल करना होगा:
- अरबी:
ar-XA - बंगाली:
bn-IN - चाइनीज़ (मंदारिन):
cmn-CN - डच:
nl-NL - अंग्रेज़ी:
en-US,en-GB,en-AU,en-IN - फ़्रेंच:
fr-FR,fr-CA - जर्मन:
de-DE - गुजराती:
gu-IN - हिन्दी:
hi-IN - इंडोनेशियाई:
id-ID - इटैलियन:
it-IT - जापानी:
ja-JP - कन्नड़:
kn-IN - कोरियन:
ko-KR - मलयालम:
ml-IN - मराठी:
mr-IN - पोलिश:
pl-PL - पॉर्चुगीज़:
pt-BR - रूसी:
ru-RU - स्पैनिश:
es-US,es-ES - तमिल:
ta-IN - तेलुगू:
te-IN - थाई:
th-TH - टर्किश:
tr-TR - वियतनामी:
vi-VN
तुम और क्या कर सकती हो?
- मॉडल को लंबे प्रॉम्प्ट भेजने से पहले, टोकन गिनने का तरीका जानें.
-
प्रोडक्शन के लिए तैयारी शुरू करें. इसके लिए, प्रोडक्शन चेकलिस्ट देखें:
- Firebase App Check को जल्द से जल्द लागू करें, ताकि बिना अनुमति वाले क्लाइंट के गलत इस्तेमाल से Gemini API को बचाया जा सके.
- Firebase Remote Config या सर्वर प्रॉम्प्ट टेंप्लेट का इस्तेमाल करें, ताकि ऐप्लिकेशन का नया वर्शन रिलीज़ किए बिना, एआई सुविधा (जैसे कि मॉडल का नाम) के कॉन्फ़िगरेशन में ज़रूरत के हिसाब से बदलाव किए जा सकें.
अन्य सुविधाएं आज़माएं
- सिलसिलेवार बातचीत (चैट) की सुविधा बनाएं.
- सिर्फ़ टेक्स्ट वाले प्रॉम्प्ट से टेक्स्ट जनरेट करना.
- टेक्स्ट और मल्टीमॉडल प्रॉम्प्ट, दोनों से स्ट्रक्चर्ड आउटपुट (जैसे, JSON) जनरेट करना.
- टेक्स्ट और मल्टीमॉडल प्रॉम्प्ट, दोनों की मदद से इमेज जनरेट करना और उनमें बदलाव करना.
- Gemini Live API का इस्तेमाल करके, स्ट्रीम इनपुट और आउटपुट (इसमें ऑडियो भी शामिल है).
-
Gemini मॉडल को अपने ऐप्लिकेशन के अन्य हिस्सों और बाहरी सिस्टम और जानकारी से कनेक्ट करने के लिए, टूल इस्तेमाल करें. जैसे, फ़ंक्शन कॉलिंग और
Google Search याGoogle Maps के साथ ग्राउंडिंग.
कॉन्टेंट जनरेट करने की सुविधा को कंट्रोल करने का तरीका जानें
- प्रॉम्प्ट डिज़ाइन करने के बारे में जानें. इसमें सबसे सही तरीके, रणनीतियां, और उदाहरण के तौर पर दिए गए प्रॉम्प्ट शामिल हैं.
- मॉडल के पैरामीटर कॉन्फ़िगर करें. जैसे, ज़्यादा से ज़्यादा आउटपुट टोकन, बार-बार इस्तेमाल होने वाले आउटपुट टोकन की संभावना वगैरह.
- सुरक्षा सेटिंग का इस्तेमाल करें, ताकि आपको ऐसे जवाब मिलने की संभावना कम हो जाए जिन्हें नुकसान पहुंचाने वाला माना जा सकता है.
साथ काम करने वाले मॉडल के बारे में ज़्यादा जानें
अलग-अलग कामों के लिए उपलब्ध मॉडल के बारे में जानें. साथ ही, उनके कोटे और कीमत के बारे में जानें.Firebase AI Logic के साथ अपने अनुभव के बारे में सुझाव/राय दें या शिकायत करें