Live API の構成オプション


Live API の基本的な実装でも、ユーザーにとって魅力的で強力なインタラクションを構築できます。必要に応じて、次の構成オプションを使用してエクスペリエンスをさらにカスタマイズできます。



レスポンスの音声と言語

モデルに特定の音声で応答させたり、異なる言語で応答させたりできます。

レスポンスの音声を指定する

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

Live API は、それぞれに特徴のある 30 種類の合成 HD 音声をサポートしています。以下のセクションを開くと、レスポンス音声オプションのリストを表示し、各音声のデモを聴くことができます。

レスポンスの音声を指定しない場合、デフォルトは Puck です。

レスポンスの音声を指定するには、モデル構成の一部として、speechConfig オブジェクト内に音声名を設定します。

Swift


// ...

let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_API_MODEL_NAME",
  // Configure the model to use a specific voice for its audio response.
  generationConfig: LiveGenerationConfig(
    responseModalities: [.audio],
    speech: SpeechConfig(voiceName: "VOICE_NAME")
  )
)

// ...

Kotlin


// ...

val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
    modelName = "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to use a specific voice for its audio response.
    generationConfig = liveGenerationConfig {
        responseModality = ResponseModality.AUDIO
        speechConfig = SpeechConfig(voice = Voice("VOICE_NAME"))
    }
)

// ...

Java


// ...

LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
    "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to use a specific voice for its audio response.
    new LiveGenerationConfig.Builder()
        .setResponseModality(ResponseModality.AUDIO)
        .setSpeechConfig(new SpeechConfig(new Voice("VOICE_NAME")))
        .build()
);

// ...

Web


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

const liveModel = getLiveGenerativeModel(ai, {
  model: "GEMINI_LIVE_API_MODEL_NAME",
  // Configure the model to use a specific voice for its audio response.
  generationConfig: {
    responseModalities: [ResponseModality.AUDIO],
    speechConfig: {
      voiceConfig: {
        prebuiltVoiceConfig: { voiceName: "VOICE_NAME" },
      },
    },
  },
});

// ...

Dart


// ...

final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
  model: 'GEMINI_LIVE_API_MODEL_NAME',
  // Configure the model to use a specific voice for its audio response.
  liveGenerationConfig: LiveGenerationConfig(
    responseModalities: [ResponseModalities.audio],
    speechConfig: SpeechConfig(voiceName: 'VOICE_NAME'),
  ),
);

// ...

Unity


// ...

var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
    modelName: "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to use a specific voice for its audio response
    liveGenerationConfig: new LiveGenerationConfig(
        responseModalities: new[] { ResponseModality.Audio },
        speechConfig: SpeechConfig.UsePrebuiltVoice("VOICE_NAME")
    )
);

// ...

回答の言語に影響を与える

Live API モデルは、回答に適切な言語を自動的に選択します。

モデルが英語以外の言語で応答するようにする場合や、常に特定の言語で応答するようにする場合は、次の例のようにシステム指示を使用してモデルのレスポンスに影響を与えることができます。

  • 英語以外の言語が適切な場合があることをモデルに強調する

    Listen to the speaker carefully. If you detect a non-English language, respond
    in the language you hear from the speaker. You must respond unmistakably in the
    speaker's language.
    
  • 特定の言語で常に回答するようモデルに指示する

    RESPOND IN LANGUAGE. YOU MUST RESPOND UNMISTAKABLY IN LANGUAGE.
    



音声入出力の文字起こし

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

モデルのレスポンスの一部として、音声入力とモデルの音声レスポンスの音声文字変換を受け取ることができます。この構成は、モデル構成の一部として設定します。

  • 音声入力の文字変換を行うには、inputAudioTranscription を追加します。

  • モデルの音声レスポンスの音声文字変換の場合は、outputAudioTranscription を追加します。

次の点にご注意ください。

  • 次の例のように、入力と出力の両方の音声文字変換を返すようにモデルを構成することも、どちらか一方のみを返すように構成することもできます。

  • 文字起こしは音声とともにストリーミングされるため、各ターンでテキスト部分を収集するのと同じように収集することをおすすめします。

  • 音声文字変換の言語は、音声入力とモデルの音声レスポンスから推測されます。

