Gemini for Developers

1. はじめに 👋

35807388b800fbe0.png

この Codelab では、デベロッパーとして知っておくべき Gemini エコシステムについて学びます。具体的には、さまざまな Gemini モデル、Gemini を活用したさまざまなツール、Gemini と統合するための Google Gen AI SDK について学びます。また、長いコンテキスト、思考モード、空間認識、Live API、ネイティブの画像と音声の出力など、Gemini のさまざまな機能についても学びます。

この Codelab を完了すると、Gemini エコシステムについてしっかりと理解できるようになります。

💡学習内容

  • さまざまな Gemini モデル。
  • Gemini モデルを搭載したツール。
  • Google Gen AI SDK を使用して Gemini と統合する方法。
  • Gemini の長いコンテキスト ウィンドウ。
  • Gemini の思考モード。
  • Google 検索、Google マップなどのさまざまな組み込みツール。
  • Interactions API を使用してリサーチ エージェントを操作する方法。
  • 画像とテキスト読み上げの生成。
  • Gemini の空間認識。
  • リアルタイムの音声と動画によるやり取りのための Live API。

⚠️ 必要なもの

  • Google AI Studio のサンプル用の API キー。
  • Vertex AI サンプルで課金が有効になっている Google Cloud プロジェクト。
  • ローカル開発環境または Google Cloud の Cloud Shell エディタ。

2. Gemini ファミリー 🫂

Gemini は、あらゆるアイデアを形にする Google の AI モデルです。最先端の推論技術を基盤として構築されており、マルチモーダル理解、エージェント型コーディング、バイブ コーディングに最適なモデルです。Gemini モデルの概要については、こちらの動画をご覧ください。

Gemini は単なるモデルではありません。また、Google サービスで使用される包括的なブランドでもあります。

Gemini モデルを活用しています。Google Cloud の Gemini プロダクトには、一般ユーザー向けの Gemini アプリNotebookLM から、デベロッパー向けの AI Studio、企業向けの Vertex AI まで、幅広いラインナップがあります。Gemini を活用した Gemini CLIGoogle Antigravity などのデベロッパー ツールもあります。

3ceb2752ccfbc149.jpeg

3. Gemini を活用したツール 🧰

Gemini を活用したツールを簡単に見てみましょう。

Gemini アプリ 💬

Gemini アプリ(gemini.google.com)は、チャットベースの消費者向けアプリケーションです。Gemini を操作する最も簡単な方法です。Deep Research、画像、動画、音楽の生成などのツールが用意されています。また、最新の Gemini モデル(Fast、Thinking、Pro)のさまざまなフレーバーも用意されています。Gemini アプリは日常的な使用に最適です。

d3800f85bafe9a4a.png

NotebookLM 📓

NotebookLM(notebooklm.google.com)は、AI を活用したリサーチ パートナーです。PDF、ウェブサイト、YouTube 動画、音声ファイル、Google ドキュメント、Google スライドなどをアップロードすると、NotebookLM がそれらを要約し、トピック間の興味深い関連性を導き出します。これらはすべて、最新バージョンの Gemini のマルチモーダル解析機能によって実現されます。また、アップロードしたソースから、興味深く魅力的な音声解説、動画解説、インフォグラフィックなどを生成することもできます。

4c3274795844251.png

Google AI Studio 🎨

Google AI Studio(ai.dev)は、Gemini を使ったビルドを開始する最速の方法です。Google AI Studio の [Playground] パネルでは、さまざまなモデルを試してテキスト、画像、動画を生成したり、Gemini Live API を使用してリアルタイムの音声と動画を試したりできます。Google AI Studio の [ビルド] パネルでは、ウェブ アプリケーションをバイブコードで作成し、Google Cloud の Cloud Run にデプロイして、コードを GitHub に push できます。

48fadc9d3d5f9500.png

Vertex AI Studio ☁️

