การถอดเสียงเป็นคำ

Gemini API จะแปลงคำพูดในไฟล์เสียงเป็นข้อความโดยใช้โมเดล Gemini 3.5 Transcribe (gemini-3.5-transcribe) โดยอิงตามความสามารถในการทำความเข้าใจเสียงของ Gemini ซึ่งจะให้การถอดเสียงที่แม่นยำพร้อมการระบุภาษาอัตโนมัติ การระบุผู้พูด การประทับเวลาที่ระดับคำ และคำแนะนำคำศัพท์ที่กำหนดเอง นอกจากนี้ยังมีโหมดการถอดเสียงเป็นคำอัจฉริยะที่มาพร้อมการนำคำพูดที่ไม่ต่อเนื่องออกและการจัดรูปแบบอัจฉริยะ

หากต้องการถอดเสียงไฟล์เสียง ให้อัปโหลดเสียงและส่งไปยัง gemini-3.5-transcribe

Python

from google import genai

client = genai.Client()

audio_file = client.files.upload(file="path/to/sample.mp3")

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
)

print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const audioFile = await client.files.upload({
  file: "path/to/sample.mp3",
  config: { mime_type: "audio/mp3" },
});

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
});

console.log(interaction.output_text);

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

# First upload the file via the Files API, then pass its URI:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ]
  }'

ภาพรวม

Gemini 3.5 Transcribe ได้รับการเพิ่มประสิทธิภาพสำหรับงานแปลงเสียงพูดเป็นข้อความ โดยจะจัดการกับสำเนียงที่หลากหลาย เสียงรบกวนรอบข้าง และการสนทนาหลายภาษา

ความสามารถหลักๆ มีดังนี้

  • การรู้จำคำพูดอัตโนมัติ (ASR): ตรวจหาภาษาโดยอัตโนมัติในกว่า 85 ภาษา จัดการการสลับภาษาภายในประโยคและระหว่างประโยคโดยไม่ต้องกำหนดค่าด้วยตนเอง
  • คำศัพท์ที่กำหนดเอง: ช่วยให้ระบบจดจำคำศัพท์ ตัวย่อ และชื่อเฉพาะในโดเมนได้ดีขึ้นโดยการส่งวลีได้สูงสุด 1,000 รายการ
  • การระบุผู้พูด: แยกแยะผู้พูดหลายคนและเชื่อมโยงส่วนที่พูดกับป้ายกำกับที่แตกต่างกัน
  • การประทับเวลาที่ระดับคำ: สร้างออฟเซ็ตเวลาเริ่มต้นและเวลาสิ้นสุดที่แน่นอนสำหรับแต่ละคำที่ระบบจดจำ
  • การถอดเสียงอัจฉริยะ: ล้างคำพูดที่ไม่มีความหมาย การพูดซ้ำ และใช้การจัดรูปแบบที่มีโครงสร้าง
  • การจัดรูปแบบและการทำให้เป็นมาตรฐาน: ใช้การใช้อักษรตัวพิมพ์ใหญ่ เครื่องหมายวรรคตอน และการทำให้ข้อความเป็นมาตรฐานแบบผกผัน เช่น การแปลง "ยี่สิบล้านหกแสนดอลลาร์" เป็น "$26M"

หากต้องการให้เหตุผลเกี่ยวกับเสียงทั่วไปหรือตอบคำถามเกี่ยวกับเนื้อหาเสียง ให้ใช้การทำความเข้าใจเสียง สำหรับการสังเคราะห์เสียงอ่านออกเสียงข้อความ ให้ใช้ Text-to-speech

การตรวจหาภาษาและคำแนะนำ

โดยค่าเริ่มต้น โมเดลจะตรวจจับภาษาที่พูดโดยอัตโนมัติ โดยจะสลับภาษาแบบไดนามิกเมื่อผู้พูดเปลี่ยนภาษา

หากต้องการใช้การตรวจหาอัตโนมัติ ให้ละเว้น language_codes หรือระบุรายการว่าง

