@framers/agentos-ext-google-cloud-stt 0.2.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 ADDED
@@ -0,0 +1,23 @@
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.
22
+
23
+
package/SKILL.md ADDED
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: google-cloud-stt
3
+ description: Batch speech-to-text via Google Cloud Speech-to-Text API
4
+ category: voice
5
+ ---
6
+
7
+ # Google Cloud STT
8
+
9
+ Batch speech-to-text recognition using Google Cloud Speech-to-Text V1 API.
10
+
11
+ ## Setup
12
+
13
+ Provide credentials via the `GOOGLE_CLOUD_STT_CREDENTIALS` secret. Accepts either:
14
+ - An absolute path to a service-account JSON key file (contains `/` or `\`)
15
+ - A raw JSON string with the service-account credentials
16
+
17
+ ## Features
18
+
19
+ - LINEAR16 PCM audio transcription
20
+ - Configurable language code (BCP-47)
21
+ - Confidence scores and word-level alternatives
22
+ - Maps to standard `SpeechTranscriptionResult` shape
23
+
24
+ ## Configuration
25
+
26
+ In `agent.config.json`:
27
+
28
+ ```json
29
+ {
30
+ "voice": {
31
+ "stt": "google-cloud-stt"
32
+ }
33
+ }
34
+ ```
35
+
36
+ Provider-specific options via `providerOptions`:
37
+
38
+ ```json
39
+ {
40
+ "voice": {
41
+ "stt": "google-cloud-stt",
42
+ "providerOptions": {
43
+ "language": "fr-FR"
44
+ }
45
+ }
46
+ }
47
+ ```
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @file GoogleCloudSTTProvider.ts
3
+ * @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
4
+ *
5
+ * Credentials are resolved from the constructor argument:
6
+ * - If the string contains `/` or `\`, it is treated as a path to a service-account JSON key file
7
+ * and passed to the client as `keyFilename`.
8
+ * - Otherwise the string is parsed as a JSON object and passed as `credentials`.
9
+ *
10
+ * @module google-cloud-stt
11
+ */
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.
17
+ */
18
+ 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. */
24
+ isFinal: boolean;
25
+ }
26
+ /**
27
+ * Per-call transcription options forwarded to the Google Cloud API.
28
+ */
29
+ export interface GoogleCloudSTTOptions {
30
+ /** BCP-47 language code (e.g. `'en-US'`, `'fr-FR'`). @defaultValue `'en-US'` */
31
+ language?: string;
32
+ }
33
+ /**
34
+ * Audio frame passed to {@link GoogleCloudSTTProvider.transcribe}.
35
+ */
36
+ export interface AudioData {
37
+ /** Raw PCM bytes (LINEAR16). */
38
+ data: Buffer;
39
+ /** Sample rate in Hz. @defaultValue `16000` */
40
+ sampleRate?: number;
41
+ }
42
+ /**
43
+ * Google Cloud Speech-to-Text batch provider.
44
+ *
45
+ * Implements the `SpeechToTextProvider` contract expected by the AgentOS
46
+ * voice pipeline without taking a hard runtime dependency on the interface
47
+ * types (to avoid circular imports when loaded as an extension pack).
48
+ */
49
+ export declare class GoogleCloudSTTProvider {
50
+ /** Stable provider identifier used by the AgentOS extension registry. */
51
+ readonly id = "google-cloud-stt";
52
+ /** Lazily initialised Speech client. */
53
+ private _client;
54
+ /** Resolved client constructor options (set in constructor, used in {@link _getClient}). */
55
+ private readonly _clientOptions;
56
+ /**
57
+ * Create a new {@link GoogleCloudSTTProvider}.
58
+ *
59
+ * @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.
62
+ */
63
+ constructor(credentials: string);
64
+ /**
65
+ * Return (and lazily create) the Google Cloud {@link SpeechClient}.
66
+ *
67
+ * Using a lazy initialisation pattern keeps the constructor synchronous and
68
+ * allows unit tests to inject the mock before the first `transcribe()` call.
69
+ */
70
+ private _getClient;
71
+ /**
72
+ * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
73
+ *
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}.
77
+ *
78
+ * @param audio - Audio frame containing the raw PCM bytes and sample rate.
79
+ * @param options - Optional per-call parameters (language code).
80
+ * @returns Array of transcription results ordered by confidence (descending).
81
+ */
82
+ transcribe(audio: AudioData, options?: GoogleCloudSTTOptions): Promise<SpeechTranscriptionResult[]>;
83
+ }
84
+ //# sourceMappingURL=GoogleCloudSTTProvider.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @file GoogleCloudSTTProvider.ts
3
+ * @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
4
+ *
5
+ * Credentials are resolved from the constructor argument:
6
+ * - If the string contains `/` or `\`, it is treated as a path to a service-account JSON key file
7
+ * and passed to the client as `keyFilename`.
8
+ * - Otherwise the string is parsed as a JSON object and passed as `credentials`.
9
+ *
10
+ * @module google-cloud-stt
11
+ */
12
+ /**
13
+ * Google Cloud Speech-to-Text batch provider.
14
+ *
15
+ * Implements the `SpeechToTextProvider` contract expected by the AgentOS
16
+ * voice pipeline without taking a hard runtime dependency on the interface
17
+ * types (to avoid circular imports when loaded as an extension pack).
18
+ */
19
+ export class GoogleCloudSTTProvider {
20
+ /** Stable provider identifier used by the AgentOS extension registry. */
21
+ id = 'google-cloud-stt';
22
+ /** Lazily initialised Speech client. */
23
+ _client = null;
24
+ /** Resolved client constructor options (set in constructor, used in {@link _getClient}). */
25
+ _clientOptions;
26
+ /**
27
+ * Create a new {@link GoogleCloudSTTProvider}.
28
+ *
29
+ * @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.
32
+ */
33
+ constructor(credentials) {
34
+ if (credentials.includes('/') || credentials.includes('\\')) {
35
+ // Treat as a file path.
36
+ this._clientOptions = { keyFilename: credentials };
37
+ }
38
+ else {
39
+ // Treat as an inline JSON credentials object.
40
+ this._clientOptions = { credentials: JSON.parse(credentials) };
41
+ }
42
+ }
43
+ // ---------------------------------------------------------------------------
44
+ // Private helpers
45
+ // ---------------------------------------------------------------------------
46
+ /**
47
+ * Return (and lazily create) the Google Cloud {@link SpeechClient}.
48
+ *
49
+ * Using a lazy initialisation pattern keeps the constructor synchronous and
50
+ * allows unit tests to inject the mock before the first `transcribe()` call.
51
+ */
52
+ async _getClient() {
53
+ if (!this._client) {
54
+ // Dynamic import keeps the peer dep truly optional at module-load time.
55
+ const { SpeechClient } = await import('@google-cloud/speech');
56
+ this._client = new SpeechClient(this._clientOptions);
57
+ }
58
+ return this._client;
59
+ }
60
+ // ---------------------------------------------------------------------------
61
+ // Public API
62
+ // ---------------------------------------------------------------------------
63
+ /**
64
+ * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
65
+ *
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}.
69
+ *
70
+ * @param audio - Audio frame containing the raw PCM bytes and sample rate.
71
+ * @param options - Optional per-call parameters (language code).
72
+ * @returns Array of transcription results ordered by confidence (descending).
73
+ */
74
+ async transcribe(audio, options) {
75
+ const client = await this._getClient();
76
+ const response = await client.recognize({
77
+ audio: { content: audio.data.toString('base64') },
78
+ config: {
79
+ encoding: 'LINEAR16',
80
+ sampleRateHertz: audio.sampleRate ?? 16000,
81
+ languageCode: options?.language ?? 'en-US',
82
+ },
83
+ });
84
+ const results = [];
85
+ for (const result of response[0]?.results ?? []) {
86
+ 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
+ }
94
+ }
95
+ return results;
96
+ }
97
+ }
98
+ //# sourceMappingURL=GoogleCloudSTTProvider.js.map
@@ -0,0 +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,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,8EAA8E;IAC9E,aAAa;IACb,8EAA8E;IAE9E;;;;;;;;;;OAUG;IACH,KAAK,CAAC,UAAU,CACd,KAAgB,EAChB,OAA+B;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAEvC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YACtC,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACjD,MAAM,EAAE;gBACN,QAAQ,EAAE,UAAU;gBACpB,eAAe,EAAE,KAAK,CAAC,UAAU,IAAI,KAAK;gBAC1C,YAAY,EAAE,OAAO,EAAE,QAAQ,IAAI,OAAO;aAC3C;SACF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;YACtC,IAAI,GAAG,EAAE,CAAC;gBACR,OAAO,CAAC,IAAI,CAAC;oBACX,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE;oBAChC,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,CAAC;oBAC/B,OAAO,EAAE,IAAI;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Pack factory for the Google Cloud STT extension pack.
4
+ *
5
+ * Exports the main {@link createGoogleCloudSTT} factory function and the
6
+ * {@link createExtensionPack} bridge function that conforms to the AgentOS
7
+ * manifest factory convention.
8
+ *
9
+ * ### Usage (direct)
10
+ * ```ts
11
+ * import { createGoogleCloudSTT } from '@framers/agentos-ext-google-cloud-stt';
12
+ *
13
+ * const stt = createGoogleCloudSTT('/path/to/service-account.json');
14
+ * const results = await stt.transcribe({ data: pcmBuffer, sampleRate: 16000 });
15
+ * ```
16
+ *
17
+ * ### Usage (manifest-driven)
18
+ * ```json
19
+ * { "packs": [{ "module": "@framers/agentos-ext-google-cloud-stt" }] }
20
+ * ```
21
+ *
22
+ * @module google-cloud-stt
23
+ */
24
+ import { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
25
+ /** Subset of ExtensionDescriptor required by this pack. */
26
+ interface ExtensionDescriptor {
27
+ id: string;
28
+ kind: string;
29
+ payload: unknown;
30
+ enableByDefault?: boolean;
31
+ metadata?: Record<string, unknown>;
32
+ }
33
+ /** Subset of ExtensionPack required by this pack. */
34
+ interface ExtensionPack {
35
+ id: string;
36
+ descriptors: ExtensionDescriptor[];
37
+ }
38
+ /** Subset of ExtensionPackContext required by this pack. */
39
+ interface ExtensionPackContext {
40
+ getSecret?: (id: string) => string | undefined;
41
+ options?: Record<string, unknown>;
42
+ }
43
+ /**
44
+ * Create a standalone {@link GoogleCloudSTTProvider} instance.
45
+ *
46
+ * Use this when composing the provider programmatically outside of the
47
+ * AgentOS extension system.
48
+ *
49
+ * @param credentials - Path to service-account JSON file or inline JSON string.
50
+ * @returns Configured {@link GoogleCloudSTTProvider}.
51
+ */
52
+ export declare function createGoogleCloudSTT(credentials: string): GoogleCloudSTTProvider;
53
+ /**
54
+ * AgentOS manifest factory function.
55
+ *
56
+ * Reads the `GOOGLE_CLOUD_STT_CREDENTIALS` secret from the context and
57
+ * returns an {@link ExtensionPack} containing a single `stt-provider`
58
+ * descriptor backed by {@link GoogleCloudSTTProvider}.
59
+ *
60
+ * @param context - Pack context supplied by the extension manager.
61
+ * @returns A fully configured {@link ExtensionPack}.
62
+ */
63
+ export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
64
+ export { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
65
+ export type { SpeechTranscriptionResult, GoogleCloudSTTOptions, AudioData, } from './GoogleCloudSTTProvider.js';
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Pack factory for the Google Cloud STT extension pack.
4
+ *
5
+ * Exports the main {@link createGoogleCloudSTT} factory function and the
6
+ * {@link createExtensionPack} bridge function that conforms to the AgentOS
7
+ * manifest factory convention.
8
+ *
9
+ * ### Usage (direct)
10
+ * ```ts
11
+ * import { createGoogleCloudSTT } from '@framers/agentos-ext-google-cloud-stt';
12
+ *
13
+ * const stt = createGoogleCloudSTT('/path/to/service-account.json');
14
+ * const results = await stt.transcribe({ data: pcmBuffer, sampleRate: 16000 });
15
+ * ```
16
+ *
17
+ * ### Usage (manifest-driven)
18
+ * ```json
19
+ * { "packs": [{ "module": "@framers/agentos-ext-google-cloud-stt" }] }
20
+ * ```
21
+ *
22
+ * @module google-cloud-stt
23
+ */
24
+ import { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
25
+ /** Kind constant matching packages/agentos/src/extensions/types.ts. */
26
+ const EXTENSION_KIND_STT = 'stt-provider';
27
+ // ---------------------------------------------------------------------------
28
+ // Factories
29
+ // ---------------------------------------------------------------------------
30
+ /**
31
+ * Create a standalone {@link GoogleCloudSTTProvider} instance.
32
+ *
33
+ * Use this when composing the provider programmatically outside of the
34
+ * AgentOS extension system.
35
+ *
36
+ * @param credentials - Path to service-account JSON file or inline JSON string.
37
+ * @returns Configured {@link GoogleCloudSTTProvider}.
38
+ */
39
+ export function createGoogleCloudSTT(credentials) {
40
+ return new GoogleCloudSTTProvider(credentials);
41
+ }
42
+ /**
43
+ * AgentOS manifest factory function.
44
+ *
45
+ * Reads the `GOOGLE_CLOUD_STT_CREDENTIALS` secret from the context and
46
+ * returns an {@link ExtensionPack} containing a single `stt-provider`
47
+ * descriptor backed by {@link GoogleCloudSTTProvider}.
48
+ *
49
+ * @param context - Pack context supplied by the extension manager.
50
+ * @returns A fully configured {@link ExtensionPack}.
51
+ */
52
+ export function createExtensionPack(context) {
53
+ const credentials = context.getSecret?.('GOOGLE_CLOUD_STT_CREDENTIALS') ?? '';
54
+ const provider = new GoogleCloudSTTProvider(credentials);
55
+ return {
56
+ id: 'google-cloud-stt',
57
+ descriptors: [
58
+ {
59
+ id: 'google-cloud-stt',
60
+ kind: EXTENSION_KIND_STT,
61
+ payload: provider,
62
+ enableByDefault: true,
63
+ metadata: { providerId: 'google-cloud-stt' },
64
+ },
65
+ ],
66
+ };
67
+ }
68
+ // ---------------------------------------------------------------------------
69
+ // Re-exports
70
+ // ---------------------------------------------------------------------------
71
+ export { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,8BAA8B,CAAC,IAAI,EAAE,CAAC;IAC9E,MAAM,QAAQ,GAAG,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAEzD,OAAO;QACL,EAAE,EAAE,kBAAkB;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 ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@framers/agentos-ext-google-cloud-stt",
3
+ "version": "0.1.0",
4
+ "description": "Batch speech-to-text via Google Cloud Speech-to-Text API",
5
+ "kind": "stt-provider",
6
+ "extensionId": "google-cloud-stt",
7
+ "entryPoint": "./dist/index.js"
8
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@framers/agentos-ext-google-cloud-stt",
3
+ "version": "0.2.0",
4
+ "description": "Batch speech-to-text via Google Cloud Speech-to-Text API for AgentOS voice pipeline",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "SKILL.md",
18
+ "manifest.json"
19
+ ],
20
+ "peerDependencies": {
21
+ "@framers/agentos": "^0.1.0",
22
+ "@google-cloud/speech": "^6.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@google-cloud/speech": "^6.0.0",
26
+ "typescript": "^5.5.0",
27
+ "vitest": "^1.6.0",
28
+ "@framers/agentos": "0.1.94"
29
+ },
30
+ "license": "MIT",
31
+ "author": "Frame.dev",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/framersai/agentos-extensions.git",
35
+ "directory": "registry/curated/voice/google-cloud-stt"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json",
42
+ "test": "vitest run"
43
+ }
44
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @file GoogleCloudSTTProvider.ts
3
+ * @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
4
+ *
5
+ * Credentials are resolved from the constructor argument:
6
+ * - If the string contains `/` or `\`, it is treated as a path to a service-account JSON key file
7
+ * and passed to the client as `keyFilename`.
8
+ * - Otherwise the string is parsed as a JSON object and passed as `credentials`.
9
+ *
10
+ * @module google-cloud-stt
11
+ */
12
+
13
+ // Dynamic import is used so the SDK is only loaded at runtime, allowing the
14
+ // module to load without throwing when the peer dep is absent.
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ type SpeechClient = any;
17
+
18
+ /**
19
+ * A single recognised audio segment returned by the provider.
20
+ *
21
+ * Mirrors the generic `SpeechTranscriptionResult` shape used across the
22
+ * AgentOS voice pipeline.
23
+ */
24
+ 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. */
30
+ isFinal: boolean;
31
+ }
32
+
33
+ /**
34
+ * Per-call transcription options forwarded to the Google Cloud API.
35
+ */
36
+ export interface GoogleCloudSTTOptions {
37
+ /** BCP-47 language code (e.g. `'en-US'`, `'fr-FR'`). @defaultValue `'en-US'` */
38
+ language?: string;
39
+ }
40
+
41
+ /**
42
+ * Audio frame passed to {@link GoogleCloudSTTProvider.transcribe}.
43
+ */
44
+ export interface AudioData {
45
+ /** Raw PCM bytes (LINEAR16). */
46
+ data: Buffer;
47
+ /** Sample rate in Hz. @defaultValue `16000` */
48
+ sampleRate?: number;
49
+ }
50
+
51
+ /**
52
+ * Google Cloud Speech-to-Text batch provider.
53
+ *
54
+ * Implements the `SpeechToTextProvider` contract expected by the AgentOS
55
+ * voice pipeline without taking a hard runtime dependency on the interface
56
+ * types (to avoid circular imports when loaded as an extension pack).
57
+ */
58
+ export class GoogleCloudSTTProvider {
59
+ /** Stable provider identifier used by the AgentOS extension registry. */
60
+ readonly id = 'google-cloud-stt';
61
+
62
+ /** Lazily initialised Speech client. */
63
+ private _client: SpeechClient | null = null;
64
+
65
+ /** Resolved client constructor options (set in constructor, used in {@link _getClient}). */
66
+ private readonly _clientOptions: Record<string, unknown>;
67
+
68
+ /**
69
+ * Create a new {@link GoogleCloudSTTProvider}.
70
+ *
71
+ * @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.
74
+ */
75
+ constructor(credentials: string) {
76
+ if (credentials.includes('/') || credentials.includes('\\')) {
77
+ // Treat as a file path.
78
+ this._clientOptions = { keyFilename: credentials };
79
+ } else {
80
+ // Treat as an inline JSON credentials object.
81
+ this._clientOptions = { credentials: JSON.parse(credentials) as Record<string, unknown> };
82
+ }
83
+ }
84
+
85
+ // ---------------------------------------------------------------------------
86
+ // Private helpers
87
+ // ---------------------------------------------------------------------------
88
+
89
+ /**
90
+ * Return (and lazily create) the Google Cloud {@link SpeechClient}.
91
+ *
92
+ * Using a lazy initialisation pattern keeps the constructor synchronous and
93
+ * allows unit tests to inject the mock before the first `transcribe()` call.
94
+ */
95
+ private async _getClient(): Promise<SpeechClient> {
96
+ if (!this._client) {
97
+ // Dynamic import keeps the peer dep truly optional at module-load time.
98
+ const { SpeechClient } = await import('@google-cloud/speech');
99
+ this._client = new SpeechClient(this._clientOptions);
100
+ }
101
+ return this._client;
102
+ }
103
+
104
+ // ---------------------------------------------------------------------------
105
+ // Public API
106
+ // ---------------------------------------------------------------------------
107
+
108
+ /**
109
+ * Transcribe a batch audio buffer using Google Cloud Speech-to-Text.
110
+ *
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}.
114
+ *
115
+ * @param audio - Audio frame containing the raw PCM bytes and sample rate.
116
+ * @param options - Optional per-call parameters (language code).
117
+ * @returns Array of transcription results ordered by confidence (descending).
118
+ */
119
+ async transcribe(
120
+ audio: AudioData,
121
+ options?: GoogleCloudSTTOptions,
122
+ ): Promise<SpeechTranscriptionResult[]> {
123
+ const client = await this._getClient();
124
+
125
+ const response = await client.recognize({
126
+ audio: { content: audio.data.toString('base64') },
127
+ config: {
128
+ encoding: 'LINEAR16',
129
+ sampleRateHertz: audio.sampleRate ?? 16000,
130
+ languageCode: options?.language ?? 'en-US',
131
+ },
132
+ });
133
+
134
+ const results: SpeechTranscriptionResult[] = [];
135
+
136
+ for (const result of response[0]?.results ?? []) {
137
+ 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
+ }
145
+ }
146
+
147
+ return results;
148
+ }
149
+ }
package/src/index.ts ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Pack factory for the Google Cloud STT extension pack.
4
+ *
5
+ * Exports the main {@link createGoogleCloudSTT} factory function and the
6
+ * {@link createExtensionPack} bridge function that conforms to the AgentOS
7
+ * manifest factory convention.
8
+ *
9
+ * ### Usage (direct)
10
+ * ```ts
11
+ * import { createGoogleCloudSTT } from '@framers/agentos-ext-google-cloud-stt';
12
+ *
13
+ * const stt = createGoogleCloudSTT('/path/to/service-account.json');
14
+ * const results = await stt.transcribe({ data: pcmBuffer, sampleRate: 16000 });
15
+ * ```
16
+ *
17
+ * ### Usage (manifest-driven)
18
+ * ```json
19
+ * { "packs": [{ "module": "@framers/agentos-ext-google-cloud-stt" }] }
20
+ * ```
21
+ *
22
+ * @module google-cloud-stt
23
+ */
24
+
25
+ import { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
26
+
27
+ // ---------------------------------------------------------------------------
28
+ // Local interface mirrors — avoids a hard runtime dep on @framers/agentos
29
+ // ---------------------------------------------------------------------------
30
+
31
+ /** Subset of ExtensionDescriptor required by this pack. */
32
+ interface ExtensionDescriptor {
33
+ id: string;
34
+ kind: string;
35
+ payload: unknown;
36
+ enableByDefault?: boolean;
37
+ metadata?: Record<string, unknown>;
38
+ }
39
+
40
+ /** Subset of ExtensionPack required by this pack. */
41
+ interface ExtensionPack {
42
+ id: string;
43
+ descriptors: ExtensionDescriptor[];
44
+ }
45
+
46
+ /** Subset of ExtensionPackContext required by this pack. */
47
+ interface ExtensionPackContext {
48
+ getSecret?: (id: string) => string | undefined;
49
+ options?: Record<string, unknown>;
50
+ }
51
+
52
+ /** Kind constant matching packages/agentos/src/extensions/types.ts. */
53
+ const EXTENSION_KIND_STT = 'stt-provider';
54
+
55
+ // ---------------------------------------------------------------------------
56
+ // Factories
57
+ // ---------------------------------------------------------------------------
58
+
59
+ /**
60
+ * Create a standalone {@link GoogleCloudSTTProvider} instance.
61
+ *
62
+ * Use this when composing the provider programmatically outside of the
63
+ * AgentOS extension system.
64
+ *
65
+ * @param credentials - Path to service-account JSON file or inline JSON string.
66
+ * @returns Configured {@link GoogleCloudSTTProvider}.
67
+ */
68
+ export function createGoogleCloudSTT(credentials: string): GoogleCloudSTTProvider {
69
+ return new GoogleCloudSTTProvider(credentials);
70
+ }
71
+
72
+ /**
73
+ * AgentOS manifest factory function.
74
+ *
75
+ * Reads the `GOOGLE_CLOUD_STT_CREDENTIALS` secret from the context and
76
+ * returns an {@link ExtensionPack} containing a single `stt-provider`
77
+ * descriptor backed by {@link GoogleCloudSTTProvider}.
78
+ *
79
+ * @param context - Pack context supplied by the extension manager.
80
+ * @returns A fully configured {@link ExtensionPack}.
81
+ */
82
+ export function createExtensionPack(context: ExtensionPackContext): ExtensionPack {
83
+ const credentials = context.getSecret?.('GOOGLE_CLOUD_STT_CREDENTIALS') ?? '';
84
+ const provider = new GoogleCloudSTTProvider(credentials);
85
+
86
+ return {
87
+ id: 'google-cloud-stt',
88
+ descriptors: [
89
+ {
90
+ id: 'google-cloud-stt',
91
+ kind: EXTENSION_KIND_STT,
92
+ payload: provider,
93
+ enableByDefault: true,
94
+ metadata: { providerId: 'google-cloud-stt' },
95
+ },
96
+ ],
97
+ };
98
+ }
99
+
100
+ // ---------------------------------------------------------------------------
101
+ // Re-exports
102
+ // ---------------------------------------------------------------------------
103
+
104
+ export { GoogleCloudSTTProvider } from './GoogleCloudSTTProvider.js';
105
+ export type {
106
+ SpeechTranscriptionResult,
107
+ GoogleCloudSTTOptions,
108
+ AudioData,
109
+ } from './GoogleCloudSTTProvider.js';