@framers/agentos-ext-google-cloud-stt 0.2.0 → 0.3.0

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.
package/LICENSE CHANGED
@@ -1,23 +1,98 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Framers
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License.
30
+
31
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License.
34
+
35
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution.
38
+
39
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
40
+
41
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
42
+
43
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+
45
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+
47
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work.
74
+
75
+ To apply the Apache License to your work, attach the following
76
+ boilerplate notice, with the fields enclosed by brackets "[]"
77
+ replaced with your own identifying information. (Don't include
78
+ the brackets!) The text should be enclosed in the appropriate
79
+ comment syntax for the file format. We also recommend that a
80
+ file or class name and description of purpose be included on the
81
+ same "printed page" as the copyright notice for easier
82
+ identification within third-party archives.
83
+
84
+ Copyright (c) 2025 Framers
85
+
86
+ Licensed under the Apache License, Version 2.0 (the "License");
87
+ you may not use this file except in compliance with the License.
88
+ You may obtain a copy of the License at
89
+
90
+ http://www.apache.org/licenses/LICENSE-2.0
91
+
92
+ Unless required by applicable law or agreed to in writing, software
93
+ distributed under the License is distributed on an "AS IS" BASIS,
94
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95
+ See the License for the specific language governing permissions and
96
+ limitations under the License.
22
97
 
23
98
 
package/SKILL.md CHANGED
@@ -14,12 +14,14 @@ Provide credentials via the `GOOGLE_CLOUD_STT_CREDENTIALS` secret. Accepts eithe
14
14
  - An absolute path to a service-account JSON key file (contains `/` or `\`)
15
15
  - A raw JSON string with the service-account credentials
16
16
 
17
+ Leave the secret unset to use Google's Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`, `gcloud auth application-default login`, or the metadata server on Google Cloud).
18
+
17
19
  ## Features
18
20
 
19
- - LINEAR16 PCM audio transcription
21
+ - WAV and FLAC files (Google reads the encoding and sample rate from the header) and raw LINEAR16 PCM
20
22
  - Configurable language code (BCP-47)
