درک صوتی
جمینی میتواند ورودی صوتی را تجزیه و تحلیل کرده و پاسخهای متنی تولید کند.
پایتون
from google import genai
import base64
client = genai.Client()
uploaded_file = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(interaction.steps[-1].content[0].text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const uploadedFile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mimeType: "audio/mp3" }
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Describe this audio clip"},
{
type: "audio",
uri: uploadedFile.uri,
mimeType: uploadedFile.mimeType
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
استراحت
# First upload the file, then use the 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-flash-preview",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"uri": "YOUR_FILE_URI",
"mime_type": "audio/mp3"
}
]
}'
نمای کلی
Gemini میتواند ورودی صوتی را تجزیه و تحلیل و درک کند و پاسخهای متنی تولید کند و موارد استفادهای مانند موارد زیر را امکانپذیر سازد:
- توصیف، خلاصه کردن یا پاسخ به سوالات مربوط به محتوای صوتی
- رونویسی و ترجمه (گفتار به متن)
- شناسایی گوینده (شناسایی گویندگان مختلف)
- تشخیص احساسات در گفتار و موسیقی
- تجزیه و تحلیل بخشهای خاص با مهرهای زمانی
برای تعاملات صوتی و تصویری در لحظه، به Live API مراجعه کنید. برای مدلهای اختصاصی تبدیل گفتار به متن با پشتیبانی از رونویسی در لحظه، از Google Cloud Speech-to-Text API استفاده کنید.
تبدیل گفتار به متن
این مثال نحوه رونویسی، ترجمه و خلاصهسازی گفتار با استفاده از مهرهای زمانی، تشخیص خاطرات گوینده و تشخیص احساسات را با استفاده از خروجیهای ساختاریافته نشان میدهد.
پایتون
from google import genai
client = genai.Client()
YOUTUBE_URL = "https://www.youtube.com/watch?v=ku-N-eS1lgM"
prompt = """
Process the audio file and generate a detailed transcription.
Requirements:
1. Identify distinct speakers (e.g., Speaker 1, Speaker 2).
2. Provide accurate timestamps for each segment (Format: MM:SS).
3. Detect the primary language of each segment.
4. If not English, provide the English translation.
5. Identify the primary emotion: Happy, Sad, Angry, or Neutral.
6. Provide a brief summary at the beginning.
"""
response_schema = {
"type": "object",
"properties": {
"summary": {"type": "string"},
"segments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"speaker": {"type": "string"},
"timestamp": {"type": "string"},
"content": {"type": "string"},
"language": {"type": "string"},
"emotion": {
"type": "string",
"enum": ["happy", "sad", "angry", "neutral"]
}
},
"required": ["speaker", "timestamp", "content", "emotion"]
}
}
},
"required": ["summary", "segments"]
}
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "video", "uri": YOUTUBE_URL, "mime_type": "video/mp4"},
{"type": "text", "text": prompt}
],
response_format=response_schema,
)
print(interaction.steps[-1].content[0].text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const YOUTUBE_URL = "https://www.youtube.com/watch?v=ku-N-eS1lgM";
const prompt = `
Process the audio file and generate a detailed transcription.
Requirements:
1. Identify distinct speakers (e.g., Speaker 1, Speaker 2).
2. Provide accurate timestamps for each segment (Format: MM:SS).
3. Detect the primary language of each segment.
4. If not English, provide the English translation.
5. Identify the primary emotion: Happy, Sad, Angry, or Neutral.
6. Provide a brief summary at the beginning.
`;
const responseSchema = {
type: "object",
properties: {
summary: { type: "string" },
segments: {
type: "array",
items: {
type: "object",
properties: {
speaker: { type: "string" },
timestamp: { type: "string" },
content: { type: "string" },
language: { type: "string" },
emotion: {
type: "string",
enum: ["happy", "sad", "angry", "neutral"]
}
},
required: ["speaker", "timestamp", "content", "emotion"]
}
}
},
required: ["summary", "segments"]
};
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{ type: "uri", uri: YOUTUBE_URL, mimeType: "video/mp4" },
{ type: "text", text: prompt }
],
response_format: responseSchema,
});
console.log(JSON.parse(interaction.steps.at(-1).content[0].text));
استراحت
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-flash-preview",
"input": [
{
"type": "video",
"uri": "https://www.youtube.com/watch?v=ku-N-eS1lgM",
"mime_type": "video/mp4"
},
{
"type": "text",
"text": "Transcribe with speaker diarization and emotion detection."
}
],
"response_format": {
"type": "object",
"properties": {
"summary": {"type": "string"},
"segments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"speaker": {"type": "string"},
"timestamp": {"type": "string"},
"content": {"type": "string"},
"emotion": {"type": "string", "enum": ["happy", "sad", "angry", "neutral"]}
}
}
}
}
}
}'

