การสร้างข้อความเป็นการอ่านออกเสียง (TTS) โดยใช้ Gemini API


คุณขอให้Geminiโมเดล TTS สร้างเอาต์พุตคำพูด (เสียง) จากพรอมต์ข้อความได้ เมื่อใช้ Firebase AI Logic คุณจะส่งคำขอนี้ได้ โดยตรงจากแอป

การสร้างการอ่านออกเสียงข้อความ (TTS) เป็นแบบควบคุมได้ ซึ่งหมายความว่าคุณระบุข้อความที่แน่นอนเพื่อสังเคราะห์เป็นคำพูด นอกจากนี้ คุณยังใช้ภาษาธรรมชาติ ในพรอมต์เพื่อกำหนดสไตล์ สำเนียง ความเร็ว และโทนเสียงของเอาต์พุตเสียงได้ด้วย คุณอาจมองว่า TTS เป็นส่วนตรงข้ามของการถอดเสียง (คำพูดเป็นข้อความ)

ฟีเจอร์นี้พร้อมใช้งานโดยใช้โมเดล Gemini -tts ใดก็ได้ ซึ่ง ได้รับการเพิ่มประสิทธิภาพเพื่อสร้างคำพูดคุณภาพสูงที่มีเวลาในการตอบสนองต่ำ

ความสามารถนี้ช่วยให้คุณทำสิ่งต่างๆ ได้ เช่น

  • การเล่าเรื่องแบบอินเทอร์แอกทีฟ: สร้างหนังสือเสียงที่สมจริงหรือเกมเล่นตามบทบาท ที่โมเดลเปลี่ยนเสียงสำหรับตัวละครต่างๆ หรือปรับ โทนเสียง (เช่น กระซิบในฉากที่น่าสงสัยหรือหัวเราะกับมุกตลก) ให้เข้ากับ การบรรยาย

  • การเรียนรู้ภาษา: สร้างคำแนะนำในการออกเสียงที่อ่านข้อความด้วย สำเนียงเฉพาะของภูมิภาคหรืออ่านช้าลงเพื่อช่วยให้ผู้เรียนฝึก การออกเสียงที่ยาก

  • โปรแกรมอ่านเนื้อหาที่รับรู้บริบท: อ่านบทความข่าว สูตรอาหาร หรือบล็อกโพสต์ ออกเสียงโดยใช้เสียงและอารมณ์ที่ตรงกับเนื้อหา (เช่น น้ำเสียงจริงจังสำหรับข่าวล่าสุด หรือน้ำเสียงอบอุ่นและอดทน สำหรับวิธีการทำอาหารแบบทีละขั้นตอน)

คู่มือนี้แสดงวิธีสร้างคำพูดจากข้อความที่ป้อนโดยมีผู้พูดคนเดียวหรือหลายคน และวิธีสตรีมคำตอบที่เป็นเสียง

ข้ามไปยังโค้ดสำหรับลำโพงตัวเดียว ข้ามไปยังโค้ดสำหรับลำโพงหลายตัว ข้ามไปยังโค้ดสำหรับการตอบกลับแบบสตรีม

การเปรียบเทียบระหว่าง TTS กับ Live API

ทั้งโมเดลการอ่านออกเสียงข้อความ (TTS) และโมเดล Live API เป็นโมเดลที่มีเวลาในการตอบสนองต่ำ ซึ่งสร้างคำพูดและกำหนดค่าให้ใช้เสียงและภาษาที่แตกต่างกันในการตอบได้ อย่างไรก็ตาม ทั้ง 2 อย่างนี้มีกรณีการใช้งานที่แตกต่างกันมาก

  • การสร้างการอ่านออกเสียงข้อความ (TTS) เป็นการโต้ตอบแบบคำขอ-คำตอบทางเดียว (ข้อความเข้า เสียงออก) โดยได้รับการปรับแต่งสำหรับสถานการณ์ที่ต้องอ่านออกเสียงข้อความที่ระบุอย่างถูกต้อง พร้อมการควบคุมสไตล์และเสียงอย่างละเอียด เช่น การบรรยายพอดแคสต์ หนังสือเสียง หรือการอ่านบทความออกเสียง

  • Live API รุ่นรองรับการสตรีมแบบสองทิศทางสำหรับการสนทนาด้วยเสียงแบบเรียลไทม์ (เสียงเข้า เสียงออก) โดยมีความสามารถในการสนทนาแบบไดนามิก ซึ่งโมเดลจะตัดสินใจเลือกคำพูดที่เหมาะสมเพื่อตอบกลับ โปรดทราบว่าLive API โมเดลล่าสุดยังรองรับอินพุตวิดีโอและรูปภาพด้วย