Vertex AI は、Google Cloud で生成 AI を構築して使用するためのフルマネージド統合 AI 開発プラットフォームです。Vertex AI Studio(console.cloud.google.com/vertex-ai/studio)は、エンタープライズ対応の生成 AI アプリケーションのテスト、チューニング、デプロイに役立ちます。

15b55a2b635d63e1.png

Gemini CLI ⚙️

Gemini CLI(geminicli.com)は、Gemini の機能をターミナルから直接利用できるオープンソースの AI エージェントです。これは、デベロッパー、エンジニア、SRE などのためのターミナル ファーストで拡張可能かつ強力なツールとして設計されています。Gemini CLI はローカル環境と統合されています。プロジェクトのコンテキストを維持しながら、ファイルの読み取りと編集、シェル コマンドの実行、ウェブ検索を行うことができます。

b2a7f0bf377ac7b0.png

Google Antigravity 🚀

Google Antigravity(antigravity.google)は、IDE をエージェント ファーストの時代へと進化させるエージェント型開発プラットフォームです。Antigravity を使用すると、デベロッパーはタスク指向のより高いレベルで作業し、ワークスペース全体でエージェントを管理できます。また、使い慣れた AI IDE の操作性を維持できます。

Antigravity は、エージェントを独自のサーフェスに抽出し、エディタ、ターミナル、ブラウザをまたいで自律的に動作するために必要なツールを提供します。タスクとアーティファクトを介した検証と高レベルのコミュニケーションを重視しています。この機能により、エージェントはより複雑なエンドツーエンドのソフトウェア タスクを計画して実行し、機能の構築、UI の反復、バグの修正から調査、レポートの生成まで、開発のあらゆる側面を向上させることができます。

ee964351b100df93.png

これらのツールは自由にダウンロードしてご利用いただけます。各ツールをいつ使用すべきかについての一般的なガイダンスは次のとおりです。

  • 初めて使用する場合は、Gemini アプリを使用して質問をしたり、基本的なコードを生成したりすることをおすすめします。
  • ウェブ アプリケーションのバイブ コーディングを行う場合は、Google AI Studio を選択することをおすすめします。
  • ローカル開発環境のコンテキストを使用して複雑なアプリケーションを構築する場合は、Gemini CLI または Google Antigravity を選択します。
  • Google Cloud をデプロイまたはすでに使用していて、エンタープライズ レベルのサポートと機能を必要とする場合は、Vertex AI とそのスタジオを選択します。

もちろん、これらのツールを組み合わせて使用することもできます。たとえば、AI Studio でバイブ コーディングを開始して GitHub に push し、Antigravity を使用してコーディングを続行してから Google Cloud にデプロイします。

4. Gemini モデル 🧠

Gemini モデルは、数か月ごとに新しいバージョンがリリースされ、常に改善されています。本日(2026 年 2 月)現在、Google Cloud の Vertex AI で提供されているモデルは次のとおりです。

d2e4a116eaccf2fc.png

他にも、一般提供の Gemini モデルプレビュー版の Gemini モデル、オープン Gemma モデルエンベディング モデルImagegen モデルVeo モデルなど、さまざまなモデルがあります。

Google モデルのドキュメント ページにアクセスして、さまざまなユースケースで Vertex AI で利用可能な主要なモデルを確認してください。

5. Google Gen AI SDK 📦

Gemini をアプリケーションに統合するには、Google Gen AI SDK を使用します。

前述のように、Gemini モデルには Google AI Studio または Vertex AI Studio からアクセスできます。Google Gen AI SDK は、Google AI API と Google Cloud API の両方を介して Gemini モデルへの統合インターフェースを提供します。いくつかの例外を除き、1 つのプラットフォームで実行されるコードは両方のプラットフォームで実行されます。

485e9a003d26f8d.png

Google Gen AI SDK は現在、PythonGoNodeJavaC# をサポートしています。

たとえば、Python で Google AI の Gemini とやり取りするには、次のようにします。

client = genai.Client(
  api_key=your-gemini-api-key)

response = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents="Why is the sky blue?")

Vertex AI の Gemini に対して同じ処理を行うには、クライアントの初期化を変更するだけで、残りの部分は同じです。

client = genai.Client(
  vertexai=True,
  project=your-google-cloud-project,
  location="us-central1")

response = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents="Why is the sky blue?")

これらのサンプルをご自身で実行するには、github.com/meteatamel/genai-samples/tree/main/vertexai/gemini2/hello-worldmain.py を実行します。

6. Interactions API 🔄

Interactions API(ベータ版)は、Gemini モデルとエージェントを操作するための新しい統合インターフェースです。generateContent API の改良版として、状態管理、ツール オーケストレーション、長時間実行タスクを簡素化します。

新しい API との基本的なやり取りは次のようになります。

interaction =  client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me a short joke."
)
print(interaction.outputs[-1].text)

前のやり取りのやり取り ID を渡すことで、ステートフルな会話を行うことができます。

interaction1 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Hi, my name is Phil."
)
print(f"Model: {interaction1.outputs[-1].text}")

interaction2 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is my name?",
    previous_interaction_id=interaction1.id
)
print(f"Model: {interaction2.outputs[-1].text}")

Interactions API は、エージェントの構築と操作用に設計されており、関数呼び出し、組み込みツール、構造化された出力、Model Context Protocol(MCP)のサポートが含まれています。Deep Research エージェントでの使用方法については、以下のエージェント 🤖 の手順をご覧ください。

これらのサンプルをご自身で実行するには、github.com/meteatamel/genai-samples/blob/main/vertexai/interactions-apimain.py を実行します。

7. 長いコンテキスト ウィンドウ 🪟

多くの Gemini モデルには、100 万トークン以上の大きなコンテキスト ウィンドウが搭載されています。これまで、大規模言語モデル(LLM)は、一度にモデルに渡すことができるテキスト(またはトークン)の量によって大幅に制限されていました。Gemini の長いコンテキスト ウィンドウは、多くの新しいユースケースとデベロッパー パラダイムを実現します。

3fb7123fc45e7cdf.png

長いコンテキスト ウィンドウの動作を確認するには、Vertex AI Studio プロンプト ギャラリーに移動して、Extract Video Chapters プロンプトを選択します。このプロンプトは、動画コンテンツをチャプターに分割し、各チャプターの概要を示します。

提供された動画で実行すると、次のような出力が得られます。

[
  {
    "timecode": "00:00",
    "chapterSummary": "The video opens with scenic views of Rio de Janeiro, introducing the \"Marvelous City\" and its famous beaches like Ipanema and Copacabana, before pivoting to the existence of the favelas."
  },
  {
    "timecode": "00:20",
    "chapterSummary": "The narrator describes the favelas, home to one in five Rio residents, highlighting that while often associated with crime and poverty, this is only a small part of their story."
  },
  {
    "timecode": "00:36",
    "chapterSummary": "Google introduces its project to map the favelas, emphasizing that providing addresses to these uncharted areas is a crucial step in giving residents an identity."
  },
  {
    "timecode": "00:43",
    "chapterSummary": "The video concludes by focusing on the people of the favelas, inviting viewers to go beyond the map and explore their world through a 360-degree experience."
  }
]

これは Gemini の長いコンテキスト ウィンドウのおかげです。

8. 思考モード 🧠

Gemini モデルは、複雑なタスクの推論を大幅に改善する内部思考プロセスを使用します。思考レベル(Gemini 3)と予算(Gemini 2.5)は、思考の動作を制御します。include_thoughts フラグを有効にして、モデルの生の思考を確認することもできます。

思考モードの動作を確認するため、Google AI Studio(ai.dev)を開いて新しいチャットを開始しましょう。右側のサイドパネルで、思考レベルを設定できます。

382b0c617ab5940e.png

右上の Get code ボタンをクリックすると、コードで思考レベルを設定する方法も確認できます。次のようなコードが表示されます。

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="How does AI work?",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(
          thinking_level="low",
          include_thoughts=True
        )
    ),
)