ورودی صدا
شما میتوانید دادههای صوتی را به روشهای زیر ارائه دهید:
- قبل از درخواست ، فایل صوتی را آپلود کنید .
- دادههای صوتی درونخطی را همراه با درخواست ارسال کنید .
آپلود فایل صوتی
برای فایلهای بزرگتر از ۲۰ مگابایت از API فایلها استفاده کنید.
پایتون
from google import genai
client = genai.Client()
uploaded_file = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(interaction.steps[-1].content[0].text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const uploadedFile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mimeType: "audio/mp3" }
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Describe this audio clip"},
{
type: "audio",
uri: uploadedFile.uri,
mimeType: uploadedFile.mimeType
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
استراحت
# First upload the file using the Files API, then use the 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-flash-preview",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"uri": "YOUR_FILE_URI",
"mime_type": "audio/mp3"
}
]
}'
انتقال دادههای صوتی به صورت درون خطی
برای فایلهای صوتی کوچک زیر ۲۰ مگابایت، حجم کل درخواست:
پایتون
from google import genai
client = genai.Client()
with open('path/to/small-sample.mp3', 'rb') as f:
audio_bytes = f.read()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"data": base64.b64encode(audio_bytes).decode('utf-8'),
"mime_type": "audio/mp3"
}
]
)
print(interaction.steps[-1].content[0].text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const client = new GoogleGenAI({});
const audioData = fs.readFileSync("path/to/small-sample.mp3", {
encoding: "base64"
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Describe this audio clip"},
{
type: "audio",
data: audioData,
mimeType: "audio/mp3"
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
استراحت
AUDIO_PATH="path/to/sample.mp3"
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"
else
B64FLAGS="-w0"
fi
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-flash-preview",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{
"type": "audio",
"data": "'$(base64 $B64FLAGS $AUDIO_PATH)'",
"mime_type": "audio/mp3"
}
]
}'
نکاتی در مورد دادههای صوتی درونخطی: * حداکثر اندازه درخواست در مجموع ۲۰ مگابایت است (شامل پیامها و تمام فایلها) * برای استفاده مجدد، فایل را آپلود کنید
دریافت ریزنمرات
برای دریافت ریزنمرات، در قسمت پرسش و پاسخ درخواست دهید:
پایتون
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Generate a transcript of the speech."},
{
"type": "audio",
"uri": uploaded_file.uri,
"mime_type": "audio/mp3"
}
]
)
print(interaction.steps[-1].content[0].text)
جاوا اسکریپت
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{ type: "text", text: "Generate a transcript of the speech." },
{
type: "audio",
uri: uploadedFile.uri,
mime_type: uploadedFile.mimeType
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
به مهرهای زمانی مراجعه کنید
برای ارجاع به بخشهای خاص از قالب MM:SS استفاده کنید:
پایتون
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Provide a transcript from 02:30 to 03:29."},
{
"type": "audio",
"uri": uploaded_file.uri,
"mime_type": "audio/mp3"
}
]
)
جاوا اسکریپت
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{ type: "text", text: "Provide a transcript from 02:30 to 03:29." },
{ type: "audio", uri: uploadedFile.uri, mime_type: "audio/mp3" }
]
});
تعداد توکنها
شمارش توکنها در یک فایل صوتی:
پایتون
response = client.models.count_tokens(
model='gemini-3-flash-preview',
input=[
{
"type": "audio",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(response)
جاوا اسکریپت
const response = await client.models.countTokens({
model: "gemini-3-flash-preview",
input: [
{
type: "audio",
uri: uploadedFile.uri,
mime_type: uploadedFile.mimeType
}
]
});
console.log(response.totalTokens);
فرمتهای صوتی پشتیبانیشده
- WAV -
audio/wav - MP3 -
audio/mp3 - AIFF -
audio/aiff - AAC -
audio/aac - OGG Vorbis -
audio/ogg - FLAC -
audio/flac
جزئیات فنی در مورد صدا
- توکنها : ۳۲ توکن در هر ثانیه از صدا (۱ دقیقه = ۱۹۲۰ توکن)
- غیرگفتاری : جوزا صداهای غیرگفتاری (آواز پرندگان، آژیرها و غیره) را میفهمد.
- حداکثر طول : ۹.۵ ساعت صدا برای هر درخواست
- وضوح تصویر : کاهش یافته به ۱۶ کیلوبیت بر ثانیه
- کانالها : صدای چند کاناله ترکیب شده با صدای تک کاناله
قدم بعدی چیست؟
- API فایلها : آپلود و مدیریت فایلهای صوتی
- دستورالعملهای سیستم : سفارشیسازی رفتار مدل
- خروجی ساختاریافته : نتایج رونویسی را با فرمت JSON دریافت کنید