@mastra/voice-playai 0.1.1-alpha.1 → 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-playai@0.1.1-alpha.1 build /home/runner/work/mastra/mastra/voice/playai
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
  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 6440ms
9
+ TSC ⚡️ Build success in 6392ms
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/playai/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 5288ms
14
+ Analysis will use the bundled TypeScript version 5.7.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/voice/playai/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 8230ms
15
17
  CLI Cleaning output folder
16
18
  ESM Build start
19
+ CJS Build start
20
+ CJS dist/index.cjs 6.03 KB
21
+ CJS ⚡️ Build success in 448ms
17
22
  ESM dist/index.js 5.97 KB
18
- ESM ⚡️ Build success in 252ms
23
+ ESM ⚡️ Build success in 452ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
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
+
3
24
  ## 0.1.1-alpha.1
4
25
 
5
26
  ### 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;
@@ -0,0 +1,2 @@
1
+ export { PLAYAI_VOICES } from './_tsup-dts-rollup.cjs';
2
+ export { PlayAIVoice } from './_tsup-dts-rollup.cjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/voice-playai",
3
- "version": "0.1.1-alpha.1",
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,13 +10,17 @@
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.1"
23
+ "@mastra/core": "^0.4.3-alpha.3"
20
24
  },
21
25
  "devDependencies": {
22
26
  "eslint": "^9.20.1",
@@ -28,7 +32,7 @@
28
32
  "@internal/lint": "0.0.0"
29
33
  },
30
34
  "scripts": {
31
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
35
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
32
36
  "build:watch": "pnpm build --watch",
33
37
  "test": "vitest run",
34
38
  "lint": "eslint ."