@ai-sdk/google-vertex 5.0.143 → 5.0.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["GoogleVertexMaasProviderSettings","GoogleVertexMaasProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/google-vertex-model-catalog.ts","../../../src/maas/google-vertex-maas-options.ts","../../../src/maas/google-vertex-maas-provider.ts","../../../src/maas/edge/google-vertex-maas-provider-edge.ts"],"mappings":";;;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;cCoTI;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KC/nBT,0BACR;;;UCqBa,iCAAiC,yBAChD;UAMeA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC3CO,yCAAyCC;;;;;;EAMxD,oBAAoB;;;;;;;;;wBAUN,uBACd,UAAS,mCACR;;;;qBAqDU,kBAAgB"}
1
+ {"version":3,"file":"index.d.ts","names":["GoogleVertexMaasProviderSettings","GoogleVertexMaasProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/google-vertex-model-catalog.ts","../../../src/maas/google-vertex-maas-options.ts","../../../src/maas/google-vertex-maas-provider.ts","../../../src/maas/edge/google-vertex-maas-provider-edge.ts"],"mappings":";;;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;cCqTI;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KChoBT,0BACR;;;UCqBa,iCAAiC,yBAChD;UAMeA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC3CO,yCAAyCC;;;;;;EAMxD,oBAAoB;;;;;;;;;wBAUN,uBACd,UAAS,mCACR;;;;qBAqDU,kBAAgB"}
@@ -2,7 +2,7 @@ import { fetchWithValidatedEndpoint, getRuntimeEnvironmentUserAgent, isBrowserRu
2
2
  import { InvalidArgumentError } from "@ai-sdk/provider";
3
3
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
4
4
  //#region src/version.ts
5
- const VERSION = "5.0.143";
5
+ const VERSION = "5.0.144";
6
6
  //#endregion
7
7
  //#region src/edge/google-vertex-auth-edge.ts
8
8
  const loadCredentials = async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["GoogleVertexMaasProviderSettings","GoogleVertexMaasProviderSettingsOriginal"],"sources":["../../src/google-vertex-model-catalog.ts","../../src/maas/google-vertex-maas-options.ts","../../src/maas/google-vertex-maas-provider.ts","../../src/maas/google-vertex-maas-provider-node.ts"],"mappings":";;;;;cA6UM;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KC/nBT,0BACR;;;UCqBa,iCAAiC,yBAChD;UAMeA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC7CO,yCAAyCC;;;;;;;EAOxD,oBAAoB;;;;;;;;;wBAUN,uBACd,UAAS,mCACR;;;;qBAuDU,kBAAgB"}