Swift


// ...

let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_API_MODEL_NAME",
  // Configure the model to return transcriptions of the audio input and output.
  generationConfig: LiveGenerationConfig(
    responseModalities: [.audio],
    inputAudioTranscription: AudioTranscriptionConfig(),
    outputAudioTranscription: AudioTranscriptionConfig()
  )
)

var inputTranscript: String = ""
var outputTranscript: String = ""

do {
  let session = try await liveModel.connect()
  for try await response in session.responses {
    if case let .content(content) = response.payload {
      if let inputText = content.inputAudioTranscription?.text {
        // Handle transcription text of the audio input.
        inputTranscript += inputText
      }

      if let outputText = content.outputAudioTranscription?.text {
        // Handle transcription text of the audio output.
        outputTranscript += outputText
      }

      if content.isTurnComplete {
        // Log the transcripts after the current turn is complete.
        print("Input audio: \(inputTranscript)")
        print("Output audio: \(outputTranscript)")

        // Reset the transcripts for the next turn.
        inputTranscript = ""
        outputTranscript = ""
      }
    }
  }


} catch {
  // Handle error
}

// ...

Kotlin


// ...

val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
    modelName = "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to return transcriptions of the audio input and output.
    generationConfig = liveGenerationConfig {
        responseModality = ResponseModality.AUDIO
        inputAudioTranscription = AudioTranscriptionConfig()
        outputAudioTranscription = AudioTranscriptionConfig()
   }
)

val liveSession = liveModel.connect()

fun handleTranscription(input: Transcription?, output: Transcription?) {
    input?.text?.let { text ->
        // Handle transcription text of the audio input.
        println("Input Transcription: $text")
    }
    output?.text?.let { text ->
        // Handle transcription text of the audio output.
        println("Output Transcription: $text")
    }
}

liveSession.startAudioConversation(null, ::handleTranscription)

// ...

Java


// ...

ExecutorService executor = Executors.newFixedThreadPool(1);

LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
    "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to return transcriptions of the audio input and output.
    new LiveGenerationConfig.Builder()
            .setResponseModality(ResponseModality.AUDIO)
            .setInputAudioTranscription(new AudioTranscriptionConfig())
            .setOutputAudioTranscription(new AudioTranscriptionConfig())
            .build()
    );

LiveModelFutures liveModel = LiveModelFutures.from(lm);
ListenableFuture<LiveSessionFutures> sessionFuture = liveModel.connect();

Futures.addCallback(sessionFuture, new FutureCallback<LiveSessionFutures>() {
    @Override
    public void onSuccess(LiveSessionFutures ses) {
        LiveSessionFutures session = ses;
        session.startAudioConversation((Transcription input, Transcription output) -> {
            if (input != null) {
                // Handle transcription text of the audio input.
                System.out.println("Input Transcription: " + input.getText());
            }
            if (output != null) {
                // Handle transcription text of the audio output.
                System.out.println("Output Transcription: " + output.getText());
            }
            return null;
        });
    }

    @Override
    public void onFailure(Throwable t) {
        // Handle exceptions
        t.printStackTrace();
    }
}, executor);

// ...

Web


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

const liveModel = getLiveGenerativeModel(ai, {
  model: 'GEMINI_LIVE_API_MODEL_NAME',
  // Configure the model to return transcriptions of the audio input and output.
  generationConfig: {
    responseModalities: [ResponseModality.AUDIO],
    inputAudioTranscription: {},
    outputAudioTranscription: {},
  },
});

const liveSession = await liveModel.connect();

liveSession.sendAudioRealtime({ data, mimeType: "audio/pcm" });

