メインコンテンツまでスキップ

音声およびビデオモデルを照会する

このページでは、 Databricks上の Gemini 基盤モデルにオーディオおよびビデオ入力を送信する方法について説明します。 Chat Completions APIまたはGoogle Gemini APIを使用して、URL または base64 エンコードされたインラインデータとしてメディアを提供できます。

要件

入力方法

音声および映像入力は、以下の2つの方法で提供できます。

  • URL :メディアファイルへの公開アクセス可能なURLを渡します。動画に関しては、YouTubeのURLもサポートされています。
  • Base64 インラインデータ : ファイルを base64 文字列としてエンコードし、データ URI として渡します (例: data:video/mp4;base64,<encoded_data> )。

チャット完了API

チャット完了APIを使用すると、ビデオと音声の入力を渡すことができます。メディア入力を渡すには、 messages配列内のvideo_urlaudio_urlコンテンツタイプを使用します。各コンテンツアイテムには、Web URL または base64 データ URI のいずれかを受け入れるurlフィールドが含まれています。

ビデオ入力

Python
import os
import base64
from openai import OpenAI

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')
DATABRICKS_BASE_URL = os.environ.get('DATABRICKS_BASE_URL')

client = OpenAI(
api_key=DATABRICKS_TOKEN,
base_url=DATABRICKS_BASE_URL
)

# Encode a local video file as base64
with open("video.mp4", "rb") as f:
video_b64 = base64.standard_b64encode(f.read()).decode("utf-8")

response = client.chat.completions.create(
model="databricks-gemini-3-1-pro",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Summarize what happens in these videos."},
{
"type": "video_url",
"video_url": {"url": "https://example.com/sample-video.mp4"}
},
{
"type": "video_url",
"video_url": {"url": f"data:video/mp4;base64,{video_b64}"}
},
]
}],
max_tokens=1024
)

print(response.choices[0].message.content)

音声入力

Python
import os
import base64
from openai import OpenAI

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')
DATABRICKS_BASE_URL = os.environ.get('DATABRICKS_BASE_URL')

client = OpenAI(
api_key=DATABRICKS_TOKEN,
base_url=DATABRICKS_BASE_URL
)

# Encode a local audio file as base64
with open("audio.mp3", "rb") as f:
audio_b64 = base64.standard_b64encode(f.read()).decode("utf-8")

response = client.chat.completions.create(
model="databricks-gemini-3-1-pro",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Transcribe this audio and summarize the key points."},
{
"type": "audio_url",
"audio_url": {"url": "https://example.com/sample-audio.mp3"}
},
{
"type": "audio_url",
"audio_url": {"url": f"data:audio/mp3;base64,{audio_b64}"}
},
]
}],
max_tokens=1024
)

print(response.choices[0].message.content)

Google Gemini API

Google Gemini API を使用して、メディアをinlineData (base64 エンコード) またはfileData (URL 参照) としてparts配列内に渡します。

ビデオ入力

Python
from google import genai
from google.genai import types
import base64
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = genai.Client(
api_key="databricks",
http_options=types.HttpOptions(
base_url="https://example.staging.cloud.databricks.com/serving-endpoints/gemini",
headers={
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
},
),
)

# Encode a local video file as base64
with open("video.mp4", "rb") as f:
video_b64 = base64.standard_b64encode(f.read()).decode("utf-8")

response = client.models.generate_content(
model="databricks-gemini-3-1-pro",
contents=[
types.Content(
role="user",
parts=[
types.Part(text="Summarize what happens in these videos."),
types.Part(
file_data=types.FileData(
mime_type="video/mp4",
file_uri="https://example.com/sample-video.mp4",
)
),
types.Part(
inline_data=types.Blob(
mime_type="video/mp4",
data=video_b64,
)
),
],
),
],
config=types.GenerateContentConfig(
max_output_tokens=1024,
),
)

print(response.text)

音声入力

Python
from google import genai
from google.genai import types
import base64
import os

DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')

client = genai.Client(
api_key="databricks",
http_options=types.HttpOptions(
base_url="https://example.staging.cloud.databricks.com/serving-endpoints/gemini",
headers={
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
},
),
)

# Encode a local audio file as base64
with open("audio.mp3", "rb") as f:
audio_b64 = base64.standard_b64encode(f.read()).decode("utf-8")

response = client.models.generate_content(
model="databricks-gemini-3-1-pro",
contents=[
types.Content(
role="user",
parts=[
types.Part(text="Transcribe this audio and summarize the key points."),
types.Part(
file_data=types.FileData(
mime_type="audio/mp3",
file_uri="https://example.com/sample-audio.mp3",
)
),
types.Part(
inline_data=types.Blob(
mime_type="audio/mp3",
data=audio_b64,
)
),
],
),
],
config=types.GenerateContentConfig(
max_output_tokens=1024,
),
)

print(response.text)

対応モデル

オーディオおよびビデオ入力は、次の Gemini Pro 単位の従量課金基盤モデルでサポートされています。 利用可能なリージョンについては、基盤モデルAPIsで利用可能なDatabricksホスト型基盤モデルを参照してください。

  • databricks-gemini-3-1-pro
  • databricks-gemini-3-pro
  • databricks-gemini-2-5-pro

制限事項

  • オーディオおよびビデオ入力は、Gemini Pro 仮想単位の従量課金基盤モデルでのみ利用可能です。 プロビジョニングされたスループットエンドポイントはサポートされていません。
  • 1つのリクエストに複数の音声または映像入力を含めることができますが、ファイルサイズが大きいほど遅延とトークン使用量が増加します。

その他のリソース