Python

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
    generation_config={
        "transcription_config": {
            "language_codes": [],
        }
    },
)

JavaScript

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
  generation_config: {
    transcription_config: {
      language_codes: [],
    },
  },
});

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
            GenerationConfig: &interactions.GenerationConfig{
                TranscriptionConfig: &interactions.TranscriptionConfig{
                    LanguageCodes: []string{},
                },
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ],
    "generation_config": {
      "transcription_config": {
        "language_codes": []
      }
    }
  }'

หากทราบภาษาล่วงหน้า ให้ระบุรหัสภาษา BCP-47 ใน language_codes เพื่อปรับปรุงความแม่นยำของการถอดเสียง (ดูภาษาที่รองรับ)

Python

generation_config = {
    "transcription_config": {
        "language_codes": ["es-ES"],
    }
}

JavaScript

const generationConfig = {
  transcription_config: {
    language_codes: ["es-ES"],
  },
};

Go

package main

import (
    "google.golang.org/genai/interactions/models/interactions"
)

func main() {
    generationConfig := &interactions.GenerationConfig{
        TranscriptionConfig: &interactions.TranscriptionConfig{
            LanguageCodes: []string{"es-ES"},
        },
    }
    _ = generationConfig
}

REST

{
  "generation_config": {
    "transcription_config": {
      "language_codes": ["es-ES"]
    }
  }
}

คำศัพท์ที่กำหนดเอง

คุณสามารถนำโมเดลการพูดไปยังคำที่ไม่ค่อยมีคนใช้ คำศัพท์เฉพาะทาง ชื่อแบรนด์ หรือคำนามเฉพาะได้ ระบุคำศัพท์ได้สูงสุด 1,000 คำในอาร์เรย์ custom_vocabulary (โดยปกติแล้วจะให้ผลลัพธ์ที่ดีที่สุดเมื่อใช้คำศัพท์ไม่เกิน 100 คำ)

Python

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
    generation_config={
        "transcription_config": {
            "custom_vocabulary": ["Gemini", "Kubernetes", "BigQuery"],
        }
    },
)

JavaScript

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
  generation_config: {
    transcription_config: {
      custom_vocabulary: ["Gemini", "Kubernetes", "BigQuery"],
    },
  },
});

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
            GenerationConfig: &interactions.GenerationConfig{
                TranscriptionConfig: &interactions.TranscriptionConfig{
                    CustomVocabulary: []string{"Gemini", "Kubernetes", "BigQuery"},
                },
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ],
    "generation_config": {
      "transcription_config": {
        "custom_vocabulary": ["Gemini", "Kubernetes", "BigQuery"]
      }
    }
  }'

การแยกแยะเสียงผู้พูด

การระบุผู้พูดจะระบุเสียงที่แตกต่างกันในการบันทึกและติดแท็กแต่ละส่วนด้วยตัวระบุผู้พูด เช่น spk_1 หรือ spk_2 รองรับลำโพงสูงสุด 8 ตัว (การระบุแหล่งที่มาสำหรับลำโพงตั้งแต่ 3 ตัวขึ้นไปเป็นเวอร์ชันทดลอง)

เปิดใช้การแยกแยะเสียงผู้พูดโดยกำหนดค่า diarization_mode ภายใน mode ดังนี้

Python

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
    generation_config={
        "transcription_config": {
            "mode": {
                "type": "verbatim",
                "diarization_mode": "speaker",
            },
        }
    },
)

JavaScript

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
  generation_config: {
    transcription_config: {
      mode: {
        type: "verbatim",
        diarization_mode: "speaker",
      },
    },
  },
});

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
            GenerationConfig: &interactions.GenerationConfig{
                TranscriptionConfig: &interactions.TranscriptionConfig{
                    Mode: genai.Ptr(interactions.NewTranscriptionConfigMode(interactions.NewTranscriptionMode(interactions.VerbatimTranscriptionMode{
                        DiarizationMode: genai.Ptr("speaker"),
                    }))),
                },
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ],
    "generation_config": {
      "transcription_config": {
        "mode": {
          "type": "verbatim",
          "diarization_mode": "speaker"
        }
      }
    }
  }'

