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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

โมเดลที่รองรับความสามารถนี้

  • gemini-3.1-flash-tts-preview

สร้างเสียงพูดจากข้อความ

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

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

ก่อนลองใช้ตัวอย่างนี้ ให้ทำตามส่วนก่อนเริ่มต้นของคู่มือนี้เพื่อตั้งค่าโปรเจ็กต์และแอป
ในส่วนนั้น คุณจะต้องคลิกปุ่มสำหรับผู้ให้บริการ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: [ResponseModalities.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',
  generationConfig: 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

    • ตั้งค่า responseModalities ให้รวม AUDIO

    • กำหนดค่า SpeechConfig ด้วยข้อมูลต่อไปนี้

  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: [ResponseModalities.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',
  generationConfig: 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: [ResponseModalities.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',
  generationConfig: 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) ที่จุดเริ่มต้นของพรอมต์



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

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

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

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

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

ภาษา

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

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

ภาษาที่โมเดลการสร้างเสียงทั้งหมดรองรับ
ภาษา รหัส 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 ได้ด้วย

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

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


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