@mastra/voice-deepgram 0.1.1-alpha.0 → 0.1.1-alpha.3

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,18 +1,23 @@
1
1
 
2
- > @mastra/voice-deepgram@0.1.1-alpha.0 build /home/runner/work/mastra/mastra/voice/deepgram
3
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
2
+ > @mastra/voice-deepgram@0.1.1-alpha.3 build /home/runner/work/mastra/mastra/voice/deepgram
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 6659ms
9
+ TSC ⚡️ Build success in 6442ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/voice/deepgram/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 5882ms
14
+ Analysis will use the bundled TypeScript version 5.7.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/voice/deepgram/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 7521ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
19
+ CJS Build start
17
20
  ESM dist/index.js 4.40 KB
18
- ESM ⚡️ Build success in 433ms
21
+ ESM ⚡️ Build success in 288ms
22
+ CJS dist/index.cjs 4.43 KB
23
+ CJS ⚡️ Build success in 288ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb4f447: Add support for commonjs
8
+ - Updated dependencies [0fd78ac]
9
+ - Updated dependencies [0d25b75]
10
+ - Updated dependencies [fd14a3f]
11
+ - Updated dependencies [3f369a2]
12
+ - Updated dependencies [4d4e1e1]
13
+ - Updated dependencies [bb4f447]
14
+ - @mastra/core@0.4.3-alpha.3
15
+
16
+ ## 0.1.1-alpha.2
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [2512a93]
21
+ - Updated dependencies [e62de74]
22
+ - @mastra/core@0.4.3-alpha.2
23
+
24
+ ## 0.1.1-alpha.1
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [0d185b1]
29
+ - Updated dependencies [ed55f1d]
30
+ - Updated dependencies [8d13b14]
31
+ - Updated dependencies [3ee4831]
32
+ - Updated dependencies [108793c]
33
+ - Updated dependencies [5f28f44]
34
+ - @mastra/core@0.4.3-alpha.1
35
+
3
36
  ## 0.1.1-alpha.0
4
37
 
5
38
  ### Patch Changes