การประทับเวลาระดับคำ

การประทับเวลาระดับคำจะระบุออฟเซ็ตเริ่มต้นและสิ้นสุดที่แน่นอนสำหรับทุกคำที่ระบบจดจำได้ในสตรีมเสียง

เปิดใช้การประทับเวลาโดยกำหนดค่า timestamp_granularities ภายใน mode ดังนี้

Python

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
    generation_config={
        "transcription_config": {
            "mode": {
                "type": "verbatim",
                "timestamp_granularities": ["word"],
            },
        }
    },
)

JavaScript

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
  generation_config: {
    transcription_config: {
      mode: {
        type: "verbatim",
        timestamp_granularities: ["word"],
      },
    },
  },
});

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
            GenerationConfig: &interactions.GenerationConfig{
                TranscriptionConfig: &interactions.TranscriptionConfig{
                    Mode: genai.Ptr(interactions.NewTranscriptionConfigMode(interactions.NewTranscriptionMode(interactions.VerbatimTranscriptionMode{
                        TimestampGranularities: []string{"word"},
                    }))),
                },
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ],
    "generation_config": {
      "transcription_config": {
        "mode": {
          "type": "verbatim",
          "timestamp_granularities": ["word"]
        }
      }
    }
  }'

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

Python

generation_config = {
    "transcription_config": {
        "mode": {
            "type": "verbatim",
            "diarization_mode": "speaker",
            "timestamp_granularities": ["word"],
        },
    }
}

JavaScript

const generationConfig = {
  transcription_config: {
    mode: {
      type: "verbatim",
      diarization_mode: "speaker",
      timestamp_granularities: ["word"],
    },
  },
};

Go

package main

import (
    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
)

func main() {
    generationConfig := &interactions.GenerationConfig{
        TranscriptionConfig: &interactions.TranscriptionConfig{
            Mode: genai.Ptr(interactions.NewTranscriptionConfigMode(interactions.NewTranscriptionMode(interactions.VerbatimTranscriptionMode{
                DiarizationMode:        genai.Ptr("speaker"),
                TimestampGranularities: []string{"word"},
            }))),
        },
    }
    _ = generationConfig
}

REST

{
  "generation_config": {
    "transcription_config": {
      "mode": {
        "type": "verbatim",
        "diarization_mode": "speaker",
        "timestamp_granularities": ["word"]
      }
    }
  }
}

โหมดการถอดเสียงเป็นคำ

Gemini 3.5 Transcribe รองรับโหมดการถอดเสียงเป็นคำ 2 โหมดผ่านพารามิเตอร์ mode ดังนี้

  • verbatim (ค่าเริ่มต้น): แสดงผลข้อความถอดเสียงแบบคำต่อคำที่ตรงกันทุกคำที่พูด โดยจะเก็บคำฟุ่มเฟือยดิบ ("เอ่อ", "อืม", "แบบว่า", "ก็") การพูดซ้ำ การหยุดชั่วคราว และการพูดติดขัด คุณกำหนดค่าการประทับเวลาและการแยกแยะเสียงผู้พูดได้ในโหมดนี้ ({"type": "verbatim", ...})
  • smart (การถอดเสียงอัจฉริยะ): เพิ่มประสิทธิภาพข้อความถอดเสียงสำหรับการอ่านโดยใช้การประมวลผลหลังการถอดเสียงอัจฉริยะ
    • การนำคำพูดที่ไม่มีความหมายออก: นำคำพูดที่ไม่มีความหมายในบทสนทนา การพูดติดขัด และการเริ่มต้นที่ไม่ถูกต้องออก
    • การแก้ไขตนเองในบรรทัด: แก้ไขคำที่พูดโดยตรง (เช่น "มาเจอกันวันอังคาร ไม่สิ วันพุธตอน 14:00 น." จะกลายเป็น "มาเจอกันวันพุธตอน 14:00 น.")
    • การจัดรูปแบบที่มีโครงสร้างอัตโนมัติ: จัดโครงสร้างความคิดที่พูดให้เป็นย่อหน้า รายการที่เรียงลำดับเลข หัวข้อย่อย วันที่ สกุลเงิน และตัวเลขที่จัดรูปแบบโดยอัตโนมัติ
    • การปรับไวยากรณ์: ใช้เครื่องหมายวรรคตอน การจัดรูปแบบประโยค และลำดับการนำเสนอที่เป็นธรรมชาติ