const messages = liveSession.receive();
for await (const message of messages) {
  switch (message.type) {
    case 'serverContent':
      if (message.inputTranscription) {
        // Handle transcription text of the audio input.
        console.log(`Input transcription: ${message.inputTranscription.text}`);
      }
      if (message.outputTranscription) {
        // Handle transcription text of the audio output.
        console.log(`Output transcription: ${message.outputTranscription.text}`);
      } else {
      	 // Handle other message types (modelTurn, turnComplete, interruption).
      }
    default:
      // Handle other message types (toolCall, toolCallCancellation).
  }
}

// ...

Dart


// ...

final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
  model: 'GEMINI_LIVE_API_MODEL_NAME',
  // Configure the model to return transcriptions of the audio input and output.
  liveGenerationConfig: LiveGenerationConfig(
    responseModalities: [ResponseModalities.audio],
    inputAudioTranscription: AudioTranscriptionConfig(),
    outputAudioTranscription: AudioTranscriptionConfig(),
  ),
);

final LiveSession _session = await _liveModel.connect();

await for (final response in _session.receive()) {
  if (response.message case LiveServerContent message) {
    if (message.inputTranscription?.text case final inputText?) {
      // Handle transcription text of the audio input.
      print('Input: $inputText');
    }

    if (message.outputTranscription?.text case final outputText?) {
      // Handle transcription text of the audio output.
      print('Output: $outputText');
    }
  }
}

// ...

Unity


// ...

var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
    modelName: "GEMINI_LIVE_API_MODEL_NAME",
    // Configure the model to return transcriptions of the audio input and output
    liveGenerationConfig: new LiveGenerationConfig(
        responseModalities: new[] { ResponseModality.Audio },
        inputAudioTranscription: new AudioTranscriptionConfig(),
        outputAudioTranscription: new AudioTranscriptionConfig()
    )
);

try
{
    var session = await liveModel.ConnectAsync();
    var stream = session.ReceiveAsync();
    await foreach (var response in stream) {
        if (response.Message is LiveSessionContent sessionContent) {
            if (!string.IsNullOrEmpty(sessionContent.InputTranscription?.Text)) {
              // handle transcription text of input audio
            }

            if (!string.IsNullOrEmpty(sessionContent.OutputTranscription?.Text)) {
              // handle transcription text of output audio
            }
        }
    }
}
catch (Exception e)
{
    // Handle error
}

// ...



音声アクティビティ検出(VAD)

音声検出(VAD)により、モデルは人が話しているときを認識できます。これは、いつでもモデルを中断できるようにするため、自然な会話を作成するうえで不可欠です。VAD はデフォルトで有効になっています。

中断の処理など、VAD の動作をカスタマイズできます。また、自動 VAD を無効にして、会話のターンを手動で完全に制御することもできます(プッシュツートーク インターフェースなど)。

音声検出(VAD)を構成する

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

次の例は、モデル構成の一部として realtimeInputConfig を設定して、VAD の動作をカスタマイズする方法を示しています。この構成で使用可能な設定については、このセクションの後半の表をご覧ください。

Swift


// ...

let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_API_MODEL_NAME",
  generationConfig: LiveGenerationConfig(
    responseModalities: [.audio],
    // Configure voice activity detection (VAD), interruption handling, and turn coverage.
    // IMPORTANT: Example values shown here. Make sure to update for your use case.
    realtimeInputConfig: RealtimeInputConfig(
      automaticActivityDetection: ActivityDetectionConfig(
        startSensitivity: .low,
        endSensitivity: .low,
        prefixPadding: .milliseconds(20),
        silenceDuration: .milliseconds(500)
      ),
      activityHandling: .interrupt,
      turnCoverage: .onlyActivity
    )
  )
)

Kotlin


// ...

val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
    modelName = "GEMINI_LIVE_API_MODEL_NAME",
    generationConfig = liveGenerationConfig {
        responseModality = ResponseModality.AUDIO
        // Configure voice activity detection (VAD), interruption handling, and turn coverage.
        // IMPORTANT: Example values shown here. Make sure to update for your use case.
        realtimeInputConfig = realtimeInputConfig {
            automaticActivityDetection = ActivityDetectionConfig.builder()
                .setStartSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
                .setEndSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
                .setPrefixPaddingMs(20)
                .setSilenceDurationMs(500)
                .build()
            activityHandling = RealtimeInputConfig.ActivityHandling.INTERRUPT
            turnCoverage = RealtimeInputConfig.TurnCoverage.ONLY_ACTIVITY
        }
    }
)