さまざまなプロンプトとさまざまな思考レベルを試して、モデルの動作を確認します。

9. ツール 🧰

Gemini には、Google 検索、Google マップ、コード実行、パソコンの使用、ファイル検索など、さまざまな組み込みツールが用意されています。関数呼び出しを使用してカスタムツールを定義することもできます。これらの使用方法を簡単に見てみましょう。

Google 検索 🔎

Google 検索の検索結果でモデルの回答をグラウンディングすると、より正確で最新かつ関連性の高い回答が得られます。

Vertex AI Studio(console.cloud.google.com/vertex-ai/studio)または Google AI Studio(ai.dev)で、新しいチャットを開始し、Google 検索のグラウンディングがオフになっていることを確認します。

fb694a21e7eb7d5a.png

その後、現在地の今日の天気について質問できます。次に例を示します。

How's the weather in London today?

通常、モデルは最新情報にアクセスできないため、過去 1 日分の回答が返されます。次に例を示します。

In London today (Friday, May 24, 2025), the weather is a bit of a mixed bag, typical for late May.

次に、Google 検索のグラウンディングを有効にして、同じ質問をします。グラウンディング ソースへのリンクを含む最新の天気情報が表示されます。

In London today (Wednesday, February 11, 2026), the weather is cool and mostly cloudy with a chance of light rain.

コードで Google 検索のグラウンディングを行う方法は次のとおりです。Vertex AI Studio の [コード] ボタンをクリックして、グラウンディングのサンプルを取得することもできます。

google_search_tool = Tool(google_search=GoogleSearch())
response = client.models.generate_content(
    model="gemini-3-flash-preview",
    contents="How's the weather like today in London?",
    config=GenerateContentConfig(tools=[google_search_tool])
)

Google マップ 🗺️

2 億 5, 000 万か所以上の場所に関する情報にアクセスできる Google マップでモデルのレスポンスをグラウンディングすることもできます。

実際に動作を確認するには、Vertex AI Studio のモデル設定のグラウンディング セクションで Google 検索の代わりに Google マップを選択し、マップデータが必要な質問をします。たとえば、次のようにします。

Can you show me some Greek restaurants and their map coordinates near me?

コードは次のようになります。

google_maps_tool = Tool(google_maps=GoogleMaps())
response = client.models.generate_content(
    model="gemini-3-flash-preview",
    contents=""What are the best restaurants near here?",
    config=GenerateContentConfig(tools=[google_maps_tool]),
       # Optional: Provide location context (this is in Los Angeles)
        tool_config=ToolConfig(
          retrieval_config=types.RetrievalConfig(
            lat_lng=types.LatLng(
                latitude=34.050481, longitude=-118.248526))),
)

コードの実行 🧑‍💻

Gemini は、サポートされているライブラリ(pandas、numpy、PyPDF2 など)のリストを使用して Python コードを生成して実行できます。これは、コードベースの推論(方程式を解くなど)を活用するアプリケーションに有用です。

この機能を試すには、Google AI Studio に切り替えて新しいチャットを開始し、Code execution 切り替えがオンになっていることを確認します。次に、コード実行ツールが役立つ可能性のある質問をします。次に例を示します。

What is the sum of the first 50 prime numbers? 

Gemini が Python コードを生成して実行します。最終的な正解は 5117 です。

コードからコード実行ツールを実行するには、次のようにします。

code_execution_tool = Tool(code_execution=ToolCodeExecution())
response = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents="What is the sum of the first 50 prime numbers?",
  config=GenerateContentConfig(
    tools=[code_execution_tool],
    temperature=0))

コンピュータ使用 🖥️

Gemini コンピュータ使用モデル(プレビュー版)を使用すると、ブラウザ制御エージェントを構築してタスクを自動化できます。このループで動作します。

de6edbd0163e6ee3.png