ก่อนเริ่มต้น

คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะของผู้ให้บริการ ในหน้านี้

หากยังไม่ได้ดำเนินการ ให้ทำตามคู่มือเริ่มต้นใช้งาน ซึ่งอธิบายวิธี ตั้งค่าโปรเจ็กต์ Firebase, เชื่อมต่อแอปกับ Firebase, เพิ่ม SDK, เริ่มต้นบริการแบ็กเอนด์สำหรับผู้ให้บริการ Gemini API ที่เลือก และ สร้างอินสแตนซ์ GenerativeModel

สําหรับการทดสอบและทําซ้ำในพรอมต์ เราขอแนะนําให้ใช้ Google AI Studio

รุ่นที่รองรับความสามารถนี้

  • gemini-3.1-flash-tts-preview

สร้างคำพูดจากข้อความ

คุณสร้างคำพูดจากข้อความที่ระบุได้โดยใช้โมเดล Gemini TTS

สร้างคำพูดด้วยผู้พูดคนเดียว

ก่อนที่จะลองใช้ตัวอย่างนี้ ให้ทำตามส่วน ก่อนที่จะเริ่มของคู่มือนี้ เพื่อตั้งค่าโปรเจ็กต์และแอป
ในส่วนนั้น คุณจะคลิกปุ่มสำหรับ ผู้ให้บริการ Gemini APIที่คุณเลือกเพื่อให้เห็นเนื้อหาเฉพาะของผู้ให้บริการ ในหน้านี้ด้วย

คุณสามารถกำหนดค่าโมเดลให้เอาต์พุตเสียงโดยใช้เสียงเดียวได้

ใน GenerationConfig ให้ระบุข้อมูลต่อไปนี้

โทรหา generateContent พร้อมพรอมต์ข้อความ โมเดลจะส่งคืน ข้อมูลเสียง PCM ดิบในส่วนการตอบกลับ

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 เมธอดใน SDK นี้เป็นฟังก์ชันระงับและต้องเรียกใช้ จากขอบเขต Coroutine

// 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 เมธอดการสตรีมใน SDK นี้จะแสดงผลประเภท Publisher จากไลบรารี Reactive Streams

// 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ที่คุณเลือกเพื่อให้เห็นเนื้อหาเฉพาะของผู้ให้บริการ ในหน้านี้ด้วย

คุณสามารถกำหนดค่าโมเดลให้ใช้เสียงที่แตกต่างกันสำหรับผู้พูดแต่ละคนในข้อความได้ ซึ่งมีประโยชน์ในการสร้างเสียงสำหรับบทสนทนาหรือการสนทนา

  1. สร้าง MultiSpeakerVoiceConfig ที่เชื่อมโยงชื่อผู้พูด (ซึ่งคุณจะใช้ ในพรอมต์) กับชื่อเสียงตอบกลับที่เฉพาะเจาะจง (เช่น Kore)

    การกำหนดค่าแบบหลายลำโพงรองรับลำโพง 2 ตัวเท่านั้น

  2. ใน GenerationConfig ให้ระบุข้อมูลต่อไปนี้

  3. ในพรอมต์ ให้ระบุผู้พูดโดยใช้ชื่อผู้พูดเป็น คำนำหน้า (เช่น Joe: Hello. Jane: Hi.)