Java


// ...

LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
        "GEMINI_LIVE_API_MODEL_NAME",
        new LiveGenerationConfig.Builder()
                .setResponseModality(ResponseModality.AUDIO)
                // Configure voice activity detection (VAD), interruption handling, and turn coverage.
                // IMPORTANT: Example values shown here. Make sure to update for your use case.
                .setRealtimeInputConfig(RealtimeInputConfig.builder()
                        .setAutomaticActivityDetection(ActivityDetectionConfig.builder()
                                .setStartSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
                                .setEndSensitivity(ActivityDetectionConfig.Sensitivity.LOW)
                                .setPrefixPaddingMs(20)
                                .setSilenceDurationMs(500)
                                .build())
                        .setActivityHandling(RealtimeInputConfig.ActivityHandling.INTERRUPT)
                        .setTurnCoverage(RealtimeInputConfig.TurnCoverage.ONLY_ACTIVITY)
                        .build())
                .build()
);

Web

Not yet supported for Web apps - check back soon!

Dart


// ...

final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
  model: 'GEMINI_LIVE_API_MODEL_NAME',
  liveGenerationConfig: LiveGenerationConfig(
    responseModalities: [ResponseModalities.audio],
    // Configure voice activity detection (VAD), interruption handling, and turn coverage.
    // IMPORTANT: Example values shown here. Make sure to update for your use case.
    realtimeInputConfig: RealtimeInputConfig(
      automaticActivityDetection: ActivityDetectionConfig(
        startSensitivity: Sensitivity.low,
        endSensitivity: Sensitivity.low,
        prefixPaddingMS: 20,
        silenceDurationMS: 500,
      ),
      activityHandling: ActivityHandling.interrupt,
      turnCoverage: TurnCoverage.onlyActivity,
    ),
  ),
);

Unity


// ...

var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
    modelName: "GEMINI_LIVE_API_MODEL_NAME",
    liveGenerationConfig: new LiveGenerationConfig(
        responseModalities: new[] { ResponseModality.Audio },
        // Configure voice activity detection (VAD), interruption handling, and turn coverage.
        // IMPORTANT: Example values shown here. Make sure to update for your use case.
        realtimeInputConfig: new RealtimeInputConfig(
            automaticActivityDetection: new ActivityDetectionConfig(
                startSensitivity: ActivityDetectionConfig.Sensitivity.Low,
                endSensitivity: ActivityDetectionConfig.Sensitivity.Low,
                prefixPaddingMS: 20,
                silenceDurationMS: 500
            ),
            activityHandling: RealtimeInputConfig.ActivityHandling.Interrupt,
            turnCoverage: RealtimeInputConfig.TurnCoverage.OnlyActivity
        )
    )
);

利用可能な VAD 構成設定

設定 サポートされる値 説明
アクティビティの自動検出(automaticActivityDetection)
startSensitivity
  • LOW(デフォルト)
  • HIGH

ユーザーが話し始めたことをサーバーが検出する感度を決定します。

  • LOW: 小さな音に対する感度が低くなります。これにより、周囲のノイズによって音声ターンが誤って開始されるのを防ぐことができます。
  • HIGH: 高い感度。これにより、小さな声やささやき声をすばやく検出できます。
endSensitivity
  • LOW(デフォルト)
  • HIGH

ユーザーが話し終えたことをサーバーが検出するタイミングを決定します。

  • LOW: 末尾の一時停止に対する感度が低くなります。サーバーは、文末の自然なためらいや、より静かな単語に対応します。
  • HIGH: 高い感度。サーバーは、音声レベルが低下するとすぐに音声ターンを終了します。
prefixPadding ミリ秒単位の期間
(デフォルト: なし(0 ミリ秒))

音声が検出される前に含める音声の量を定義します。