เสียงพูด เอาต์พุต verbatim smart เอาต์พุต (การถอดเสียงอัจฉริยะ)
"เอ่อ สำหรับการประชุม ฉันคิดว่าเราควรเชิญ เอ่อ ขวัญใจ ไม่สิ บัญชาและแคโรล" "เอ่อ สำหรับการประชุม ฉันคิดว่าเราควรเชิญอลิซ เอ่อ ไม่ใช่ บ็อบกับแครอล" "สำหรับการประชุม ฉันคิดว่าเราควรเชิญบ็อบและแครอล"
"รายการแรกตรวจสอบงบประมาณ รายการที่สองกำหนดไทม์ไลน์ รายการที่สามส่งสรุป" "first item review budget second item finalize timeline third item send recap" "1. ตรวจสอบงบประมาณ
2. สรุปไทม์ไลน์
3. ส่งสรุป"

Python

interaction = client.interactions.create(
    model="gemini-3.5-transcribe",
    input=[
        {
            "type": "audio",
            "uri": audio_file.uri,
            "mime_type": audio_file.mime_type,
        }
    ],
    generation_config={
        "transcription_config": {
            "mode": "smart",
        }
    },
)
print(interaction.output_text)

JavaScript

const interaction = await client.interactions.create({
  model: "gemini-3.5-transcribe",
  input: [
    {
      type: "audio",
      uri: audioFile.uri,
      mime_type: audioFile.mimeType,
    },
  ],
  generation_config: {
    transcription_config: {
      mode: "smart",
    },
  },
});
console.log(interaction.output_text);

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    audioFile, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.5-transcribe"),
            Input: interactions.NewInteractionsInput([]interactions.Content{
                interactions.NewContent(interactions.AudioContent{
                    URI:      genai.Ptr(audioFile.URI),
                    MimeType: interactions.AudioContentMimeType(audioFile.MIMEType).ToPointer(),
                }),
            }),
            GenerationConfig: &interactions.GenerationConfig{
                TranscriptionConfig: &interactions.TranscriptionConfig{
                    Mode: genai.Ptr(interactions.NewTranscriptionConfigMode(interactions.TranscriptionConfigModeEnumSmart)),
                },
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res.Interaction.GetOutputText())
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-transcribe",
    "input": [
      {
        "type": "audio",
        "uri": "YOUR_FILE_URI",
        "mime_type": "audio/mp3"
      }
    ],
    "generation_config": {
      "transcription_config": {
        "mode": "smart"
      }
    }
  }'

การแยกวิเคราะห์เอาต์พุตการถอดเสียง

ระบบจะแสดงข้อความถอดเสียงทั้งหมดใน interaction.output_text

เมื่อเปิดใช้ timestamp_granularities หรือ diarization_mode API จะแสดงคำอธิบายประกอบระดับคำแบบละเอียดที่แนบมากับเนื้อหาการโต้ตอบด้วย

วิธีแยกและวนซ้ำการประทับเวลาของคำและลำดับการพูดมีดังนี้

Python

def extract_word_annotations(interaction):
    words = []
    for step in getattr(interaction, "steps", []) or []:
        for content in getattr(step, "content", []) or []:
            for annotation in getattr(content, "annotations", []) or []:
                if getattr(annotation, "type", None) == "word_info":
                    words.append(annotation)
    return words

words = extract_word_annotations(interaction)