โทรหา generateContent พร้อมพรอมต์ข้อความ โมเดลจะส่งคืน ข้อมูลเสียง PCM ดิบในส่วนการตอบกลับ

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 เมธอดใน SDK นี้เป็นฟังก์ชันระงับและต้องเรียกใช้ จากขอบเขต Coroutine

// 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 เมธอดการสตรีมใน SDK นี้จะแสดงผลประเภท Publisher จากไลบรารี Reactive Streams

// 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

หากต้องการสตรีมการตอบกลับด้วยคำพูด ให้เรียกใช้ generateContentStream แทน 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")
)

// 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 เมธอดใน SDK นี้เป็นฟังก์ชันระงับและต้องเรียกใช้ จากขอบเขต Coroutine

// 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 เมธอดการสตรีมใน SDK นี้จะแสดงผลประเภท Publisher จากไลบรารี Reactive Streams

// 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!



ข้อจำกัดและข้อกำหนด

โปรดทราบข้อจำกัดและข้อกำหนดต่อไปนี้เมื่อใช้การสร้างคำพูด

  • การกำหนดค่าแบบหลายลำโพงรองรับลำโพง 2 ตัวเท่านั้น

  • ฟีเจอร์ต่อไปนี้รองรับเฉพาะเมื่อใช้โมเดล Gemini 3.x TTS การสตรีม แท็กเสียง และภาษาเพิ่มเติมที่ตรวจหาอัตโนมัติ