この「ルックバック」バッファにより、モデルは音声の開始を完全にキャプチャできます。これには、検出機能がトリガーされる前に開始されることが多い最初の音節も含まれます。

  • 0 のデフォルト値を使用すると、単語の先頭が切り取られることがあります。
  • 推奨: 20 ~ 50 ミリ秒
silenceDuration ミリ秒単位の再生時間
(デフォルト: 約 800 ミリ秒)

音声ターンを終了する前に、サーバーが無音状態で待機する時間を定義します。これにより、システムが自然な文中のポーズ(思考、呼吸、節の境界など)をどの程度許容するかが決まります。

  • 推奨(500 ~ 800 ミリ秒): 適切なバランスを実現します。モデルは、コンテキストが豊富な完全な音声を受信しながら、レスポンス レイテンシを妥当な範囲に抑えます。
  • 低すぎる(200 ミリ秒未満): 自然な一時停止中に音声ターンを終了し、発話を小さなフラグメントに分割します。これにより、音声文字変換とレスポンスの品質が低下する可能性があります。
  • 高すぎる(2,000 ミリ秒超): モデルが応答を開始する前に、顕著な遅延が発生します。
割り込み動作(activityHandling)
activityHandling
  • INTERRUPT(デフォルト)
  • NO_INTERRUPT

レスポンスの生成中にサーバーが受信したユーザー アクティビティを処理する方法を定義します。

  • INTERRUPT: ユーザー アクティビティが検出されると、モデルの現在のレスポンスを直ちにキャンセルします。
  • NO_INTERRUPT: 中断することなくレスポンスの生成を続行します。
ターン コンテキスト カバレッジ(turnCoverage)
turnCoverage
  • ONLY_ACTIVITY(デフォルト)
  • ALL_INPUT
  • AUDIO_ACTIVITY_AND_ALL_VIDEO

会話ターンのコンテキストに含まれるストリーミング入力を定義します。

  • ONLY_ACTIVITY: 無音部分を除外し、ユーザー アクティビティが検出されたセグメントのみを保持します。
  • ALL_INPUT: 音声の無音部分を含む、ストリーミングされたすべての入力を保持します。
  • AUDIO_ACTIVITY_AND_ALL_VIDEO: ストリーミングされたすべての動画フレームを保持しますが、アクティビティが検出された音声セグメントのみを保持します。

割り込みを処理する

モデルがレスポンスを生成している間にサーバーがユーザーの音声入力を検出した場合、activityHandling が INTERRUPT(デフォルト)に設定されていると、次の動作に注意してください。

  • 生成がキャンセルされる: モデルはレスポンスを直ちに停止し、保留中のツール呼び出しを破棄します。

  • セッション履歴が切り捨てられる: 中断前にアプリに送信されたコンテンツのみがセッション コンテキスト ウィンドウに保持されます。

  • 中断シグナルが送信される: サーバーは、生成が中断されたことを示すレスポンス メッセージを送信します(Swift の wasInterrupted、Kotlin、Java、ウェブ、Flutter、Unity の interrupted など)。

自動音声検出(VAD)を無効にする

会話のターンを手動で完全に制御するには(プッシュ ツー トーク インターフェースなど)、感度パラメータを構成する代わりに、自動音声検出(VAD)を無効にします。

自動検出が無効になっている場合、サーバーは音声を自動的に検出したり、音声の無音に基づいてレスポンスをトリガーしたりしません。代わりに、アプリはアクティブなセッション中にユーザー アクティビティの境界を手動で通知する必要があります。

1. モデル構成で自動 VAD を無効にする

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

Swift


// ...

let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_API_MODEL_NAME",
  generationConfig: LiveGenerationConfig(
    responseModalities: [.audio],
    // Disable automatic voice activity detection (VAD).
    realtimeInputConfig: RealtimeInputConfig(
      automaticActivityDetection: .disabled()
    )
  )
)

Kotlin


// ...

val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
    modelName = "GEMINI_LIVE_API_MODEL_NAME",
    generationConfig = liveGenerationConfig {
        responseModality = ResponseModality.AUDIO
        // Disable automatic voice activity detection (VAD).
        realtimeInputConfig = realtimeInputConfig {
            automaticActivityDetection = ActivityDetectionConfig.disabled()
        }
    }
)