@@ -0,0 +1,50 @@
1
+ import { MastraVoice } from '@mastra/core/voice';
2
+
3
+ /**
4
+ * List of available Deepgram models for text-to-speech and speech-to-text
5
+ */
6
+ export declare const DEEPGRAM_MODELS: readonly ["aura", "whisper", "base", "enhanced", "nova", "nova-2", "nova-3"];
7
+
8
+ /**
9
+ * List of available Deepgram voice models for text-to-speech
10
+ * Each voice is designed for specific use cases and languages
11
+ * Format: {name}-{language} (e.g. asteria-en)
12
+ */
13
+ export declare const DEEPGRAM_VOICES: readonly ["asteria-en", "luna-en", "stella-en", "athena-en", "hera-en", "orion-en", "arcas-en", "perseus-en", "angus-en", "orpheus-en", "helios-en", "zeus-en"];
14
+
15
+ declare type DeepgramModel = (typeof DEEPGRAM_MODELS)[number];
16
+ export { DeepgramModel }
17
+ export { DeepgramModel as DeepgramModel_alias_1 }
18
+
19
+ export declare class DeepgramVoice extends MastraVoice {
20
+ private speechClient?;
21
+ private listeningClient?;
22
+ constructor({ speechModel, listeningModel, speaker, }?: {
23
+ speechModel?: DeepgramVoiceConfig;
24
+ listeningModel?: DeepgramVoiceConfig;
25
+ speaker?: DeepgramVoiceId;
26
+ });
27
+ getSpeakers(): Promise<{
28
+ voiceId: "asteria-en" | "luna-en" | "stella-en" | "athena-en" | "hera-en" | "orion-en" | "arcas-en" | "perseus-en" | "angus-en" | "orpheus-en" | "helios-en" | "zeus-en";
29
+ }[]>;
30
+ speak(input: string | NodeJS.ReadableStream, options?: {
31
+ speaker?: string;
32
+ [key: string]: any;
33
+ }): Promise<NodeJS.ReadableStream>;
34
+ listen(audioStream: NodeJS.ReadableStream, options?: {
35
+ [key: string]: any;
36
+ }): Promise<string>;
37
+ }
38
+
39
+ export declare interface DeepgramVoiceConfig {
40
+ name?: DeepgramModel;
41
+ apiKey?: string;
42
+ properties?: Record<string, any>;
43
+ language?: string;
44
+ }
45
+
46
+ declare type DeepgramVoiceId = (typeof DEEPGRAM_VOICES)[number];
47
+ export { DeepgramVoiceId }
48
+ export { DeepgramVoiceId as DeepgramVoiceId_alias_1 }
49
+
50
+ export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ var stream = require('stream');
4
+ var sdk = require('@deepgram/sdk');
5
+ var voice = require('@mastra/core/voice');
6
+
7
+ // src/index.ts
8
+
9
+ // src/voices.ts
10
+ var DEEPGRAM_VOICES = [
11
+ "asteria-en",
12
+ "luna-en",
13
+ "stella-en",
14
+ "athena-en",
15
+ "hera-en",
16
+ "orion-en",
17
+ "arcas-en",
18
+ "perseus-en",
19
+ "angus-en",
20
+ "orpheus-en",
21
+ "helios-en",
22
+ "zeus-en"
23
+ ];
24
+
25
+ // src/index.ts
26
+ var DeepgramVoice = class extends voice.MastraVoice {
27
+ speechClient;
28
+ listeningClient;
29
+ constructor({
30
+ speechModel,
31
+ listeningModel,
32
+ speaker
33
+ } = {}) {
34
+ const defaultApiKey = process.env.DEEPGRAM_API_KEY;
35
+ const defaultSpeechModel = {
36
+ name: "aura",
37
+ apiKey: defaultApiKey
38
+ };
39
+ const defaultListeningModel = {
40
+ name: "nova",
41
+ apiKey: defaultApiKey
42
+ };
43
+ super({
44
+ speechModel: {
45
+ name: speechModel?.name ?? defaultSpeechModel.name,
46
+ apiKey: speechModel?.apiKey ?? defaultSpeechModel.apiKey
47
+ },
48
+ listeningModel: {
49
+ name: listeningModel?.name ?? defaultListeningModel.name,
50
+ apiKey: listeningModel?.apiKey ?? defaultListeningModel.apiKey
51
+ },
52
+ speaker
53
+ });
54
+ const speechApiKey = speechModel?.apiKey || defaultApiKey;
55
+ const listeningApiKey = listeningModel?.apiKey || defaultApiKey;
56
+ if (!speechApiKey && !listeningApiKey) {
57
+ throw new Error("At least one of DEEPGRAM_API_KEY, speechModel.apiKey, or listeningModel.apiKey must be set");
58
+ }
59
+ if (speechApiKey) {
60
+ this.speechClient = sdk.createClient(speechApiKey);
61
+ }
62
+ if (listeningApiKey) {
63
+ this.listeningClient = sdk.createClient(listeningApiKey);
64
+ }
65
+ this.speaker = speaker || "asteria-en";
66
+ }
67
+ async getSpeakers() {
68
+ return this.traced(async () => {
69
+ return DEEPGRAM_VOICES.map((voice) => ({
70
+ voiceId: voice
71
+ }));
72
+ }, "voice.deepgram.getSpeakers")();
73
+ }
74
+ async speak(input, options) {
75
+ if (!this.speechClient) {
76
+ throw new Error("Deepgram speech client not configured");
77
+ }
78
+ let text;
79
+ if (typeof input !== "string") {
80
+ const chunks = [];
81
+ for await (const chunk of input) {
82
+ chunks.push(Buffer.from(chunk));
83
+ }
84
+ text = Buffer.concat(chunks).toString("utf-8");
85
+ } else {
86
+ text = input;
87
+ }
88
+ if (text.trim().length === 0) {
89
+ throw new Error("Input text is empty");
90
+ }
91
+ return this.traced(async () => {
92
+ if (!this.speechClient) {
93
+ throw new Error("No speech client configured");
94
+ }
95
+ let model;
96
+ if (options?.speaker) {
97
+ model = this.speechModel?.name + "-" + options.speaker;
98
+ } else if (this.speaker) {
99
+ model = this.speechModel?.name + "-" + this.speaker;
100
+ }
101
+ const speakClient = this.speechClient.speak;
102
+ const response = await speakClient.request(
103
+ { text },
104
+ {
105
+ model,
106
+ ...options
107
+ }
108
+ );
109
+ const webStream = await response.getStream();
110
+ if (!webStream) {
111
+ throw new Error("No stream returned from Deepgram");
112
+ }
113
+ const reader = webStream.getReader();
114
+ const nodeStream = new stream.PassThrough();
115
+ (async () => {
116
+ try {
117
+ while (true) {
118
+ const { done, value } = await reader.read();
119
+ if (done) {
120
+ nodeStream.end();
121
+ break;
122
+ }
123
+ nodeStream.write(value);
124
+ }
125
+ } catch (error) {
126
+ nodeStream.destroy(error);
127
+ }
128
+ })().catch((error) => {
129
+ nodeStream.destroy(error);
130
+ });
131
+ return nodeStream;
132
+ }, "voice.deepgram.speak")();
133
+ }
134
+ async listen(audioStream, options) {
135
+ if (!this.listeningClient) {
136
+ throw new Error("Deepgram listening client not configured");
137
+ }
138
+ const chunks = [];
139
+ for await (const chunk of audioStream) {
140
+ chunks.push(Buffer.from(chunk));
141
+ }
142
+ const buffer = Buffer.concat(chunks);
143
+ return this.traced(async () => {
144
+ if (!this.listeningClient) {
145
+ throw new Error("No listening client configured");
146
+ }
147
+ const { result, error } = await this.listeningClient.listen.prerecorded.transcribeFile(buffer, {
148
+ model: this.listeningModel?.name,
149
+ ...options
150
+ });
151
+ if (error) {
152
+ throw error;
153
+ }
154
+ const transcript = result.results?.channels?.[0]?.alternatives?.[0]?.transcript;
155
+ if (!transcript) {
156
+ throw new Error("No transcript found in Deepgram response");
157
+ }
158
+ return transcript;
159
+ }, "voice.deepgram.listen")();
160
+ }
161
+ };
162
+
163
+ exports.DeepgramVoice = DeepgramVoice;
@@ -0,0 +1,4 @@
1
+ export { DeepgramVoice } from './_tsup-dts-rollup.cjs';
2
+ export { DeepgramVoiceConfig } from './_tsup-dts-rollup.cjs';
3
+ export { DeepgramVoiceId } from './_tsup-dts-rollup.cjs';
4
+ export { DeepgramModel } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { PassThrough } from 'stream';
1
2
  import { createClient } from '@deepgram/sdk';
