@mastra/voice-deepgram 0.1.1-alpha.1 → 0.1.1-alpha.4
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/.turbo/turbo-build.log +10 -5
- package/CHANGELOG.md +28 -0
- package/dist/_tsup-dts-rollup.d.cts +50 -0
- package/dist/index.cjs +163 -0
- package/dist/index.d.cts +4 -0
- package/package.json +7 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/voice-deepgram@0.1.1-alpha.
|
|
3
|
-
> tsup src/index.ts --format esm --experimental-dts --clean --treeshake
|
|
2
|
+
> @mastra/voice-deepgram@0.1.1-alpha.4 build /home/runner/work/mastra/mastra/voice/deepgram
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.3.6
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 7635ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.7.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/deepgram/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
|
-
|
|
14
|
+
Analysis will use the bundled TypeScript version 5.7.3
|
|
15
|
+
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/deepgram/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8648ms
|
|
15
17
|
[34mCLI[39m Cleaning output folder
|
|
16
18
|
[34mESM[39m Build start
|
|
19
|
+
[34mCJS[39m Build start
|
|
17
20
|
[32mESM[39m [1mdist/index.js [22m[32m4.40 KB[39m
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 464ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m4.43 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 467ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [dabecf4]
|
|
8
|
+
- @mastra/core@0.4.3-alpha.4
|
|
9
|
+
|
|
10
|
+
## 0.1.1-alpha.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- bb4f447: Add support for commonjs
|
|
15
|
+
- Updated dependencies [0fd78ac]
|
|
16
|
+
- Updated dependencies [0d25b75]
|
|
17
|
+
- Updated dependencies [fd14a3f]
|
|
18
|
+
- Updated dependencies [3f369a2]
|
|
19
|
+
- Updated dependencies [4d4e1e1]
|
|
20
|
+
- Updated dependencies [bb4f447]
|
|
21
|
+
- @mastra/core@0.4.3-alpha.3
|
|
22
|
+
|
|
23
|
+
## 0.1.1-alpha.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [2512a93]
|
|
28
|
+
- Updated dependencies [e62de74]
|
|
29
|
+
- @mastra/core@0.4.3-alpha.2
|
|
30
|
+
|
|
3
31
|
## 0.1.1-alpha.1
|
|
4
32
|
|
|
5
33
|
### 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;
|
package/dist/index.d.cts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-deepgram",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.4",
|
|
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.
|
|
24
|
+
"@mastra/core": "^0.4.3-alpha.4"
|
|
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 ."
|