Java


// ...

LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
        "GEMINI_LIVE_API_MODEL_NAME",
        new LiveGenerationConfig.Builder()
                .setResponseModality(ResponseModality.AUDIO)
                // Disable automatic voice activity detection (VAD).
                .setRealtimeInputConfig(RealtimeInputConfig.builder()
                        .setAutomaticActivityDetection(ActivityDetectionConfig.disabled())
                        .build())
                .build()
);

Web

Not yet supported for Web apps - check back soon!

Dart


// ...

final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
  model: 'GEMINI_LIVE_API_MODEL_NAME',
  liveGenerationConfig: LiveGenerationConfig(
    responseModalities: [ResponseModalities.audio],
    // Disable automatic voice activity detection (VAD).
    realtimeInputConfig: RealtimeInputConfig(
      automaticActivityDetection: ActivityDetectionConfig.disabled(),
    ),
  ),
);

Unity


// ...

var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
    modelName: "GEMINI_LIVE_API_MODEL_NAME",
    liveGenerationConfig: new LiveGenerationConfig(
        responseModalities: new[] { ResponseModality.Audio },
        // Disable automatic voice activity detection (VAD).
        realtimeInputConfig: new RealtimeInputConfig(
            automaticActivityDetection: ActivityDetectionConfig.Disabled()
        )
    )
);

2. ユーザー アクティビティの境界を手動で通知する

VAD を無効にする場合、アプリは各ユーザー アクティビティ ターンの境界を手動で区切る必要があります。

  1. アクティビティの開始を通知する: 音声データを送信する前に sendStartActivityRealtime を呼び出します(ユーザーがプッシュツートーク ボタンを押したときなど)。

  2. ユーザー入力をストリーミングする: sendAudioRealtime を使用して、音声(または動画)データを継続的にストリーミングします。

  3. アクティビティの終了を通知する: ユーザーが話し終えたとき(ユーザーがプッシュツートーク ボタンを離したときなど)に sendStopActivityRealtime を呼び出します。これは、ユーザーのターンの終了を通知し、モデルのレスポンスをトリガーします。

Swift

// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.

// Signal the start of user activity (for example, on push-to-talk button press).
await session.sendStartActivityRealtime()

// Stream user audio data while the user speaks.
await session.sendAudioRealtime(audioData)

// Signal the end of user activity (for example, on button release) to trigger model response.
await session.sendStopActivityRealtime()

Kotlin

// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.

// Signal the start of user activity (for example, on push-to-talk button press).
session.sendStartActivityRealtime()

// Stream user audio data while the user speaks.
session.sendAudioRealtime(audioData)

// Signal the end of user activity (for example, on button release) to trigger model response.
session.sendStopActivityRealtime()

Java

// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.

// Signal the start of user activity (for example, on push-to-talk button press).
session.sendStartActivityRealtime();

// Stream user audio data while the user speaks.
session.sendAudioRealtime(audioData);

// Signal the end of user activity (for example, on button release) to trigger model response.
session.sendStopActivityRealtime();

Web

Not yet supported for Web apps - check back soon!

Dart

// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.

// Signal the start of user activity (for example, on push-to-talk button press).
await session.sendStartActivityRealtime();

// Stream user audio data while the user speaks.
await session.sendAudioRealtime(audioData);

// Signal the end of user activity (for example, on button release) to trigger model response.
await session.sendStopActivityRealtime();

Unity

// If you disable automatic voice activity detection (VAD), you need to manually demarcate user activity.

// Signal the start of user activity (for example, on push-to-talk button press).
await session.SendStartActivityRealtimeAsync();

// Stream user audio data while the user speaks.
await session.SendAudioRealtimeAsync(audio: audioData);

// Signal the end of user activity (for example, on button release) to trigger model response.
await session.SendStopActivityRealtimeAsync();



セッション管理

セッションに関連する次のトピックについて説明します。