@mastra/voice-playai 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.
- package/.turbo/turbo-build.log +10 -5
- package/CHANGELOG.md +33 -0
- package/dist/_tsup-dts-rollup.d.cts +43 -0
- package/dist/index.cjs +222 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.js +2 -2
- package/eslint.config.js +6 -0
- package/package.json +12 -5
- package/src/index.test.ts +2 -3
- package/src/index.ts +3 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/voice-playai@0.1.1-alpha.
|
|
3
|
-
> tsup src/index.ts --format esm --experimental-dts --clean --treeshake
|
|
2
|
+
> @mastra/voice-playai@0.1.1-alpha.3 build /home/runner/work/mastra/mastra/voice/playai
|
|
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 6392ms
|
|
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/playai/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/playai/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8230ms
|
|
15
17
|
[34mCLI[39m Cleaning output folder
|
|
16
18
|
[34mESM[39m Build start
|
|
19
|
+
[34mCJS[39m Build start
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m6.03 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 448ms
|
|
17
22
|
[32mESM[39m [1mdist/index.js [22m[32m5.97 KB[39m
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 452ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @mastra/voice-playai
|
|
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,43 @@
|
|
|
1
|
+
import { MastraVoice } from '@mastra/core/voice';
|
|
2
|
+
|
|
3
|
+
export declare const PLAYAI_VOICES: PlayAIVoiceInfo[];
|
|
4
|
+
|
|
5
|
+
declare interface PlayAIConfig {
|
|
6
|
+
name?: 'PlayDialog' | 'Play3.0-mini';
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare class PlayAIVoice extends MastraVoice {
|
|
12
|
+
private baseUrl;
|
|
13
|
+
private userId;
|
|
14
|
+
constructor({ speechModel, speaker }?: {
|
|
15
|
+
speechModel?: PlayAIConfig;
|
|
16
|
+
speaker?: string;
|
|
17
|
+
});
|
|
18
|
+
private makeRequest;
|
|
19
|
+
private streamToString;
|
|
20
|
+
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
21
|
+
speaker?: string;
|
|
22
|
+
}): Promise<NodeJS.ReadableStream>;
|
|
23
|
+
listen(_input: NodeJS.ReadableStream, _options?: Record<string, unknown>): Promise<string | NodeJS.ReadableStream>;
|
|
24
|
+
getSpeakers(): Promise<{
|
|
25
|
+
voiceId: string;
|
|
26
|
+
name: string;
|
|
27
|
+
accent: string;
|
|
28
|
+
gender: "M" | "F";
|
|
29
|
+
age: "Young" | "Middle" | "Old";
|
|
30
|
+
style: "Conversational" | "Narrative";
|
|
31
|
+
}[]>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare interface PlayAIVoiceInfo {
|
|
35
|
+
name: string;
|
|
36
|
+
accent: string;
|
|
37
|
+
gender: 'M' | 'F';
|
|
38
|
+
age: 'Young' | 'Middle' | 'Old';
|
|
39
|
+
style: 'Conversational' | 'Narrative';
|
|
40
|
+
id: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { }
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('stream');
|
|
4
|
+
var voice = require('@mastra/core/voice');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
var PLAYAI_VOICES = [
|
|
8
|
+
{
|
|
9
|
+
name: "Angelo",
|
|
10
|
+
accent: "US",
|
|
11
|
+
gender: "M",
|
|
12
|
+
age: "Young",
|
|
13
|
+
style: "Conversational",
|
|
14
|
+
id: "s3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "Arsenio",
|
|
18
|
+
accent: "US African American",
|
|
19
|
+
gender: "M",
|
|
20
|
+
age: "Middle",
|
|
21
|
+
style: "Conversational",
|
|
22
|
+
id: "s3://voice-cloning-zero-shot/65977f5e-a22a-4b36-861b-ecede19bdd65/original/manifest.json"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "Cillian",
|
|
26
|
+
accent: "Irish",
|
|
27
|
+
gender: "M",
|
|
28
|
+
age: "Middle",
|
|
29
|
+
style: "Conversational",
|
|
30
|
+
id: "s3://voice-cloning-zero-shot/1591b954-8760-41a9-bc58-9176a68c5726/original/manifest.json"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "Timo",
|
|
34
|
+
accent: "US",
|
|
35
|
+
gender: "M",
|
|
36
|
+
age: "Middle",
|
|
37
|
+
style: "Conversational",
|
|
38
|
+
id: "s3://voice-cloning-zero-shot/677a4ae3-252f-476e-85ce-eeed68e85951/original/manifest.json"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "Dexter",
|
|
42
|
+
accent: "US",
|
|
43
|
+
gender: "M",
|
|
44
|
+
age: "Middle",
|
|
45
|
+
style: "Conversational",
|
|
46
|
+
id: "s3://voice-cloning-zero-shot/b27bc13e-996f-4841-b584-4d35801aea98/original/manifest.json"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "Miles",
|
|
50
|
+
accent: "US African American",
|
|
51
|
+
gender: "M",
|
|
52
|
+
age: "Young",
|
|
53
|
+
style: "Conversational",
|
|
54
|
+
id: "s3://voice-cloning-zero-shot/29dd9a52-bd32-4a6e-bff1-bbb98dcc286a/original/manifest.json"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "Briggs",
|
|
58
|
+
accent: "US Southern (Oklahoma)",
|
|
59
|
+
gender: "M",
|
|
60
|
+
age: "Old",
|
|
61
|
+
style: "Conversational",
|
|
62
|
+
id: "s3://voice-cloning-zero-shot/71cdb799-1e03-41c6-8a05-f7cd55134b0b/original/manifest.json"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "Deedee",
|
|
66
|
+
accent: "US African American",
|
|
67
|
+
gender: "F",
|
|
68
|
+
age: "Middle",
|
|
69
|
+
style: "Conversational",
|
|
70
|
+
id: "s3://voice-cloning-zero-shot/e040bd1b-f190-4bdb-83f0-75ef85b18f84/original/manifest.json"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "Nia",
|
|
74
|
+
accent: "US",
|
|
75
|
+
gender: "F",
|
|
76
|
+
age: "Young",
|
|
77
|
+
style: "Conversational",
|
|
78
|
+
id: "s3://voice-cloning-zero-shot/831bd330-85c6-4333-b2b4-10c476ea3491/original/manifest.json"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "Inara",
|
|
82
|
+
accent: "US African American",
|
|
83
|
+
gender: "F",
|
|
84
|
+
age: "Middle",
|
|
85
|
+
style: "Conversational",
|
|
86
|
+
id: "s3://voice-cloning-zero-shot/adb83b67-8d75-48ff-ad4d-a0840d231ef1/original/manifest.json"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "Constanza",
|
|
90
|
+
accent: "US Latin American",
|
|
91
|
+
gender: "F",
|
|
92
|
+
age: "Young",
|
|
93
|
+
style: "Conversational",
|
|
94
|
+
id: "s3://voice-cloning-zero-shot/b0aca4d7-1738-4848-a80b-307ac44a7298/original/manifest.json"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "Gideon",
|
|
98
|
+
accent: "British",
|
|
99
|
+
gender: "M",
|
|
100
|
+
age: "Old",
|
|
101
|
+
style: "Narrative",
|
|
102
|
+
id: "s3://voice-cloning-zero-shot/5a3a1168-7793-4b2c-8f90-aff2b5232131/original/manifest.json"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "Casper",
|
|
106
|
+
accent: "US",
|
|
107
|
+
gender: "M",
|
|
108
|
+
age: "Middle",
|
|
109
|
+
style: "Narrative",
|
|
110
|
+
id: "s3://voice-cloning-zero-shot/1bbc6986-fadf-4bd8-98aa-b86fed0476e9/original/manifest.json"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "Mitch",
|
|
114
|
+
accent: "Australian",
|
|
115
|
+
gender: "M",
|
|
116
|
+
age: "Middle",
|
|
117
|
+
style: "Narrative",
|
|
118
|
+
id: "s3://voice-cloning-zero-shot/c14e50f2-c5e3-47d1-8c45-fa4b67803d19/original/manifest.json"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "Ava",
|
|
122
|
+
accent: "Australian",
|
|
123
|
+
gender: "F",
|
|
124
|
+
age: "Middle",
|
|
125
|
+
style: "Narrative",
|
|
126
|
+
id: "s3://voice-cloning-zero-shot/50381567-ff7b-46d2-bfdc-a9584a85e08d/original/manifest.json"
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
var PlayAIVoice = class extends voice.MastraVoice {
|
|
130
|
+
baseUrl = "https://api.play.ai/api/v1";
|
|
131
|
+
userId;
|
|
132
|
+
constructor({ speechModel, speaker } = {}) {
|
|
133
|
+
super({
|
|
134
|
+
speechModel: {
|
|
135
|
+
name: speechModel?.name ?? "PlayDialog",
|
|
136
|
+
apiKey: speechModel?.apiKey ?? process.env.PLAYAI_API_KEY
|
|
137
|
+
},
|
|
138
|
+
speaker: speaker ?? PLAYAI_VOICES[0]?.id
|
|
139
|
+
});
|
|
140
|
+
const userId = speechModel?.userId ?? process.env.PLAYAI_USER_ID;
|
|
141
|
+
if (!userId) {
|
|
142
|
+
throw new Error("userId is required");
|
|
143
|
+
}
|
|
144
|
+
this.userId = userId;
|
|
145
|
+
}
|
|
146
|
+
async makeRequest(endpoint, payload, method = "POST") {
|
|
147
|
+
const headers = new Headers({
|
|
148
|
+
Authorization: `Bearer ${this.speechModel?.apiKey}`,
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
"X-USER-ID": this.userId
|
|
151
|
+
});
|
|
152
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
153
|
+
method,
|
|
154
|
+
headers,
|
|
155
|
+
body: payload ? JSON.stringify(payload) : void 0
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
const error = await response.json();
|
|
159
|
+
throw new Error(`PlayAI API Error: ${error.message || response.statusText}`);
|
|
160
|
+
}
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
async streamToString(stream) {
|
|
164
|
+
const chunks = [];
|
|
165
|
+
for await (const chunk of stream) {
|
|
166
|
+
chunks.push(Buffer.from(chunk));
|
|
167
|
+
}
|
|
168
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
169
|
+
}
|
|
170
|
+
async speak(input, options) {
|
|
171
|
+
const text = typeof input === "string" ? input : await this.streamToString(input);
|
|
172
|
+
return this.traced(async () => {
|
|
173
|
+
const payload = {
|
|
174
|
+
text,
|
|
175
|
+
voice: options?.speaker || this.speaker,
|
|
176
|
+
model: this.speechModel?.name
|
|
177
|
+
};
|
|
178
|
+
const response = await this.makeRequest("/tts/stream", payload);
|
|
179
|
+
if (!response.body) {
|
|
180
|
+
throw new Error("No response body received");
|
|
181
|
+
}
|
|
182
|
+
const stream$1 = new stream.PassThrough();
|
|
183
|
+
const reader = response.body.getReader();
|
|
184
|
+
void (async () => {
|
|
185
|
+
try {
|
|
186
|
+
while (true) {
|
|
187
|
+
const { done, value } = await reader.read();
|
|
188
|
+
if (done) {
|
|
189
|
+
stream$1.end();
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
stream$1.write(value);
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
stream$1.destroy(error);
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
return stream$1;
|
|
199
|
+
}, "voice.playai.speak")();
|
|
200
|
+
}
|
|
201
|
+
async listen(_input, _options) {
|
|
202
|
+
throw new Error("PlayAI does not support speech recognition");
|
|
203
|
+
}
|
|
204
|
+
async getSpeakers() {
|
|
205
|
+
return this.traced(
|
|
206
|
+
() => Promise.resolve(
|
|
207
|
+
PLAYAI_VOICES.map((voice) => ({
|
|
208
|
+
voiceId: voice.id,
|
|
209
|
+
name: voice.name,
|
|
210
|
+
accent: voice.accent,
|
|
211
|
+
gender: voice.gender,
|
|
212
|
+
age: voice.age,
|
|
213
|
+
style: voice.style
|
|
214
|
+
}))
|
|
215
|
+
),
|
|
216
|
+
"voice.playai.voices"
|
|
217
|
+
)();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
exports.PLAYAI_VOICES = PLAYAI_VOICES;
|
|
222
|
+
exports.PlayAIVoice = PlayAIVoice;
|
package/dist/index.d.cts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
2
1
|
import { PassThrough } from 'stream';
|
|
2
|
+
import { MastraVoice } from '@mastra/core/voice';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var PLAYAI_VOICES = [
|
|
@@ -179,7 +179,7 @@ var PlayAIVoice = class extends MastraVoice {
|
|
|
179
179
|
}
|
|
180
180
|
const stream = new PassThrough();
|
|
181
181
|
const reader = response.body.getReader();
|
|
182
|
-
(async () => {
|
|
182
|
+
void (async () => {
|
|
183
183
|
try {
|
|
184
184
|
while (true) {
|
|
185
185
|
const { done, value } = await reader.read();
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-playai",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.3",
|
|
4
4
|
"description": "Mastra PlayAI voice integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,24 +10,31 @@
|
|
|
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"
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"zod": "^3.24.1",
|
|
19
|
-
"@mastra/core": "^0.4.3-alpha.
|
|
23
|
+
"@mastra/core": "^0.4.3-alpha.3"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
26
|
+
"eslint": "^9.20.1",
|
|
22
27
|
"@microsoft/api-extractor": "^7.49.2",
|
|
23
28
|
"@types/node": "^22.13.1",
|
|
24
29
|
"tsup": "^8.0.1",
|
|
25
30
|
"typescript": "^5.7.3",
|
|
26
|
-
"vitest": "^2.1.8"
|
|
31
|
+
"vitest": "^2.1.8",
|
|
32
|
+
"@internal/lint": "0.0.0"
|
|
27
33
|
},
|
|
28
34
|
"scripts": {
|
|
29
|
-
"build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
35
|
+
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
|
|
30
36
|
"build:watch": "pnpm build --watch",
|
|
31
|
-
"test": "vitest run"
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"lint": "eslint ."
|
|
32
39
|
}
|
|
33
40
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createWriteStream, mkdirSync } from 'fs';
|
|
2
|
+
import { writeFile } from 'fs/promises';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { Readable } from 'stream';
|
|
4
5
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
5
6
|
|
|
6
|
-
import { writeFile } from 'fs/promises';
|
|
7
|
-
|
|
8
7
|
import { PlayAIVoice, PLAYAI_VOICES } from './index.js';
|
|
9
8
|
|
|
10
9
|
describe('PlayAI Voice Integration Tests', () => {
|
|
@@ -22,7 +21,7 @@ describe('PlayAI Voice Integration Tests', () => {
|
|
|
22
21
|
// Create output directory if it doesn't exist
|
|
23
22
|
try {
|
|
24
23
|
mkdirSync(outputDir, { recursive: true });
|
|
25
|
-
} catch
|
|
24
|
+
} catch {
|
|
26
25
|
// Ignore if directory already exists
|
|
27
26
|
}
|
|
28
27
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
2
1
|
import { PassThrough } from 'stream';
|
|
3
2
|
|
|
3
|
+
import { MastraVoice } from '@mastra/core/voice';
|
|
4
|
+
|
|
4
5
|
interface PlayAIVoiceInfo {
|
|
5
6
|
name: string;
|
|
6
7
|
accent: string;
|
|
@@ -209,7 +210,7 @@ export class PlayAIVoice extends MastraVoice {
|
|
|
209
210
|
|
|
210
211
|
// Process the stream
|
|
211
212
|
const reader = response.body.getReader();
|
|
212
|
-
(async () => {
|
|
213
|
+
void (async () => {
|
|
213
214
|
try {
|
|
214
215
|
while (true) {
|
|
215
216
|
const { done, value } = await reader.read();
|