1
+ {"version":3,"file":"index.d.ts","names":["GoogleVertexMaasProviderSettings","GoogleVertexMaasProviderSettingsOriginal"],"sources":["../../src/google-vertex-model-catalog.ts","../../src/maas/google-vertex-maas-options.ts","../../src/maas/google-vertex-maas-provider.ts","../../src/maas/google-vertex-maas-provider-node.ts"],"mappings":";;;;;cA8UM;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KChoBT,0BACR;;;UCqBa,iCAAiC,yBAChD;UAMeA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC7CO,yCAAyCC;;;;;;;EAOxD,oBAAoB;;;;;;;;;wBAUN,uBACd,UAAS,mCACR;;;;qBAuDU,kBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["GoogleVertexXaiProviderSettings","GoogleVertexXaiProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/google-vertex-model-catalog.ts","../../../src/xai/google-vertex-xai-options.ts","../../../src/xai/google-vertex-xai-provider.ts","../../../src/xai/edge/google-vertex-xai-provider-edge.ts"],"mappings":";;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;cCoTI;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KC/nBT,yBACR;;;UCea,gCAAgC;;;;GAI9C,SAAS,yBAAyB;;;;EAKnC,cAAc,SAAS,yBAAyB;;;;EAKhD,UAAU,SAAS,yBAAyB;;;;EAK5C,mBAAmB;;UAGJA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC3DO,wCAAwCC;;;;;;EAMvD,oBAAoB;;;;;;;;;wBAUN,sBACd,UAAS,kCACR;;;;qBA8BU,iBAAe"}
1
+ {"version":3,"file":"index.d.ts","names":["GoogleVertexXaiProviderSettings","GoogleVertexXaiProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/google-vertex-model-catalog.ts","../../../src/xai/google-vertex-xai-options.ts","../../../src/xai/google-vertex-xai-provider.ts","../../../src/xai/edge/google-vertex-xai-provider-edge.ts"],"mappings":";;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;cCqTI;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KChoBT,yBACR;;;UCea,gCAAgC;;;;GAI9C,SAAS,yBAAyB;;;;EAKnC,cAAc,SAAS,yBAAyB;;;;EAKhD,UAAU,SAAS,yBAAyB;;;;EAK5C,mBAAmB;;UAGJA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC3DO,wCAAwCC;;;;;;EAMvD,oBAAoB;;;;;;;;;wBAUN,sBACd,UAAS,kCACR;;;;qBA8BU,iBAAe"}
@@ -2,7 +2,7 @@ import { getRuntimeEnvironmentUserAgent, loadOptionalSetting, loadSetting, resol
2
2
  import { NoSuchModelError } from "@ai-sdk/provider";
3
3
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
4
4
  //#region src/version.ts
5
- const VERSION = "5.0.143";
5
+ const VERSION = "5.0.144";
6
6
  //#endregion
7
7
  //#region src/edge/google-vertex-auth-edge.ts
8
8
  const loadCredentials = async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["GoogleVertexXaiProviderSettings","GoogleVertexXaiProviderSettingsOriginal"],"sources":["../../src/google-vertex-model-catalog.ts","../../src/xai/google-vertex-xai-options.ts","../../src/xai/google-vertex-xai-provider.ts","../../src/xai/google-vertex-xai-provider-node.ts"],"mappings":";;;;cA6UM;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KC/nBT,yBACR;;;UCea,gCAAgC;;;;GAI9C,SAAS,yBAAyB;;;;EAKnC,cAAc,SAAS,yBAAyB;;;;EAKhD,UAAU,SAAS,yBAAyB;;;;EAK5C,mBAAmB;;UAGJA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC7DO,wCAAwCC;;;;;;;EAOvD,oBAAoB;;;;;;;;;wBAUN,sBACd,UAAS,kCACR;;;;qBAgCU,iBAAe"}
1
+ {"version":3,"file":"index.d.ts","names":["GoogleVertexXaiProviderSettings","GoogleVertexXaiProviderSettingsOriginal"],"sources":["../../src/google-vertex-model-catalog.ts","../../src/xai/google-vertex-xai-options.ts","../../src/xai/google-vertex-xai-provider.ts","../../src/xai/google-vertex-xai-provider-node.ts"],"mappings":";;;;cA8UM;cAuCA;cAOA;cAcA;cAcA;cAQA;cAEA;cA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0GA;;;;;;;;;;;;;;cA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCM;EACV,kBAAkB;EAClB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,uBAAuB;EACvB,6BAA6B;EAC7B,wBAAwB;EACxB,kBAAkB;EAClB,mBAAmB;;;;KChoBT,yBACR;;;UCea,gCAAgC;;;;GAI9C,SAAS,yBAAyB;;;;EAKnC,cAAc,SAAS,yBAAyB;;;;EAKhD,UAAU,SAAS,yBAAyB;;;;EAK5C,mBAAmB;;UAGJA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC7DO,wCAAwCC;;;;;;;EAOvD,oBAAoB;;;;;;;;;wBAUN,sBACd,UAAS,kCACR;;;;qBAgCU,iBAAe"}
@@ -1494,6 +1494,40 @@ Gemini does not provide separate caption segments and warns if `'segment'` is
1494
1494
  requested. These shared timing controls currently apply to Gemini transcription;
1495
1495
  Chirp and telephony use their provider settings below.
1496
1496
 
1497
+ `gemini-3.5-transcribe-live` transcribes live audio with
1498
+ [`experimental_streamTranscribe`](/docs/ai-sdk-core/transcription#streaming-transcription)
1499
+ over the Vertex Live API. It authenticates with an `Authorization` header, which
1500
+ native WebSockets cannot send, so pass a header-capable implementation such as
1501
+ the `ws` package:
1502
+
1503
+ ```ts
1504
+ import {
1505
+ createVertex,
1506
+ type GoogleVertexProviderSettings,
1507
+ } from '@ai-sdk/google-vertex';
1508
+ import { experimental_streamTranscribe as streamTranscribe } from 'ai';
1509
+ import { WebSocket } from 'ws';
1510
+
1511
+ const vertex = createVertex({
1512
+ // `ws`'s WebSocket type differs from the DOM-style WebSocketConstructor.
1513
+ webSocket: WebSocket as unknown as GoogleVertexProviderSettings['webSocket'],
1514
+ });
1515
+
1516
+ const result = streamTranscribe({
1517
+ model: vertex.transcription('gemini-3.5-transcribe-live'),
1518
+ audio, // ReadableStream of 16kHz 16-bit mono PCM chunks
1519
+ inputAudioFormat: { type: 'audio/pcm', rate: 16000 },
1520
+ });
1521
+ ```
1522
+
1523
+ By default, server-side voice activity detection splits the audio into segments
1524
+ at pauses, and each segment is emitted as a `transcript-final` part. For
1525
+ push-to-talk input, set
1526
+ `providerOptions.googleVertex.streaming.automaticActivityDetection.disabled` to
1527
+ `true`: the whole audio stream is then transcribed as a single turn without
1528
+ splitting at pauses, and the transcript is finalized as soon as the audio input
1529
+ closes.
1530
+
1497
1531
  #### Speech-to-Text transcription
1498
1532
 
1499
1533
  You can transcribe audio with Google Cloud Speech-to-Text models using the
@@ -2590,6 +2624,7 @@ The following option definitions are generated from the provider catalog.
2590
2624
  | transcription | `wordTimestamp` | Include Gemini word timestamps. |
2591
2625
  | transcription | `diarization` | Enable Gemini speaker diarization. |
2592
2626
  | transcription | `mode` | Verbatim or smart Gemini transcription formatting. |
2627
+ | transcription | `streaming` | Live Gemini voice activity detection. |
2593
2628
  | video | `pollIntervalMs` | Polling interval. |
2594
2629
  | video | `pollTimeoutMs` | Polling timeout. |
2595
2630
  | video | `personGeneration` | Policy for generating people. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google-vertex",
3
- "version": "5.0.143",
3
+ "version": "5.0.144",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@ai-sdk/anthropic": "4.0.107",
75
- "@ai-sdk/google": "4.0.123",
75
+ "@ai-sdk/google": "4.0.124",
76
76
  "@ai-sdk/openai-compatible": "3.0.94",
77
77
  "@ai-sdk/provider": "4.0.39",
78
78
  "@ai-sdk/provider-utils": "5.0.83",
@@ -51,6 +51,29 @@ export const googleVertexGeminiTranscriptionModelOptions = lazySchema(() =>
51
51
  * (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
52
52
  */
53
53
  mode: z.enum(['SMART', 'VERBATIM']).optional(),
54
+
55
+ /**
56
+ * Options for live transcription models such as
57
+ * `gemini-3.5-transcribe-live`.
58
+ */
59
+ streaming: z
60
+ .object({
61
+ /**
62
+ * Server-side voice activity detection, which splits the audio into
63
+ * segments at pauses (enabled by default).
64
+ *
65
+ * Set `disabled: true` for push-to-talk input: the whole audio
66
+ * stream is then transcribed as a single turn, without splitting at
67
+ * pauses, and the transcript is finalized as soon as the audio
68
+ * stream ends.
69
+ */
70
+ automaticActivityDetection: z
71
+ .object({
72
+ disabled: z.boolean().optional(),
73
+ })
74
+ .optional(),
75
+ })
76
+ .optional(),
54
77
  }),
55
78
  ),
56
79
  );