2
3
  import { MastraVoice } from '@mastra/core/voice';
3
- import { PassThrough } from 'stream';
4
4
 
5
5
  // src/index.ts
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/voice-deepgram",
3
- "version": "0.1.1-alpha.0",
3
+ "version": "0.1.1-alpha.3",
4
4
  "description": "Mastra Deepgram voice integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,6 +10,10 @@
10
10
  "import": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
13
17
  }
14
18
  },
15
19
  "./package.json": "./package.json"
@@ -17,7 +21,7 @@
17
21
  "dependencies": {
18
22
  "@deepgram/sdk": "^3.9.0",
19
23
  "zod": "^3.24.1",
20
- "@mastra/core": "^0.4.3-alpha.0"
24
+ "@mastra/core": "^0.4.3-alpha.3"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@microsoft/api-extractor": "^7.49.2",
@@ -29,7 +33,7 @@
29
33
  "@internal/lint": "0.0.0"
30
34
  },
31
35
  "scripts": {
32
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
36
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
33
37
  "build:watch": "pnpm build --watch",
34
38
  "test": "vitest run",
35
39
  "lint": "eslint ."
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { PassThrough } from 'stream';
2
+
1
3
  import { createClient } from '@deepgram/sdk';
2
4
  import { MastraVoice } from '@mastra/core/voice';
3
- import { PassThrough } from 'stream';
4
5
 
5
6
  import { DEEPGRAM_VOICES } from './voices';
6
7
  import type { DeepgramVoiceId, DeepgramModel } from './voices';