i18n/zh-TW/gemini-live-api-dev/SKILL.md
處理使用 Gemini Live API 的即時、雙向串流應用程式時使用此技能。涵蓋基於 WebSocket 的音訊/視訊/文字串流、語音活動偵測 (VAD)、原生音訊功能、函式呼叫、會話管理、用戶端身分驗證的臨時權杖,以及所有 Live API 設定選項。涵蓋的 SDK - google-genai (Python)、@google/genai (JavaScript/TypeScript)。
npx skillsauth add tai-ch0802/skills-bundle gemini-live-api-devInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Live API 支援透過 WebSockets 與 Gemini 進行低延遲、即時的語音和視訊互動。它能處理連續的音訊、視訊或文字串流,並提供即時、擬真的口語回應。
主要功能:
thinkingLevel)[!NOTE] Live API 目前僅支援 WebSockets。如需 WebRTC 支援或簡化的整合,請使用合作夥伴整合。
gemini-3.1-flash-live-preview — 針對低延遲、即時對話進行最佳化。原生音訊輸出、思考(透過 thinkingLevel)。128k 上下文視窗。這是所有 Live API 案例的建議模型。[!WARNING] 以下 Live API 模型已棄用並將被關閉。請遷移至
gemini-3.1-flash-live-preview。
gemini-2.5-flash-native-audio-preview-12-2025— 請遷移至gemini-3.1-flash-live-preview。gemini-live-2.5-flash-preview— 於 2025 年 6 月 17 日發布。關閉時間:2025 年 12 月 9 日。gemini-2.0-flash-live-001— 於 2025 年 4 月 9 日發布。關閉時間:2025 年 12 月 9 日。
audio/pcm;rate=16000[!IMPORTANT] 請使用
send_realtime_input/sendRealtimeInput處理所有即時使用者輸入(音訊、視訊和文字)。send_client_content/sendClientContent僅支援用於設定初始上下文歷史記錄(需要在history_config中設定initial_history_in_client_content)。請勿使用它在對話期間傳送新的使用者訊息。
[!WARNING] 請勿在
sendRealtimeInput中使用media。請使用特定鍵值:audio用於音訊資料、video用於圖片/視訊影格、text用於文字輸入。
from google import genai
client = genai.Client(api_key="YOUR_API_KEY")
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({ apiKey: 'YOUR_API_KEY' });
from google.genai import types
config = types.LiveConnectConfig(
response_modalities=[types.Modality.AUDIO],
system_instruction=types.Content(
parts=[types.Part(text="你是一個樂於助人的助手。")]
)
)
async with client.aio.live.connect(model="gemini-3.1-flash-live-preview", config=config) as session:
pass # 會話現已啟動
const session = await ai.live.connect({
model: 'gemini-3.1-flash-live-preview',
config: {
responseModalities: ['audio'],
systemInstruction: { parts: [{ text: '你是一個樂於助人的助手。' }] }
},
callbacks: {
onopen: () => console.log('已連接'),
onmessage: (response) => console.log('訊息:', response),
onerror: (error) => console.error('錯誤:', error),
onclose: () => console.log('已關閉')
}
});
await session.send_realtime_input(text="你好,你好嗎?")
session.sendRealtimeInput({ text: '你好,你好嗎?' });
await session.send_realtime_input(
audio=types.Blob(data=chunk, mime_type="audio/pcm;rate=16000")
)
session.sendRealtimeInput({
audio: { data: chunk.toString('base64'), mimeType: 'audio/pcm;rate=16000' }
});
# frame:原始 JPEG 編碼位元組
await session.send_realtime_input(
video=types.Blob(data=frame, mime_type="image/jpeg")
)
session.sendRealtimeInput({
video: { data: frame.toString('base64'), mimeType: 'image/jpeg' }
});
[!IMPORTANT] 單一伺服器事件可同時包含多個內容部分(例如音訊區塊和文字轉錄)。請務必在每個事件中處理所有部分,以避免遺漏內容。
async for response in session.receive():
content = response.server_content
if content:
# 音訊 — 在每個事件中處理所有部分
if content.model_turn:
for part in content.model_turn.parts:
if part.inline_data:
audio_data = part.inline_data.data
# 轉錄
if content.input_transcription:
print(f"User: {content.input_transcription.text}")
if content.output_transcription:
print(f"Gemini: {content.output_transcription.text}")
# 中斷
if content.interrupted is True:
pass # 停止播放,清除音訊佇列
// 在 onmessage 回呼函式中
const content = response.serverContent;
if (content?.modelTurn?.parts) {
for (const part of content.modelTurn.parts) {
if (part.inlineData) {
const audioData = part.inlineData.data; // Base64 編碼
}
}
}
if (content?.inputTranscription) console.log('User:', content.inputTranscription.text);
if (content?.outputTranscription) console.log('Gemini:', content.outputTranscription.text);
if (content?.interrupted) { /* 停止播放,清除音訊佇列 */ }
TEXT 或 AUDIO,無法兩者兼具send_realtime_input(音訊、視訊、文字)。僅保留 send_client_content 來注入對話歷史記錄audioStreamEnd 以排空快取的音訊如需詳細的 API 文件,請從官方文件索引取得:
llms.txt URL:https://ai.google.dev/gemini-api/docs/llms.txt
此索引包含所有文件頁面的 .md.txt 格式連結。使用網路擷取工具來:
llms.txt 以探索可用的文件頁面https://ai.google.dev/gemini-api/docs/live-session.md.txt)[!IMPORTANT] 以下並非所有文件頁面。請使用
llms.txt索引來探索可用的文件頁面。
Live API 支援 70 種語言,包括:英文、西班牙文、法文、德文、義大利文、葡萄牙文、中文、日文、韓文、印地文、阿拉伯文、俄文等。原生音訊模型會自動偵測並切換語言。
development
Unified testing skill — TDD workflow, unit/integration patterns, E2E/Playwright strategies. Replaces tdd-workflow + testing-patterns + webapp-testing.
testing
Security-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
development
Spec-Driven Development (SDD): A structured workflow (Requirement -> Analysis -> Implementation) enforcing explicit documentation before coding.
development
Methodologies for System Analysis (SA), focusing on technical architecture, data flow modeling, and API design.