@@ -40,12 +40,19 @@ const liveWebSocketPath =
40
40
  'google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent';
41
41
 
42
42
  /**
43
- * After the input audio has ended, finish when no terminal signal
44
- * (`turnComplete` / idle `interactionStatus`) arrives within this window.
43
+ * After the input audio has ended, finish when no terminal signal (idle
44
+ * `interactionStatus`, `turnComplete`, or server VAD showing that all audio
45
+ * was transcribed) arrives within this window.
45
46
  * Trailing transcripts reset the timer.
46
47
  */
47
48
  const defaultFinishGraceMs = 3000;
48
49
 
50
+ /**
51
+ * Speech that server VAD ended within this distance of the end of the sent
52
+ * audio counts as ending at the end of the audio.
53
+ */
54
+ const audioEndToleranceMs = 250;
55
+
49
56
  /** Live transcription is only supported by `*-live` model variants. */
50
57
  function isLiveTranscriptionModelId(modelId: string): boolean {
51
58
  return getGoogleVertexRequestConfig(modelId).transcription?.live === true;
@@ -85,6 +92,7 @@ type GoogleLiveServerMessage = {
85
92
  interactionStatus?: string;
86
93
  };
87
94
  inputTranscription?: GoogleLiveTranscription;
95
+ voiceActivity?: { type?: string; audioOffset?: string };
88
96
  usageMetadata?: JSONObject;
89
97
  error?: { message?: string };
90
98
  };