for w in words:
    speaker = f"[{w.speaker}] " if getattr(w, "speaker", None) else ""
    start = getattr(w, "start_offset", "")
    end = getattr(w, "end_offset", "")
    timing = f"({start} -> {end}) " if start and end else ""
    print(f"{speaker}{timing}{w.text}")

JavaScript

function extractWordAnnotations(interaction) {
  const words = [];
  for (const step of interaction.steps ?? []) {
    for (const content of step.content ?? []) {
      for (const annotation of content.annotations ?? []) {
        if (annotation.type === "word_info") {
          words.push(annotation);
        }
      }
    }
  }
  return words;
}

const words = extractWordAnnotations(interaction);

for (const w of words) {
  const speaker = w.speaker ? `[${w.speaker}] ` : "";
  const timing = (w.start_offset && w.end_offset) ? `(${w.start_offset} -> ${w.end_offset}) ` : "";
  console.log(`${speaker}${timing}${w.text}`);
}

Go

package main

import (
    "fmt"

    "google.golang.org/genai/interactions/models/interactions"
)

func extractWordAnnotations(interaction *interactions.Interaction) []*interactions.WordInfo {
    var words []*interactions.WordInfo
    if interaction == nil {
        return words
    }
    for _, step := range interaction.Steps {
        if step.ModelOutputStep != nil {
            for _, content := range step.ModelOutputStep.Content {
                if content.TextContent != nil {
                    for _, annotation := range content.TextContent.Annotations {
                        if annotation.WordInfo != nil {
                            words = append(words, annotation.WordInfo)
                        }
                    }
                }
            }
        }
    }
    return words
}

func main() {
    var interaction *interactions.Interaction
    words := extractWordAnnotations(interaction)

    for _, w := range words {
        speaker := ""
        if w.Speaker != nil && *w.Speaker != "" {
            speaker = fmt.Sprintf("[%s] ", *w.Speaker)
        }
        timing := ""
        if w.StartOffset != nil && w.EndOffset != nil {
            timing = fmt.Sprintf("(%s -> %s) ", *w.StartOffset, *w.EndOffset)
        }
        fmt.Printf("%s%s%s\n", speaker, timing, w.GetText())
    }
}

REST

{
  "id": "interactions/abc123xyz",
  "status": "completed",
  "steps": [
    {
      "id": "step_001",
      "type": "model_output",
      "content": [
        {
          "type": "text",
          "text": "Hello world",
          "annotations": [
            {
              "type": "word_info",
              "text": "Hello",
              "speaker": "spk_1",
              "start_offset": "0.100s",
              "end_offset": "0.450s"
            },
            {
              "type": "word_info",
              "text": "world",
              "speaker": "spk_1",
              "start_offset": "0.500s",
              "end_offset": "0.850s"
            }
          ]
        }
      ]
    }
  ]
}

ภาษาที่รองรับ

Gemini 3.5 Transcribe รองรับภาษาและรหัสภาษา BCP-47 ต่อไปนี้