21
- - Confidence scores and word-level alternatives
22
- - Maps to standard `SpeechTranscriptionResult` shape
23
+ - Returns the AgentOS `SpeechTranscriptionResult`: `text` (each stretch's most likely transcript, in order), mean `confidence`, `isFinal`, and `segments` with timing when Google reports end times
24
+ - Batch only (`supportsStreaming: false`)
23
25
 
24
26
  ## Configuration
25
27
 
@@ -10,18 +10,39 @@
10
10
  * @module google-cloud-stt
11
11
  */
12
12
  /**
13
- * A single recognised audio segment returned by the provider.
14
- *
15
- * Mirrors the generic `SpeechTranscriptionResult` shape used across the
16
- * AgentOS voice pipeline.
13
+ * One stretch of recognised speech: Google returns a result per consecutive
14
+ * portion of the audio.
15
+ */
16
+ export interface SpeechTranscriptionSegment {
17
+ /** The most likely transcript of this stretch. */
18
+ text: string;
19
+ /** Start in seconds from the beginning of the audio. */
20
+ startTime: number;
21
+ /** End in seconds from the beginning of the audio. */
22
+ endTime: number;
23
+ /** Confidence score in [0, 1], when Google reports one. */
24
+ confidence?: number;
25
+ }
26
+ /**
27
+ * The transcription result of the AgentOS `SpeechToTextProvider` contract
28
+ * (`SpeechTranscriptionResult` in `@framers/agentos`), mirrored here so the
29
+ * pack carries no type import from agentos.
17
30
  */
18
31
  export interface SpeechTranscriptionResult {
19
- /** The recognised text. */
20
- transcript: string;
21
- /** Confidence score in [0, 1]. */
22
- confidence: number;
23
- /** Whether this is a final (non-speculative) result. Always `true` for batch. */
32
+ /** The recognised text: every stretch's most likely transcript, in order. */
33
+ text: string;
34
+ /** BCP-47 language of the transcript. */
35
+ language?: string;
36
+ /** Mean confidence of the stretches, in [0, 1], when Google reports any. */
37
+ confidence?: number;
38
+ /** Always `true`: batch recognition returns final results only. */
24
39
  isFinal: boolean;
40
+ /** Always 0; cost is tracked above the provider, as for AgentOS's core batch providers. */
41
+ cost: number;
42
+ /** Per-stretch transcripts with their timing, when Google reports end times. */
43
+ segments?: SpeechTranscriptionSegment[];
44
+ /** The raw `RecognizeResponse`. */
45
+ providerResponse?: unknown;
25
46
  }
26
47
  /**
27
48
  * Per-call transcription options forwarded to the Google Cloud API.
@@ -31,13 +52,18 @@ export interface GoogleCloudSTTOptions {
31
52
  language?: string;
32
53
  }
33
54
  /**
34
- * Audio frame passed to {@link GoogleCloudSTTProvider.transcribe}.
55
+ * Audio passed to {@link GoogleCloudSTTProvider.transcribe}: the fields of the
56
+ * AgentOS `SpeechAudioInput` this provider reads.
35
57
  */
36
58
  export interface AudioData {
37
- /** Raw PCM bytes (LINEAR16). */
59
+ /** The audio bytes: a WAV or FLAC file, or raw LINEAR16 PCM. */
38
60
  data: Buffer;
39
- /** Sample rate in Hz. @defaultValue `16000` */
61
+ /** Sample rate in Hz. Raw PCM defaults to 16000; a WAV or FLAC header supplies its own. */
40
62
  sampleRate?: number;
63
+ /** MIME type, such as `'audio/wav'` or `'audio/flac'`. */
64
+ mimeType?: string;
65
+ /** Container format, such as `'wav'` or `'flac'`. */
66
+ format?: string;
41
67
  }
42
68
  /**
43
69
  * Google Cloud Speech-to-Text batch provider.
@@ -49,6 +75,10 @@ export interface AudioData {
49
75
  export declare class GoogleCloudSTTProvider {
50
76
  /** Stable provider identifier used by the AgentOS extension registry. */
51
77
  readonly id = "google-cloud-stt";
78
+ /** Human-readable provider name. */
79
+ readonly displayName = "Google Cloud Speech-to-Text";
80
+ /** Batch recognition only: this provider does not stream. */
81
+ readonly supportsStreaming = false;
52
82
  /** Lazily initialised Speech client. */
53
83
  private _client;
54
84
  /** Resolved client constructor options (set in constructor, used in {@link _getClient}). */
@@ -57,8 +87,9 @@ export declare class GoogleCloudSTTProvider {
57
87
  * Create a new {@link GoogleCloudSTTProvider}.
58
88
  *
59
89
  * @param credentials - Either an absolute path to a service-account JSON key
60
- * file (any string that contains `/` or `\`) or a JSON string containing
61
- * the service-account credentials object.
90
+ * file (any string that contains `/` or `\`), a JSON string containing
91
+ * the service-account credentials object, or an empty string, which
92
+ * leaves the client on Google's Application Default Credentials.
62
93
  */
63
94
  constructor(credentials: string);
64
95
  /**
@@ -69,16 +100,22 @@ export declare class GoogleCloudSTTProvider {
69
100
  */
70
101
  private _getClient;
71
102
  /**
72
- * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
103
+ * The provider's display name, as the AgentOS speech contract requires.
104
+ *
105
+ * @returns `'Google Cloud Speech-to-Text'`.
106
+ */
107
+ getProviderName(): string;
108
+ /**
109
+ * Transcribe an audio file or raw PCM buffer using Google Cloud Speech-to-Text.
73
110
  *
74
- * The audio must be encoded as LINEAR16 (raw PCM, 16-bit little-endian).
75
- * The method returns all recognised alternatives from the first result, each
76
- * mapped to a {@link SpeechTranscriptionResult}.
111
+ * Google returns one result per consecutive stretch of the audio, each with
112
+ * its alternatives ordered by likelihood. The transcript is every stretch's
113
+ * first alternative, in order.
77
114
  *
78
- * @param audio - Audio frame containing the raw PCM bytes and sample rate.
115
+ * @param audio - WAV or FLAC file bytes, or raw LINEAR16 PCM with its sample rate.
79
116
  * @param options - Optional per-call parameters (language code).
80
- * @returns Array of transcription results ordered by confidence (descending).
117
+ * @returns The transcription in the AgentOS `SpeechTranscriptionResult` shape.
81
118
  */
82
- transcribe(audio: AudioData, options?: GoogleCloudSTTOptions): Promise<SpeechTranscriptionResult[]>;
119
+ transcribe(audio: AudioData, options?: GoogleCloudSTTOptions): Promise<SpeechTranscriptionResult>;
83
120
  }
84
121
  //# sourceMappingURL=GoogleCloudSTTProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleCloudSTTProvider.d.ts","sourceRoot":"","sources":["../src/GoogleCloudSTTProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,sBAAsB;IACjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE,sBAAsB;IAEjC,wCAAwC;IACxC,OAAO,CAAC,OAAO,CAA6B;IAE5C,4FAA4F;IAC5F,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;IAEzD;;;;;;OAMG;gBACS,WAAW,EAAE,MAAM;IAc/B;;;;;OAKG;YACW,UAAU;IAaxB;;;;;;;;;;OAUG;IACG,UAAU,CACd,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,yBAAyB,EAAE,CAAC;CA2BxC"}
1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7D,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,wCAAwC;IACxC,OAAO,CAAC,OAAO,CAA6B;IAE5C,4FAA4F;IAC5F,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;IAEzD;;;;;;;OAOG;gBACS,WAAW,EAAE,MAAM;IAmB/B;;;;;OAKG;YACW,UAAU;IAaxB;;;;OAIG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;;;;;;;OAUG;IACG,UAAU,CACd,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,yBAAyB,CAAC;CA0CtC"}
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * @file GoogleCloudSTTProvider.ts
3
4
  * @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
@@ -9,6 +10,29 @@
9
10
  *
10
11
  * @module google-cloud-stt
11
12
  */
13
+ /**
14
+ * The encoding fields of the recognition config for this audio.
15
+ *
16
+ * WAV and FLAC files carry a header that states the encoding and sample rate.
17
+ * Google reads both from it and rejects a request whose stated values disagree
18
+ * (google.cloud.speech.v1 `RecognitionConfig`), so for those formats the
19
+ * encoding is left out and the sample rate is sent only when the caller gives
20
+ * one. Anything else is sent as raw LINEAR16 PCM.
21
+ */
22
+ function encodingFor(audio) {
23
+ const declared = `${audio.mimeType ?? ''} ${audio.format ?? ''}`.toLowerCase();
24
+ if (declared.includes('wav') || declared.includes('flac')) {
25
+ return audio.sampleRate ? { sampleRateHertz: audio.sampleRate } : {};
26
+ }
27
+ return { encoding: 'LINEAR16', sampleRateHertz: audio.sampleRate ?? 16000 };
28
+ }
29
+ /** Seconds in a protobuf `Duration` (`{ seconds, nanos }`, seconds possibly a string). */
30
+ function durationSeconds(duration) {
31
+ if (!duration)
32
+ return undefined;
33
+ const seconds = Number(duration.seconds ?? 0) + Number(duration.nanos ?? 0) / 1e9;
34
+ return Number.isFinite(seconds) ? seconds : undefined;
35
+ }
12
36
  /**
13
37
  * Google Cloud Speech-to-Text batch provider.
14
38
  *
@@ -19,6 +43,10 @@
19
43
  export class GoogleCloudSTTProvider {
20
44
  /** Stable provider identifier used by the AgentOS extension registry. */
21
45
  id = 'google-cloud-stt';
46
+ /** Human-readable provider name. */
47
+ displayName = 'Google Cloud Speech-to-Text';
48
+ /** Batch recognition only: this provider does not stream. */
49
+ supportsStreaming = false;
22
50
  /** Lazily initialised Speech client. */
23
51
  _client = null;
24
52
  /** Resolved client constructor options (set in constructor, used in {@link _getClient}). */
@@ -27,11 +55,18 @@ export class GoogleCloudSTTProvider {
27
55
  * Create a new {@link GoogleCloudSTTProvider}.
28
56
  *
29
57
  * @param credentials - Either an absolute path to a service-account JSON key
30
- * file (any string that contains `/` or `\`) or a JSON string containing
31
- * the service-account credentials object.
58
+ * file (any string that contains `/` or `\`), a JSON string containing
59
+ * the service-account credentials object, or an empty string, which
60
+ * leaves the client on Google's Application Default Credentials.
32
61
  */
33
62
  constructor(credentials) {
34
- if (credentials.includes('/') || credentials.includes('\\')) {
63
+ if (!credentials.trim()) {
64
+ // No key given: the Google client finds Application Default Credentials
65
+ // (GOOGLE_APPLICATION_CREDENTIALS, gcloud, or the metadata server) when
66
+ // it is first used, so the pack still loads without a configured secret.
67
+ this._clientOptions = {};
68
+ }
69
+ else if (credentials.includes('/') || credentials.includes('\\')) {
35
70
  // Treat as a file path.
36
71
  this._clientOptions = { keyFilename: credentials };
37
72
  }
@@ -61,38 +96,62 @@ export class GoogleCloudSTTProvider {
61
96
  // Public API
62
97
  // ---------------------------------------------------------------------------
63
98
  /**
64
- * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
99
+ * The provider's display name, as the AgentOS speech contract requires.
100
+ *
101
+ * @returns `'Google Cloud Speech-to-Text'`.
102
+ */
103
+ getProviderName() {
104
+ return this.displayName;
105
+ }
106
+ /**
107
+ * Transcribe an audio file or raw PCM buffer using Google Cloud Speech-to-Text.
65
108
  *
66
- * The audio must be encoded as LINEAR16 (raw PCM, 16-bit little-endian).
67
- * The method returns all recognised alternatives from the first result, each
68
- * mapped to a {@link SpeechTranscriptionResult}.
109
+ * Google returns one result per consecutive stretch of the audio, each with
110
+ * its alternatives ordered by likelihood. The transcript is every stretch's
111
+ * first alternative, in order.
69
112
  *
70
- * @param audio - Audio frame containing the raw PCM bytes and sample rate.
113
+ * @param audio - WAV or FLAC file bytes, or raw LINEAR16 PCM with its sample rate.
71
114
  * @param options - Optional per-call parameters (language code).
72
- * @returns Array of transcription results ordered by confidence (descending).
115
+ * @returns The transcription in the AgentOS `SpeechTranscriptionResult` shape.
73
116
  */
74
117
  async transcribe(audio, options) {
75
118
  const client = await this._getClient();
119
+ const languageCode = options?.language ?? 'en-US';
76
120
  const response = await client.recognize({
77
121
  audio: { content: audio.data.toString('base64') },
78
- config: {
79
- encoding: 'LINEAR16',
80
- sampleRateHertz: audio.sampleRate ?? 16000,
81
- languageCode: options?.language ?? 'en-US',
82
- },
122
+ config: { ...encodingFor(audio), languageCode },
83
123
  });
84
- const results = [];
85
- for (const result of response[0]?.results ?? []) {
124
+ const recognized = response[0];
125
+ const stretches = [];
126
+ for (const result of recognized?.results ?? []) {
86
127
  const alt = result?.alternatives?.[0];
87
- if (alt) {
88
- results.push({
89
- transcript: alt.transcript ?? '',
90
- confidence: alt.confidence ?? 0,
91
- isFinal: true,
92
- });
93
- }
128
+ if (!alt)
129
+ continue;
130
+ stretches.push({
131
+ text: (alt.transcript ?? '').trim(),
132
+ confidence: typeof alt.confidence === 'number' ? alt.confidence : undefined,
133
+ endTime: durationSeconds(result.resultEndTime),
134
+ });
94
135
  }
95
- return results;
136
+ const confidences = stretches.map((s) => s.confidence).filter((c) => c !== undefined);
137
+ // Timing is reported only when Google gives every stretch an end time.
138
+ let start = 0;
139
+ const segments = stretches.length > 0 && stretches.every((s) => s.endTime !== undefined)
140
+ ? stretches.map((s) => {
141
+ const segment = { text: s.text, startTime: start, endTime: s.endTime, confidence: s.confidence };
142
+ start = s.endTime;
143
+ return segment;
144
+ })
145
+ : undefined;
146
+ return {
147
+ text: stretches.map((s) => s.text).filter((t) => t.length > 0).join(' '),
148
+ language: recognized?.results?.[0]?.languageCode || languageCode,
149
+ confidence: confidences.length > 0 ? confidences.reduce((sum, c) => sum + c, 0) / confidences.length : undefined,
150
+ isFinal: true,
151
+ cost: 0,
152
+ segments,
153
+ providerResponse: recognized,
154
+ };
96
155
  }
97
156
  }
98
157
  //# sourceMappingURL=GoogleCloudSTTProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleCloudSTTProvider.js","sourceRoot":"","sources":["../src/GoogleCloudSTTProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwCH;;;;;;GAMG;AACH,MAAM,OAAO,sBAAsB;IACjC,yEAAyE;IAChE,EAAE,GAAG,kBAAkB,CAAC;IAEjC,wCAAwC;IAChC,OAAO,GAAwB,IAAI,CAAC;IAE5C,4FAA4F;IAC3E,cAAc,CAA0B;IAEzD;;;;;;OAMG;IACH,YAAY,WAAmB;QAC7B,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5D,wBAAwB;YACxB,IAAI,CAAC,cAAc,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,8CAA8C;YAC9C,IAAI,CAAC,cAAc,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAA4B,EAAE,CAAC;QAC5F,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,kBAAkB;IAClB,8EAA8E;IAE9E;;;;;OAKG;IACK,KAAK,CAAC,UAAU;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,wEAAwE;YACxE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;YAC9D,IAAI,CAAC,OAAO,GA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AAE,CAAC,CAAC,OAAiB,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;gBAC3G,KAAK,GAAG,CAAC,CAAC,OAAiB,CAAC;gBAC5B,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;QAEd,OAAO;YACL,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YACxE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,IAAI,YAAY;YAChE,UAAU,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAChH,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,CAAC;YACP,QAAQ;YACR,gBAAgB,EAAE,UAAU;SAC7B,CAAC;IACJ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -62,5 +62,5 @@ export declare function createGoogleCloudSTT(credentials: string): GoogleCloudST
62
62
  */
63
63
  export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
64
64
  export { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
65
- export type { SpeechTranscriptionResult, GoogleCloudSTTOptions, AudioData, } from './GoogleCloudSTTProvider.js';
65
+ export type { SpeechTranscriptionResult, SpeechTranscriptionSegment, GoogleCloudSTTOptions, AudioData, } from './GoogleCloudSTTProvider.js';
66
66
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAMrE,2DAA2D;AAC3D,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qDAAqD;AACrD,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,4DAA4D;AAC5D,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AASD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,sBAAsB,CAEhF;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAgBhF;AAMD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,SAAS,GACV,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAMrE,2DAA2D;AAC3D,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qDAAqD;AACrD,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,4DAA4D;AAC5D,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AASD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,sBAAsB,CAEhF;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAgBhF;AAMD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,qBAAqB,EACrB,SAAS,GACV,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * @file index.ts
3
4
  * @description Pack factory for the Google Cloud STT extension pack.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AA2BrE,uEAAuE;AACvE,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAmB;IACtD,OAAO,IAAI,sBAAsB,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QACtB,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,kBAAkB;gBACtB,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,QAAQ;gBACjB,eAAe,EAAE,IAAI;gBACrB,QAAQ,EAAE,EAAE,UAAU,EAAE,kBAAkB,EAAE;aAC7C;SACF;KACF,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC"}
package/manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@framers/agentos-ext-google-cloud-stt",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Batch speech-to-text via Google Cloud Speech-to-Text API",
5
5
  "kind": "stt-provider",
6
6
  "extensionId": "google-cloud-stt",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@framers/agentos-ext-google-cloud-stt",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Batch speech-to-text via Google Cloud Speech-to-Text API for AgentOS voice pipeline",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,27 +18,31 @@
18
18
  "manifest.json"
19
19
  ],
20
20
  "peerDependencies": {
21
- "@framers/agentos": "^0.1.0",
21
+ "@framers/agentos": ">=0.10.40",
22
22
  "@google-cloud/speech": "^6.0.0"
23
23
  },
24
24
  "devDependencies": {
25
+ "@framers/agentos": "^0.12.5",
25
26
  "@google-cloud/speech": "^6.0.0",
26
27
  "typescript": "^5.5.0",
27
- "vitest": "^1.6.0",
28
- "@framers/agentos": "0.1.94"
28
+ "vitest": "^3.2.7"
29
29
  },
30
30
  "license": "MIT",
31
31
  "author": "Frame.dev",
32
32
  "repository": {
33
33
  "type": "git",
34
- "url": "https://github.com/framersai/agentos-extensions.git",
34
+ "url": "git+https://github.com/framerslab/agentos-extensions.git",
35
35
  "directory": "registry/curated/voice/google-cloud-stt"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
+ "homepage": "https://github.com/framerslab/agentos-extensions/tree/master/registry/curated/voice/google-cloud-stt#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/framerslab/agentos-extensions/issues"
43
+ },
40
44
  "scripts": {
41
45
  "build": "tsc -p tsconfig.json",
42
- "test": "vitest run"
46
+ "test": "vitest run --passWithNoTests"
43
47
  }
44
48
  }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * @file GoogleCloudSTTProvider.ts
3
4
  * @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
@@ -16,18 +17,40 @@
16
17
  type SpeechClient = any;
17
18
 
18
19
  /**
19
- * A single recognised audio segment returned by the provider.
20
- *
21
- * Mirrors the generic `SpeechTranscriptionResult` shape used across the
22
- * AgentOS voice pipeline.
20
+ * One stretch of recognised speech: Google returns a result per consecutive
21
+ * portion of the audio.
22
+ */
23
+ export interface SpeechTranscriptionSegment {
24
+ /** The most likely transcript of this stretch. */
25
+ text: string;
26
+ /** Start in seconds from the beginning of the audio. */
27
+ startTime: number;
28
+ /** End in seconds from the beginning of the audio. */
29
+ endTime: number;
30
+ /** Confidence score in [0, 1], when Google reports one. */
31
+ confidence?: number;
32
+ }
33
+
34
+ /**
35
+ * The transcription result of the AgentOS `SpeechToTextProvider` contract
36
+ * (`SpeechTranscriptionResult` in `@framers/agentos`), mirrored here so the
37
+ * pack carries no type import from agentos.
23
38
  */
24
39
  export interface SpeechTranscriptionResult {
25
- /** The recognised text. */
26
- transcript: string;
27
- /** Confidence score in [0, 1]. */
28
- confidence: number;
29
- /** Whether this is a final (non-speculative) result. Always `true` for batch. */
40
+ /** The recognised text: every stretch's most likely transcript, in order. */
41
+ text: string;
42
+ /** BCP-47 language of the transcript. */
43
+ language?: string;
44
+ /** Mean confidence of the stretches, in [0, 1], when Google reports any. */
45
+ confidence?: number;
46
+ /** Always `true`: batch recognition returns final results only. */
30
47
  isFinal: boolean;
48
+ /** Always 0; cost is tracked above the provider, as for AgentOS's core batch providers. */
49
+ cost: number;
50
+ /** Per-stretch transcripts with their timing, when Google reports end times. */
51
+ segments?: SpeechTranscriptionSegment[];
52
+ /** The raw `RecognizeResponse`. */
53
+ providerResponse?: unknown;
31
54
  }
32
55
 
33
56
  /**
@@ -39,13 +62,42 @@ export interface GoogleCloudSTTOptions {
39
62
  }
40
63
 
41
64
  /**
42
- * Audio frame passed to {@link GoogleCloudSTTProvider.transcribe}.
65
+ * Audio passed to {@link GoogleCloudSTTProvider.transcribe}: the fields of the
66
+ * AgentOS `SpeechAudioInput` this provider reads.
43
67
  */
44
68
  export interface AudioData {
45
- /** Raw PCM bytes (LINEAR16). */
69
+ /** The audio bytes: a WAV or FLAC file, or raw LINEAR16 PCM. */
46
70
  data: Buffer;
47
- /** Sample rate in Hz. @defaultValue `16000` */
71
+ /** Sample rate in Hz. Raw PCM defaults to 16000; a WAV or FLAC header supplies its own. */
48
72
  sampleRate?: number;
73
+ /** MIME type, such as `'audio/wav'` or `'audio/flac'`. */
74
+ mimeType?: string;
75
+ /** Container format, such as `'wav'` or `'flac'`. */
76
+ format?: string;
77
+ }
78
+
79
+ /**
80
+ * The encoding fields of the recognition config for this audio.
81
+ *
82
+ * WAV and FLAC files carry a header that states the encoding and sample rate.
83
+ * Google reads both from it and rejects a request whose stated values disagree
84
+ * (google.cloud.speech.v1 `RecognitionConfig`), so for those formats the
85
+ * encoding is left out and the sample rate is sent only when the caller gives
86
+ * one. Anything else is sent as raw LINEAR16 PCM.
87
+ */
88
+ function encodingFor(audio: AudioData): { encoding?: string; sampleRateHertz?: number } {
89
+ const declared = `${audio.mimeType ?? ''} ${audio.format ?? ''}`.toLowerCase();
90
+ if (declared.includes('wav') || declared.includes('flac')) {
91
+ return audio.sampleRate ? { sampleRateHertz: audio.sampleRate } : {};
92
+ }
93
+ return { encoding: 'LINEAR16', sampleRateHertz: audio.sampleRate ?? 16000 };
94
+ }
95
+
96
+ /** Seconds in a protobuf `Duration` (`{ seconds, nanos }`, seconds possibly a string). */
97
+ function durationSeconds(duration: { seconds?: unknown; nanos?: unknown } | null | undefined): number | undefined {
98
+ if (!duration) return undefined;
99
+ const seconds = Number(duration.seconds ?? 0) + Number(duration.nanos ?? 0) / 1e9;
100
+ return Number.isFinite(seconds) ? seconds : undefined;
49
101
  }
50
102
 
51
103
  /**
@@ -59,6 +111,12 @@ export class GoogleCloudSTTProvider {
59
111
  /** Stable provider identifier used by the AgentOS extension registry. */
60
112
  readonly id = 'google-cloud-stt';
61
113
 
114
+ /** Human-readable provider name. */
115
+ readonly displayName = 'Google Cloud Speech-to-Text';
116
+
117
+ /** Batch recognition only: this provider does not stream. */
118
+ readonly supportsStreaming = false;
119
+
62
120
  /** Lazily initialised Speech client. */
63
121
  private _client: SpeechClient | null = null;
64
122
 
@@ -69,11 +127,17 @@ export class GoogleCloudSTTProvider {
69
127
  * Create a new {@link GoogleCloudSTTProvider}.
70
128
  *
71
129
  * @param credentials - Either an absolute path to a service-account JSON key
72
- * file (any string that contains `/` or `\`) or a JSON string containing
73
- * the service-account credentials object.
130
+ * file (any string that contains `/` or `\`), a JSON string containing
131
+ * the service-account credentials object, or an empty string, which
132
+ * leaves the client on Google's Application Default Credentials.
74
133
  */
75
134
  constructor(credentials: string) {
76
- if (credentials.includes('/') || credentials.includes('\\')) {
135
+ if (!credentials.trim()) {
136
+ // No key given: the Google client finds Application Default Credentials
137
+ // (GOOGLE_APPLICATION_CREDENTIALS, gcloud, or the metadata server) when
138
+ // it is first used, so the pack still loads without a configured secret.
139
+ this._clientOptions = {};
140
+ } else if (credentials.includes('/') || credentials.includes('\\')) {
77
141
  // Treat as a file path.
78
142
  this._clientOptions = { keyFilename: credentials };
79
143
  } else {
@@ -106,44 +170,68 @@ export class GoogleCloudSTTProvider {
106
170
  // ---------------------------------------------------------------------------
107
171
 
108
172
  /**
109
- * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
173
+ * The provider's display name, as the AgentOS speech contract requires.
110
174
  *
111
- * The audio must be encoded as LINEAR16 (raw PCM, 16-bit little-endian).
112
- * The method returns all recognised alternatives from the first result, each
113
- * mapped to a {@link SpeechTranscriptionResult}.
175
+ * @returns `'Google Cloud Speech-to-Text'`.
176
+ */
177
+ getProviderName(): string {
178
+ return this.displayName;
179
+ }
180
+
181
+ /**
182
+ * Transcribe an audio file or raw PCM buffer using Google Cloud Speech-to-Text.
114
183
  *
115
- * @param audio - Audio frame containing the raw PCM bytes and sample rate.
184
+ * Google returns one result per consecutive stretch of the audio, each with
185
+ * its alternatives ordered by likelihood. The transcript is every stretch's
186
+ * first alternative, in order.
187
+ *
188
+ * @param audio - WAV or FLAC file bytes, or raw LINEAR16 PCM with its sample rate.
116
189
  * @param options - Optional per-call parameters (language code).
117
- * @returns Array of transcription results ordered by confidence (descending).
190
+ * @returns The transcription in the AgentOS `SpeechTranscriptionResult` shape.
118
191
  */
119
192
  async transcribe(
120
193
  audio: AudioData,
121
194
  options?: GoogleCloudSTTOptions,
122
- ): Promise<SpeechTranscriptionResult[]> {
195
+ ): Promise<SpeechTranscriptionResult> {
123
196
  const client = await this._getClient();
197
+ const languageCode = options?.language ?? 'en-US';
124
198
 
125
199
  const response = await client.recognize({
126
200
  audio: { content: audio.data.toString('base64') },
127
- config: {
128
- encoding: 'LINEAR16',
129
- sampleRateHertz: audio.sampleRate ?? 16000,
130
- languageCode: options?.language ?? 'en-US',
131
- },
201
+ config: { ...encodingFor(audio), languageCode },
132
202
  });
203
+ const recognized = response[0];
133
204
 
134
- const results: SpeechTranscriptionResult[] = [];
135
-
136
- for (const result of response[0]?.results ?? []) {
205
+ const stretches: Array<{ text: string; confidence?: number; endTime?: number }> = [];
206
+ for (const result of recognized?.results ?? []) {
137
207
  const alt = result?.alternatives?.[0];
138
- if (alt) {
139
- results.push({
140
- transcript: alt.transcript ?? '',
141
- confidence: alt.confidence ?? 0,
142
- isFinal: true,
143
- });
144
- }
208
+ if (!alt) continue;
209
+ stretches.push({
210
+ text: (alt.transcript ?? '').trim(),
211
+ confidence: typeof alt.confidence === 'number' ? alt.confidence : undefined,
212
+ endTime: durationSeconds(result.resultEndTime),
213
+ });
145
214
  }
146
215
 
147
- return results;
216
+ const confidences = stretches.map((s) => s.confidence).filter((c): c is number => c !== undefined);
217
+ // Timing is reported only when Google gives every stretch an end time.
218
+ let start = 0;
219
+ const segments = stretches.length > 0 && stretches.every((s) => s.endTime !== undefined)
220
+ ? stretches.map((s) => {
221
+ const segment = { text: s.text, startTime: start, endTime: s.endTime as number, confidence: s.confidence };
222
+ start = s.endTime as number;
223
+ return segment;
224
+ })
225
+ : undefined;
226
+
227
+ return {
228
+ text: stretches.map((s) => s.text).filter((t) => t.length > 0).join(' '),
229
+ language: recognized?.results?.[0]?.languageCode || languageCode,
230
+ confidence: confidences.length > 0 ? confidences.reduce((sum, c) => sum + c, 0) / confidences.length : undefined,
231
+ isFinal: true,
232
+ cost: 0,
233
+ segments,
234
+ providerResponse: recognized,
235
+ };
148
236
  }
149
237
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * @file index.ts
3
4
  * @description Pack factory for the Google Cloud STT extension pack.
@@ -104,6 +105,7 @@ export function createExtensionPack(context: ExtensionPackContext): ExtensionPac
104
105
  export { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
105
106
  export type {
106
107
  SpeechTranscriptionResult,
108
+ SpeechTranscriptionSegment,
107
109
  GoogleCloudSTTOptions,
108
110
  AudioData,
109
111
  } from './GoogleCloudSTTProvider.js';