ข้อจำกัดสำหรับ gemini-3.1-flash-tts-preview

  • เสียงไม่สอดคล้องกัน: เอาต์พุตของโมเดลอาจไม่ตรงกับผู้พูดที่เลือกเสมอไป หากโทนและบริบทของพรอมต์ไม่สอดคล้องกับโปรไฟล์ของผู้พูด (เช่น เสียงผู้ชายทุ้มพยายามพูดเหมือนเด็กผู้หญิง) ตรวจสอบว่าบริบทของพรอมต์ตรงกับเสียง
  • เอาต์พุตที่ยาวขึ้น: คุณภาพและความสอดคล้องของคำพูดอาจเปลี่ยนแปลงสำหรับเสียงที่ยาวกว่า 2-3 นาที เราขอแนะนำให้แบ่งพรอมต์ที่เป็นข้อความยาวๆ ออกเป็นส่วนเล็กๆ
  • การแสดงผลโทเค็นข้อความเป็นครั้งคราว: บางครั้งโมเดลจะแสดงผลโทเค็นข้อความ แทนโทเค็นเสียง ซึ่งทำให้คำขอไม่สำเร็จและเกิดข้อผิดพลาด 500 เนื่องจากเหตุการณ์นี้เกิดขึ้นแบบสุ่มในคำขอบางส่วน คุณจึงควรใช้ตรรกะการลองใหม่ในแอป
  • การปฏิเสธที่ผิดพลาดของตัวแยกประเภท: พรอมต์ที่ไม่ชัดเจนอาจทำให้ตัวแยกประเภทการสังเคราะห์เสียงพูดไม่ทำงาน ส่งผลให้คำขอถูกปฏิเสธ (PROHIBITED_CONTENT) หรือทำให้โมเดลอ่านคำสั่งสไตล์ของคุณออกเสียง หากต้องการหลีกเลี่ยงปัญหานี้ ให้ใช้พรอมต์ที่มีโครงสร้างพร้อมคำนำที่ชัดเจน (เช่น Audio Profile และ Director's Notes) ที่จุดเริ่มต้นของพรอมต์



เสียงและภาษาที่รองรับ

Geminiโมเดล TTS จะรับอินพุตข้อความและสร้างเอาต์พุตเสียง ดังนั้น คำตอบจึงเป็นเสียงพูดที่สังเคราะห์ขึ้นเอง ส่วนย่อยต่อไปนี้แสดงรายการ เสียงและภาษาที่รองรับซึ่งGeminiโมเดล TTS สามารถ "พูด" (หรือตอบกลับ) ได้

เสียงพูดรองรับหลายภาษา ซึ่งหมายความว่าคุณใช้เสียงเดียวกันเพื่อสร้าง คำพูดในภาษาใดก็ได้ที่รองรับ เช่น คุณสามารถตั้งค่าเสียงเป็น Kore และส่งชุดพรอมต์ข้อความเป็นภาษาสเปน ฮินดี และเวียดนาม คำตอบทั้งหมดจะเป็นเสียงของ Kore แต่เป็นภาษาต่างๆ เหล่านั้น

ชื่อของเสียง

Geminiโมเดล TTS รองรับเสียง HD ที่สังเคราะห์ขึ้น 30 แบบ ซึ่งแต่ละแบบ มีลักษณะเฉพาะที่แตกต่างกัน คุณสามารถดูรายการตัวเลือกเสียงตอบและฟังตัวอย่างเสียงแต่ละเสียงได้ โดยขยายส่วนด้านล่าง

ภาษา

Geminiโมเดล TTS สามารถตรวจหาภาษาต่อไปนี้ในพรอมต์ข้อความโดยอัตโนมัติ โดยคำพูดที่สร้างขึ้นจะอยู่ในภาษานั้น

โปรดทราบว่าคุณสามารถตั้งรหัสภาษาอย่างชัดเจนในการกำหนดค่าคำพูดได้ (ไม่บังคับ)

ภาษาที่โมเดลสร้างเสียงทั้งหมดรองรับ
ภาษา รหัส BCP-47 ภาษา รหัส BCP-47
อาหรับ (อียิปต์) ar-EG เยอรมัน (เยอรมนี) de-DE
อังกฤษ (อเมริกัน) th-TH สเปน (สหรัฐอเมริกา) 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
เบลารุส be เฮติครีโอล ht
บัลแกเรีย bg ฮีบรู เขา
พม่า ของฉัน ฮังการี hu
คาตาลัน ca ไอซ์แลนด์ เท่ากับ
เซบู ceb ชวา jv
จีนกลาง cmn กันนาดา kn
โครเอเชีย ชม. กงกณี kok
เช็ก cs ลาว lo
เดนมาร์ก da ละติน la
เอสโตเนีย et ลัตเวีย lv
ลิทัวเนีย lt ลักเซมเบิร์ก ปอนด์
มาซิโดเนีย mk ไมถิลี mai
มาลากาซี มก. มาเลย์ ms
Malayalam ml มองโกเลีย mn
Nepali ne นอร์เวย์ (บ็อกมอล) nb
นอร์เวย์ (นีนอสก์) nn โอเดีย หรือ
พาชตู ps เปอร์เซีย fa
ปัญจาบ pa เซอร์เบียน sr
สินธี sd สิงหล si
Slovak sk สโลวีเนีย sl
สวาฮิลี sw Swedish sv
อูรดู ur

(ไม่บังคับ) ตั้งรหัสภาษาอย่างชัดเจน

หากคุณไม่ได้ระบุรหัสภาษาในการกำหนดค่าการพูด โมเดลจะตรวจหาภาษาโดยอัตโนมัติในพรอมต์ข้อความ

อย่างไรก็ตาม คุณสามารถตั้งค่าภาษาอย่างชัดเจนได้ (โดยใช้พารามิเตอร์ languageCode ในการกำหนดค่าการพูด) โดยคุณต้องใช้รหัสภาษา BCP-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



คุณทำอะไรได้อีกบ้าง

ลองใช้ความสามารถอื่นๆ

ดูวิธีควบคุมการสร้างเนื้อหา

นอกจากนี้ คุณยังทดลองใช้พรอมต์และการกำหนดค่าโมเดล รวมถึงรับ ข้อมูลโค้ดที่สร้างขึ้นได้ด้วยการใช้ Google AI Studio

ดูข้อมูลเพิ่มเติมเกี่ยวกับโมเดลที่รองรับ

ดูข้อมูลเกี่ยวกับ โมเดลที่พร้อมใช้งานสำหรับกรณีการใช้งานต่างๆ รวมถึง โควต้าและ ราคา


แสดงความคิดเห็น เกี่ยวกับประสบการณ์การใช้งาน Firebase AI Logic