ภาษา รหัส BCP-47 ภาษา รหัส BCP-47
อาฟรีกานส์ af-ZA ญี่ปุ่น ja-JP
อัมฮาริก am-ET ชวา jv-ID
อาหรับ (อียิปต์) ar-EG คาบูเวอร์เดียนู kea-CV
อาร์เมเนีย hy-AM กันนาดา kn-IN
อัสสัม as-IN คาซัค kk-KZ
อาร์เซอร์ไบจัน az-AZ เกาหลี ko-KR
เบลารุส be-BY คีร์กิซ ky-KG
เบงกาลี (บังกลาเทศ) bn-BD ลัตเวีย lv-LV
เบงกาลี (อินเดีย) bn-IN ลิงกาลา ln-CD
บอสเนีย bs-BA ลิทัวเนีย lt-LT
บัลแกเรีย bg-BG มาซีโดเนีย mk-MK
บัลแกเรีย (อโรมาเนีย) rup-BG มาเลย์ ms-MY
พม่า my-MM มาลายาลัม ml-IN
จีนกวางตุ้ง (ตัวเต็ม) yue-Hant-HK มอลตา mt-MT
คาตาลัน ca-ES จีนกลาง (ตัวย่อ) cmn-Hans-CN
ซีบัวโน ceb มราฐี mr-IN
เขมรตอนกลาง km-KH มองโกเลีย mn-MN
โครเอเชีย hr-HR เนปาล ne-NP
เช็ก cs-CZ นอร์เวย์ nb-NO
เดนมาร์ก da-DK โอริยา or-IN
ดัตช์ nl-NL โปแลนด์ pl-PL
อังกฤษ (บริเตนใหญ่) en-GB โปรตุเกส (บราซิล) pt-BR
อังกฤษ (อินเดีย) en-IN โปรตุเกส (โปรตุเกส) pt-PT
อังกฤษ (สหรัฐอเมริกา) en-US ปัญจาบ pa-IN
เอสโตเนีย et-EE ปัญจาบ (สคริปต์คุรมุขี) pa-Guru-IN
ฟาร์ซี fa-IR โรมาเนีย ro-RO
ฟิลิปปินส์ fil-PH รัสเซีย ru-RU
ฟินแลนด์ fi-FI เซอร์เบีย sr-RS
ฝรั่งเศส fr-FR ภาษาสินธี (อักษรอาหรับ) sd-Arab-IN
กาลิเชียน gl-ES สโลวัก sk-SK
จอร์เจีย ka-GE สโลวีเนีย sl-SI
เยอรมัน de-DE สเปน (ลาตินอเมริกา) es-419
กรีก el-GR สเปน (สหรัฐอเมริกา) es-US
คุชราต gu-IN สวาฮีลี (เคนยา) sw-KE
เฮาซา ha-NG สวีเดน sv-SE
ฮีบรู he-IL ทาจิก tg-TJ
ฮินดี hi-IN เตลูกู te-IN
ฮังการี hu-HU ไทย th-TH
ไอซ์แลนด์ is-IS ตุรกี tr-TR
อังกฤษแบบอินเดีย en-IN ยูเครน uk-UA
อินโดนีเซีย id-ID อุซเบก uz-UZ
อิตาลี it-IT เวียดนาม vi-VN

รูปแบบเสียงที่รองรับ

Gemini 3.5 Transcribe รองรับประเภท MIME ของรูปแบบเสียงต่อไปนี้

  • WAV - audio/wav
  • MP3 - audio/mp3
  • AIFF - audio/aiff
  • AAC - audio/aac
  • OGG - audio/ogg
  • FLAC - audio/flac
  • MPEG - audio/mpeg
  • M4A - audio/m4a
  • L16 - audio/l16
  • Opus - audio/opus
  • ALAW - audio/alaw
  • MULAW - audio/mulaw
  • WebM - audio/webm

ดูรายการประเภท MIME และสคีมาพารามิเตอร์ที่รองรับทั้งหมดได้ในเอกสารอ้างอิง Interactions API

ข้อมูลอ้างอิงพารามิเตอร์

กำหนดค่าการถอดเสียงเป็นคำโดยตั้งค่าฟิลด์ภายในออบเจ็กต์ transcription_config ใน generation_config ดังนี้