実際に動作を確認するには、github.com/google-gemini/computer-use-previewmain.py を実行します。

たとえば、Google AI Studio から API キーを取得し、Gemini にフライトの検索を依頼できます。

export GEMINI_API_KEY=your-api-key

python main.py --query "Find me top 5 fights sorted by price with the following constraints:

Flight site to use: www.google.com/travel/flights
From: London
To: Larnaca
One-way or roundtrip: One way
Date to leave: Sometime next week
Date to return: N/A
Travel preferences:
-Direct flights
-No flights before 10am
-Carry-on luggage"

Gemini がシークレット ブラウザを開き、フライトの検索を開始します。

ファイル検索 📁

ファイル検索ツールを使用すると、検索拡張生成(RAG)を簡単に行うことができます。ファイルをアップロードするだけで、チャンク化、エンベディング、取得などの RAG の詳細をすべて処理してくれます。

実際に機能していることを確認するには、github.com/meteatamel/genai-beyond-basics/blob/main/samples/grounding/file-search-toolmain.py を実行します。

Google AI Studio から API キーを取得し、ファイル検索ストアを作成します。

export GEMINI_API_KEY=your-gemini-api-key

python main.py create_store my-file-search-store

PDF をストアにアップロードするには:

python main.py upload_to_store fileSearchStores/myfilesearchstore-5a9x71ifjge9 cymbal-starlight-2024.pdf

PDF について質問する(ストアへのリンクを含む):

python main.py generate_content "What's the cargo capacity of Cymbal Starlight?" fileSearchStores/myfilesearchstore-5a9x71ifjge9

PDF に基づいたレスポンスが返されます。

Generating content with file search store: fileSearchStores/myfilesearchstore-5a9x71ifjge9
Response: The Cymbal Starlight 2024 has a cargo capacity of 13.5 cubic feet, which is located in the trunk of the vehicle. It is important to distribute the weight evenly and not overload the trunk, as this could impact the vehicle's handling and stability. The vehicle can also accommodate up to two suitcases in the trunk, and it is recommended to use soft-sided luggage to maximize space and cargo straps to secure it while driving.
Grounding sources:  cymbal-starlight-2024.pdf

関数呼び出し 📲

組み込みツールだけでは不十分な場合は、Gemini で独自のツール(関数)を定義することもできます。(関数の詳細な OpenAPI 仕様を送信するのではなく)Python 関数をツールとして送信するだけです。モデルと SDK によってツールとして自動的に使用されます。

たとえば、位置情報の緯度と経度を返す関数を作成できます。

def location_to_lat_long(location: str):
    """Given a location, returns the latitude and longitude

    Args:
        location: The location for which to get the weather.

    Returns:
        The latitude and longitude information in JSON.
    """
    logger.info(f"Calling location_to_lat_long({location})")
    url = f"https://geocoding-api.open-meteo.com/v1/search?name={location}&count=1"
    return api_request(url)

緯度と経度から天気情報を返す関数を作成することもできます。

def lat_long_to_weather(latitude: str, longitude: str):
    """Given a latitude and longitude, returns the weather information

    Args:
        latitude: The latitude of a location
        longitude: The longitude of a location

    Returns:
        The weather information for the location in JSON.
    """
    logger.info(f"Calling lat_long_to_weather({latitude}, {longitude})")
    url = (f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current=temperature_2m,"
           f"relative_humidity_2m,surface_pressure,wind_speed_10m,wind_direction_10m&forecast_days=1")
    return api_request(url)

これで、これらの 2 つの関数をツールとして Gemini に渡し、それを使用して場所の天気情報を取得できるようになりました。

def generate_content_with_function_calls():
    client = genai.Client(
        vertexai=True,
        project=PROJECT_ID,
        location=LOCATION)

    response = client.models.generate_content(
        model=MODEL_ID,
        contents=PROMPT,
        config=GenerateContentConfig(
            system_instruction=[
                "You are a helpful weather assistant.",
                "Your mission is to provide weather information for different cities."
                "Make sure your responses are in plain text format (no markdown) and include all the cities asked.",
            ],
            tools=[location_to_lat_long, lat_long_to_weather],
            temperature=0),
    )

    print(response.text)
    #print(response.automatic_function_calling_history)