@@ -336,6 +344,9 @@ export class GoogleVertexGeminiTranscriptionModel implements TranscriptionModelV
336
344
  `wss://${vertexHost(location)}/ws/${liveWebSocketPath}`,
337
345
  );
338
346
 
347
+ const manualActivityDetection =
348
+ googleOptions?.streaming?.automaticActivityDetection?.disabled === true;
349
+
339
350
  // NOTE: mirrors the Developer API model — Google's documented setup shape
340
351
  // includes `generationConfig.responseModalities: ['TEXT']`, but sending it
341
352
  // suppresses the final `inputTranscription` segments; omit generationConfig.
@@ -343,6 +354,13 @@ export class GoogleVertexGeminiTranscriptionModel implements TranscriptionModelV
343
354
  model: modelResource,
344
355
  inputAudioTranscription:
345
356
  buildAudioTranscriptionConfig(googleOptions) ?? {},
357
+ ...(manualActivityDetection
358
+ ? {
359
+ realtimeInputConfig: {
360
+ automaticActivityDetection: { disabled: true },
361
+ },
362
+ }
363
+ : {}),
346
364
  };
347
365
 
348
366
  return {
@@ -357,6 +375,7 @@ export class GoogleVertexGeminiTranscriptionModel implements TranscriptionModelV
357
375
  headers,
358
376
  setup,
359
377
  inputAudioRate: options.inputAudioFormat.rate ?? 16000,
378
+ manualActivityDetection,
360
379
  finishGraceMs:
361
380
  this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
362
381
  warnings,
@@ -374,6 +393,7 @@ function createVertexLiveTranscriptionStream({
374
393
  headers,
375
394
  setup,
376
395
  inputAudioRate,
396
+ manualActivityDetection,
377
397
  finishGraceMs,
378
398
  warnings,
379
399
  audio,
@@ -385,6 +405,7 @@ function createVertexLiveTranscriptionStream({
385
405
  headers: Record<string, string | undefined>;
386
406
  setup: unknown;
387
407
  inputAudioRate: number;
408
+ manualActivityDetection: boolean;
388
409
  finishGraceMs: number;
389
410
  warnings: SharedV4Warning[];
390
411
  audio: ReadableStream<Uint8Array | string>;
@@ -412,7 +433,8 @@ function createVertexLiveTranscriptionStream({
412
433
  // Google Live messages carry no response/item IDs; a segment counter
413
434
  // generates consistent synthetic IDs. Transcription fragments arrive
414
435
  // incrementally and are accumulated per segment; a `finished: true`
415
- // transcription or `turnComplete` finalizes the current segment.
436
+ // transcription, `generationComplete`, or `turnComplete` finalizes the
437
+ // current segment.
416
438
  let segmentCounter = 0;
417
439
  let segmentBuffer = '';
418
440
  let fullText = '';
@@ -423,6 +445,11 @@ function createVertexLiveTranscriptionStream({
423
445
  let audioEnded = false;
424
446
  let usageMetadata: JSONObject | undefined;
425
447
  let finishTimer: ReturnType<typeof setTimeout> | undefined;
448
+ // latest server VAD signal (`ACTIVITY_START` / `ACTIVITY_END`)
449
+ let lastVoiceActivity:
450
+ | { type: string; audioOffsetMs: number | undefined }
451
+ | undefined;
452
+ let sentAudioBytes = 0;
426
453
 
427
454
  const segmentId = () => `google-segment-${segmentCounter}`;
428
455
 
@@ -481,6 +508,23 @@ function createVertexLiveTranscriptionStream({
481
508
  segmentCounter++;
482
509
  };
483
510
 
511
+ const getSentAudioMs = () =>
512
+ (sentAudioBytes / (inputAudioRate * 2)) * 1000;
513
+
514
+ // Once the audio has ended, the server has transcribed all of it when
515
+ // server VAD ended the last speech at the end of the sent audio and no
516
+ // transcript is pending. VAD ends speech at the end of the audio when
517
+ // the audio ends mid-speech (the server transcribes the rest as one
518
+ // segment) and, with manual activity detection, always (`activityEnd`
519
+ // closes the single turn). Earlier `ACTIVITY_END` offsets can mean the
520
+ // server is still processing buffered audio with further segments.
521
+ const isTranscriptionComplete = () =>
522
+ lastVoiceActivity?.type === 'ACTIVITY_END' &&
523
+ segmentBuffer === '' &&
524
+ latestInterim === '' &&
525
+ (lastVoiceActivity.audioOffsetMs ?? 0) >=
526
+ getSentAudioMs() - audioEndToleranceMs;
527
+
484
528
  const finish = () => {
485
529
  if (finished) return;
486
530
  completeSegment();
@@ -503,16 +547,27 @@ function createVertexLiveTranscriptionStream({
503
547
  };
504
548
 
505
549
  const sendAudio = async (socket: WebSocketLike) => {
550
+ // with manual activity detection, the audio stream is one user turn
551
+ if (manualActivityDetection) {
552
+ socket.send(JSON.stringify({ realtimeInput: { activityStart: {} } }));
553
+ }
506
554
  audioReader = audio.getReader();
507
555
  try {
508
556
  while (true) {
509
557
  const { done, value } = await audioReader.read();
510
558
  if (done || finished) break;
559
+ const data = convertToBase64(value);
560
+ const padding = data.endsWith('==')
561
+ ? 2
562
+ : data.endsWith('=')
563
+ ? 1
564
+ : 0;
565
+ sentAudioBytes += (data.length * 3) / 4 - padding;
511
566
  socket.send(
512
567
  JSON.stringify({
513
568
  realtimeInput: {
514
569
  audio: {
515
- data: convertToBase64(value),
570
+ data,
516
571
  mimeType: `audio/pcm;rate=${inputAudioRate}`,
517
572
  },
518
573
  },
@@ -528,10 +583,18 @@ function createVertexLiveTranscriptionStream({
528
583
  }
529
584
  if (!finished) {
530
585
  socket.send(
531
- JSON.stringify({ realtimeInput: { audioStreamEnd: true } }),
586
+ JSON.stringify({
587
+ realtimeInput: manualActivityDetection
588
+ ? { activityEnd: {} }
589
+ : { audioStreamEnd: true },
590
+ }),
532
591
  );
533
592
  audioEnded = true;
534
- schedulePendingFinish();
593
+ if (isTranscriptionComplete()) {
594
+ finish();
595
+ } else {
596
+ schedulePendingFinish();
597
+ }
535
598
  }
536
599
  };
537
600
 
@@ -568,6 +631,19 @@ function createVertexLiveTranscriptionStream({
568
631
  usageMetadata = message.usageMetadata;
569
632
  }
570
633
 
634
+ if (message.voiceActivity?.type != null) {
635
+ const audioOffsetSeconds = parseOffsetSeconds(
636
+ message.voiceActivity.audioOffset,
637
+ );
638
+ lastVoiceActivity = {
639
+ type: message.voiceActivity.type,
640
+ audioOffsetMs:
641
+ audioOffsetSeconds != null
642
+ ? audioOffsetSeconds * 1000
643
+ : undefined,
644
+ };
645
+ }
646
+
571
647
  if (message.error != null) {
572
648
  finishWithError(
573
649
  new Error(message.error.message ?? 'Vertex Live API error'),
@@ -611,7 +687,12 @@ function createVertexLiveTranscriptionStream({
611
687
  }
612
688
  }
613
689
 
614
- if (serverContent?.turnComplete) {
690
+ // `gemini-3.5-transcribe-live` ends each segment with
691
+ // `generationComplete` and never sends `turnComplete`.
692
+ if (
693
+ serverContent?.generationComplete ||
694
+ serverContent?.turnComplete
695
+ ) {
615
696
  completeSegment();
616
697
  }
617
698
 
@@ -624,7 +705,8 @@ function createVertexLiveTranscriptionStream({
624
705
  (interactionStatus === 'IDLE' ||
625
706
  interactionStatus === 'REQUIRES_ACTION' ||
626
707
  (serverContent?.turnComplete === true &&
627
- interactionStatus == null))
708
+ interactionStatus == null) ||
709
+ isTranscriptionComplete())
628
710
  ) {
629
711
  finish();
630
712
  }
@@ -150,6 +150,7 @@ export const googleVertexProviderOptions = {
150
150
  wordTimestamp: { description: 'Include Gemini word timestamps.' },
151
151
  diarization: { description: 'Enable Gemini speaker diarization.' },
152
152
  mode: { description: 'Verbatim or smart Gemini transcription formatting.' },
153
+ streaming: { description: 'Live Gemini voice activity detection.' },
153
154
  } satisfies Record<
154
155
  | keyof GoogleVertexTranscriptionModelOptions
155
156
  | keyof GoogleVertexTranscriptionModelGeminiOptions,