ช่อง ประเภท คำอธิบาย
language_codes อาร์เรย์ของสตริง รหัสภาษา BCP-47 (เช่น ["en-US"]) หากเว้นว่างหรือไม่มีข้อมูล ([]) โมเดลจะตรวจหาภาษาโดยอัตโนมัติและจัดการการสลับภาษา
custom_vocabulary อาร์เรย์ของสตริง คำที่กำหนดเอง ตัวย่อ หรือชื่อเฉพาะสูงสุด 1,000 รายการเพื่อปรับการจดจำคำพูด ใช้ร่วมกับการระบุผู้พูดและแสตมป์เวลาระดับคำไม่ได้
mode ออบเจ็กต์หรือสตริง การกำหนดค่าโหมดการถอดเสียงเป็นคำ ยอมรับ "smart" หรือออบเจ็กต์โหมดตรงตามต้นฉบับ ({"type": "verbatim", ...}) ค่าเริ่มต้นคือการถอดเสียงตรงตามต้นฉบับ
mode.type สตริง (โหมดตรงตามคำเท่านั้น) ตัวระบุโหมด ตั้งค่าเป็น "verbatim" เสมอ
mode.timestamp_granularities อาร์เรย์ของสตริง (โหมดตามตัวอักษรเท่านั้น) รายละเอียดของการประทับเวลาที่จะแสดง ส่ง ["word"] เพื่อเปิดใช้การชดเชยจุดเริ่มต้นและจุดสิ้นสุดของคำ ใช้ร่วมกับคำศัพท์ที่กำหนดเองไม่ได้
mode.diarization_mode สตริง (โหมดตามคำพูดเท่านั้น) โหมดการระบุผู้พูด ส่ง "speaker" เพื่อระบุและติดป้ายกำกับผู้พูดแต่ละคน ใช้ร่วมกับคำศัพท์ที่กำหนดเองไม่ได้

แนวทางปฏิบัติแนะนำ

  • จัดเตรียมเสียงที่ชัดเจน: ตรวจสอบว่าไฟล์บันทึกเสียงมีการแยกเสียงพูดที่ชัดเจนและหลีกเลี่ยงการตัดเสียงที่รุนแรง
  • ระบุคำใบ้ภาษาเมื่อทราบ: หากทราบภาษาของเสียงล่วงหน้า ให้ระบุ language_codes เพื่อเพิ่มความแม่นยำให้สูงสุด
  • กำหนดเป้าหมายคำศัพท์ที่กำหนดเอง: ใส่เฉพาะคำในโดเมน ชื่อแบรนด์ หรือคำนามเฉพาะที่แตกต่างกันใน custom_vocabulary แทนที่จะใช้คำทั่วไปที่ใช้ในชีวิตประจำวัน
  • ใช้ Files API สำหรับการบันทึกขนาดใหญ่: สำหรับไฟล์ที่ยาวกว่าไม่กี่วินาที ให้อัปโหลดไฟล์โดยใช้ client.files.upload และส่ง URI ของไฟล์ที่ส่งคืนไปยังโมเดล

ข้อจำกัด

  • ระยะเวลาของเสียง: คำขอแบบเอกภาคมาตรฐานรองรับไฟล์เสียงได้นานสูงสุด 1 ชั่วโมง การประมวลผลเสียงจะจำกัดไว้ที่ 30 นาทีเมื่อเปิดใช้ฟีเจอร์ต่างๆ เช่น การระบุผู้พูดหรือการประทับเวลาที่ระดับคำ
  • การประทับเวลาระดับคำ: การเปิดใช้การประทับเวลาระดับคำอาจลดความแม่นยำในการถอดเสียงเป็นคำโดยรวม
  • การแยกแยะเสียงผู้พูด: การแยกแยะเสียงผู้พูดรองรับผู้พูดได้สูงสุด 8 คน การระบุแหล่งที่มาของลำโพงสำหรับลำโพง 3 ตัวขึ้นไปอยู่ในขั้นทดลอง
  • คำศัพท์ที่กำหนดเอง: คุณระบุคำได้สูงสุด 1,000 คำใน custom_vocabulary แต่โดยปกติแล้วการระบุคำสูงสุด 100 คำจะให้ผลลัพธ์ที่ดีที่สุด คุณใช้ custom_vocabulary ร่วมกับการระบุผู้พูดหรือการประทับเวลาที่ระดับคำไม่ได้ API จะปฏิเสธคำขอที่ระบุ custom_vocabulary พร้อมกับฟีเจอร์ใดฟีเจอร์หนึ่ง
  • ความเข้ากันได้ของโหมด: คุณไม่สามารถใช้การถอดเสียงอัจฉริยะ ("smart") ร่วมกับ timestamp_granularities หรือ diarization_mode ได้

ขั้นตอนถัดไป