実際に機能していることを確認するには、github.com/meteatamel/genai-beyond-basics/blob/main/samples/function-calling/weathermain_genaisdk.py を実行します。

10. エージェント 🤖

Gemini の Interactions API は、エージェントの構築と操作用に設計されています。Gemini Deep Research エージェントなどの特殊なエージェントを使用できます。Gemini Deep Research エージェントは、複数ステップの調査タスクを自律的に計画、実行、統合します。ウェブ検索とユーザー自身のデータを使用して複雑な情報環境をナビゲートし、詳細な引用付きレポートを作成します。

Interaction API で Deep Research エージェントを使用する方法は次のとおりです。

interaction = client.interactions.create(
    input="Research the history of the Google TPUs.",
    agent="deep-research-pro-preview-12-2025",
    background=True
)

while True:
    if interaction.status == "completed":
        print("\nFinal Report:\n",
interaction.outputs[-1].text)
        break

このサンプルをご自身で実行するには、github.com/meteatamel/genai-samples/blob/main/vertexai/interactions-apimain.py を実行します。

export GOOGLE_API_KEY=your-api-key
python main.py agent

しばらくすると、調査結果が表示されます。

User: Research the history of the Google TPUs with a focus on 2025 and 2026

Status: in_progress
Status: in_progress
Status: in_progress
...
Model Final Report:
 # Architectural Convergence and Commercial Expansion: The History of Google TPUs (2015–2026)

## Key Findings
*   **Strategic Pivot (2025):** Google transitioned the Tensor Processing Unit (TPU) from a primarily internal differentiator to a commercial merchant-silicon competitor, epitomized by the massive "Ironwood" (TPU v7) deployment and external sales strategy.
*   **Technological Leap:** The introduction of TPU v7 "Ironwood" in 2025 marked a paradigm shift, utilizing 3nm process technology to deliver 42.5 exaFLOPS per pod, directly challenging NVIDIA's Blackwell architecture in the high-performance computing (HPC) sector.
...

11. 画像生成 📷

Nano Banana 🍌 は、Gemini のネイティブ画像生成機能の名称です。Gemini は、テキスト、画像、またはその両方を組み合わせて、会話形式で画像を生成して処理できます。これにより、これまでにない制御でビジュアルを作成、編集、反復処理できます。

Nano Banana は、Gemini API で使用できる 2 つの異なるモデルを指します。

  • Nano Banana: Gemini 2.5 Flash Image モデル(gemini-2.5-flash-image)。このモデルは速度と効率を重視して設計されており、大量の低レイテンシ タスク向けに最適化されています。
  • Nano Banana Pro: Gemini 3 Pro Image プレビュー版モデル(gemini-3-pro-image-preview)。このモデルは、高度な推論を使用して複雑な指示に従い、高忠実度のテキストをレンダリングすることで、プロフェッショナルなアセット制作向けに設計されています。

既存の画像を渡して Nano Banana に画像の編集をリクエストできるコード スニペットを次に示します。

from google import genai
from google.genai import types
from PIL import Image

client = genai.Client()

prompt = (
    "Create a picture of my cat eating a nano-banana in a "
    "fancy restaurant under the Gemini constellation",
)

image = Image.open("/path/to/cat_image.png")

response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents=[prompt, image],
)

for part in response.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        image = part.as_image()
        image.save("generated_image.png")

Nano Banana は、Gemini アプリ、AI Studio、Vertex AI Studio で利用できます。最も簡単な方法は、Gemini アプリで試すことです。Gemini アプリ(gemini.google.com)で、Tools の下の 🍌 Create images を選択します。次に、画像をアップロードして、楽しいことを試してみましょう。たとえば、次のように話しかけます。

Can you transform this picture of mine to a nice beach on a tropical island?

41a830bea8cf3c9f.png 2fc9ac5b7008aafb.png

12. Text-to-Speech 生成 🎶

Gemini は、Gemini のテキスト読み上げ(TTS)生成機能を使用して、テキスト入力を単一話者または複数話者の音声に変換できます。TTS 生成は制御可能です。つまり、自然言語を使用してインタラクションを構造化し、音声のスタイル、アクセント、速度、トーンをガイドできます。

TTS をサポートするモデルは次の 2 つです。

TTS 機能は、インタラクティブな非構造化音声とマルチモーダルな入出力を対象に設計された Live API を介して提供される音声生成とは異なります。Live API は動的な会話コンテキストに優れていますが、Gemini API を介した TTS は、ポッドキャストやオーディオブックの生成など、スタイルや音をきめ細かく制御してテキストを正確に朗読する必要があるシナリオ向けに調整されています。

単一話者 TTS のコード スニペットは次のとおりです。

from google import genai
from google.genai import types
import wave

# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
   with wave.open(filename, "wb") as wf:
      wf.setnchannels(channels)
      wf.setsampwidth(sample_width)
      wf.setframerate(rate)
      wf.writeframes(pcm)

client = genai.Client()

response = client.models.generate_content(
   model="gemini-2.5-flash-preview-tts",
   contents="Say cheerfully: Have a wonderful day!",
   config=types.GenerateContentConfig(
      response_modalities=["AUDIO"],
      speech_config=types.SpeechConfig(
         voice_config=types.VoiceConfig(
            prebuilt_voice_config=types.PrebuiltVoiceConfig(
               voice_name='Kore',
            )
         )
      ),
   )
)

data = response.candidates[0].content.parts[0].inline_data.data

file_name='out.wav'
wave_file(file_name, data) # Saves the file to current directory

その他のサンプルについては、テキスト読み上げ生成(TTS)のドキュメントをご覧ください。

Google AI Studio プレイグラウンドで音声の生成を試すこともできます。generate-speech アプリでさまざまなプロンプトを試してみます。

6eb20d8a20e571fb.png

13. 空間認識 🌐

Gemini は、高度なオブジェクト検出と空間認識を備えています。

これを理解する最も簡単な方法は、実際に動作を確認することです。AI Studio の Spatial Understanding スターター アプリに移動します。画像を選択して、Gemini で画像内のアイテムを検出してみましょう。

たとえば、さまざまな画像で「影」や「果物」を検出できます。

6a521c961664339.png 2260ab81a8c9a5e8.png

さまざまな画像を試して、Gemini がさまざまなオブジェクトをどの程度検出してラベル付けできるかを確認します。

14. Live API 🎤

Live API を使用すると、Gemini と音声と動画によるやり取りを低レイテンシかつリアルタイムで行うことができます。音声、動画、テキストの連続ストリームを処理して、人間のような音声による応答を即座に提供し、ユーザーに自然な会話エクスペリエンスを提供します。

9ada309ba0cd0888.png

Google AI Studio の Live API または Vertex AI Studio の Live API をお試しください。どちらのアプリでも、音声、動画、画面を共有して Gemini とライブで会話できます。

8b4901d2aecc5b62.png

動画や画面の共有を開始し、Gemini に音声で一般的な質問をします。次に例を示します。

Can you describe what you see on the screen?

Gemini から返される回答がどれほど自然であるかに驚かれることでしょう。

15. まとめ

この Codelab では、Gemini プロダクト ファミリーから始まり、統合された Google Gen AI SDK を使用してモデルをアプリケーションに統合する方法を学ぶことで、Gemini エコシステムについて説明しました。長いコンテキスト ウィンドウ、思考モード、組み込みのグラウンディング ツール、Live API、空間認識など、Gemini の最先端の機能について説明しました。リファレンス ドキュメントを詳しく読み、Gemini の可能性を最大限に引き出すための実験を続けてください。

参照