@mastra/voice-playai 0.1.3-alpha.8 → 0.1.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/dist/index.cjs +5 -1
- package/dist/index.js +5 -1
- package/package.json +14 -11
- package/.turbo/turbo-build.log +0 -23
- package/CHANGELOG.md +0 -233
- package/eslint.config.js +0 -6
- package/src/index.test.ts +0 -143
- package/src/index.ts +0 -255
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -163,7 +163,11 @@ var PlayAIVoice = class extends voice.MastraVoice {
|
|
|
163
163
|
async streamToString(stream) {
|
|
164
164
|
const chunks = [];
|
|
165
165
|
for await (const chunk of stream) {
|
|
166
|
-
|
|
166
|
+
if (typeof chunk === "string") {
|
|
167
|
+
chunks.push(Buffer.from(chunk));
|
|
168
|
+
} else {
|
|
169
|
+
chunks.push(chunk);
|
|
170
|
+
}
|
|
167
171
|
}
|
|
168
172
|
return Buffer.concat(chunks).toString("utf-8");
|
|
169
173
|
}
|
package/dist/index.js
CHANGED
|
@@ -161,7 +161,11 @@ var PlayAIVoice = class extends MastraVoice {
|
|
|
161
161
|
async streamToString(stream) {
|
|
162
162
|
const chunks = [];
|
|
163
163
|
for await (const chunk of stream) {
|
|
164
|
-
|
|
164
|
+
if (typeof chunk === "string") {
|
|
165
|
+
chunks.push(Buffer.from(chunk));
|
|
166
|
+
} else {
|
|
167
|
+
chunks.push(chunk);
|
|
168
|
+
}
|
|
165
169
|
}
|
|
166
170
|
return Buffer.concat(chunks).toString("utf-8");
|
|
167
171
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-playai",
|
|
3
|
-
"version": "0.1.3
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Mastra PlayAI voice integration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"main": "dist/index.js",
|
|
7
10
|
"types": "dist/index.d.ts",
|
|
8
11
|
"exports": {
|
|
@@ -19,20 +22,20 @@
|
|
|
19
22
|
"./package.json": "./package.json"
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"zod": "^3.24.
|
|
23
|
-
"@mastra/core": "^0.5.0
|
|
25
|
+
"zod": "^3.24.2",
|
|
26
|
+
"@mastra/core": "^0.5.0"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"tsup": "^8.0
|
|
30
|
-
"typescript": "^5.
|
|
31
|
-
"vitest": "^2.1.
|
|
32
|
-
"@internal/lint": "0.0.
|
|
29
|
+
"@microsoft/api-extractor": "^7.52.1",
|
|
30
|
+
"@types/node": "^22.13.10",
|
|
31
|
+
"eslint": "^9.22.0",
|
|
32
|
+
"tsup": "^8.4.0",
|
|
33
|
+
"typescript": "^5.8.2",
|
|
34
|
+
"vitest": "^2.1.9",
|
|
35
|
+
"@internal/lint": "0.0.1"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
|
35
|
-
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
|
|
38
|
+
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
36
39
|
"build:watch": "pnpm build --watch",
|
|
37
40
|
"test": "vitest run",
|
|
38
41
|
"lint": "eslint ."
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @mastra/voice-playai@0.1.3-alpha.8 build /home/runner/work/mastra/mastra/voice/playai
|
|
3
|
-
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.3.6
|
|
8
|
-
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in 5982ms
|
|
10
|
-
[34mDTS[39m Build start
|
|
11
|
-
[34mCLI[39m Target: es2022
|
|
12
|
-
Analysis will use the bundled TypeScript version 5.7.3
|
|
13
|
-
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/playai/dist/_tsup-dts-rollup.d.ts[39m
|
|
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 7930ms
|
|
17
|
-
[34mCLI[39m Cleaning output folder
|
|
18
|
-
[34mESM[39m Build start
|
|
19
|
-
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[32m5.97 KB[39m
|
|
21
|
-
[32mESM[39m ⚡️ Build success in 360ms
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m6.03 KB[39m
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in 360ms
|
package/CHANGELOG.md
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# @mastra/voice-playai
|
|
2
|
-
|
|
3
|
-
## 0.1.3-alpha.8
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [506f1d5]
|
|
8
|
-
- @mastra/core@0.5.0-alpha.8
|
|
9
|
-
|
|
10
|
-
## 0.1.3-alpha.7
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Updated dependencies [ee667a2]
|
|
15
|
-
- @mastra/core@0.5.0-alpha.7
|
|
16
|
-
|
|
17
|
-
## 0.1.3-alpha.6
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- Updated dependencies [f6678e4]
|
|
22
|
-
- @mastra/core@0.5.0-alpha.6
|
|
23
|
-
|
|
24
|
-
## 0.1.3-alpha.5
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- Updated dependencies [22643eb]
|
|
29
|
-
- Updated dependencies [6feb23f]
|
|
30
|
-
- Updated dependencies [f2d6727]
|
|
31
|
-
- Updated dependencies [301e4ee]
|
|
32
|
-
- Updated dependencies [dfbe4e9]
|
|
33
|
-
- Updated dependencies [9e81f35]
|
|
34
|
-
- Updated dependencies [caefaa2]
|
|
35
|
-
- Updated dependencies [c151ae6]
|
|
36
|
-
- Updated dependencies [52e0418]
|
|
37
|
-
- Updated dependencies [03236ec]
|
|
38
|
-
- Updated dependencies [3764e71]
|
|
39
|
-
- Updated dependencies [df982db]
|
|
40
|
-
- Updated dependencies [0461849]
|
|
41
|
-
- Updated dependencies [2259379]
|
|
42
|
-
- Updated dependencies [358f069]
|
|
43
|
-
- @mastra/core@0.5.0-alpha.5
|
|
44
|
-
|
|
45
|
-
## 0.1.3-alpha.4
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Updated dependencies [d79aedf]
|
|
50
|
-
- @mastra/core@0.5.0-alpha.4
|
|
51
|
-
|
|
52
|
-
## 0.1.3-alpha.3
|
|
53
|
-
|
|
54
|
-
### Patch Changes
|
|
55
|
-
|
|
56
|
-
- Updated dependencies [3d0e290]
|
|
57
|
-
- @mastra/core@0.5.0-alpha.3
|
|
58
|
-
|
|
59
|
-
## 0.1.3-alpha.2
|
|
60
|
-
|
|
61
|
-
### Patch Changes
|
|
62
|
-
|
|
63
|
-
- Updated dependencies [02ffb7b]
|
|
64
|
-
- @mastra/core@0.5.0-alpha.2
|
|
65
|
-
|
|
66
|
-
## 0.1.3-alpha.1
|
|
67
|
-
|
|
68
|
-
### Patch Changes
|
|
69
|
-
|
|
70
|
-
- Updated dependencies [dab255b]
|
|
71
|
-
- @mastra/core@0.5.0-alpha.1
|
|
72
|
-
|
|
73
|
-
## 0.1.3-alpha.0
|
|
74
|
-
|
|
75
|
-
### Patch Changes
|
|
76
|
-
|
|
77
|
-
- Updated dependencies [59df7b6]
|
|
78
|
-
- Updated dependencies [29f3a82]
|
|
79
|
-
- Updated dependencies [59df7b6]
|
|
80
|
-
- Updated dependencies [c139344]
|
|
81
|
-
- @mastra/core@0.5.0-alpha.0
|
|
82
|
-
|
|
83
|
-
## 0.1.2
|
|
84
|
-
|
|
85
|
-
### Patch Changes
|
|
86
|
-
|
|
87
|
-
- Updated dependencies [1da20e7]
|
|
88
|
-
- @mastra/core@0.4.4
|
|
89
|
-
|
|
90
|
-
## 0.1.2-alpha.0
|
|
91
|
-
|
|
92
|
-
### Patch Changes
|
|
93
|
-
|
|
94
|
-
- Updated dependencies [1da20e7]
|
|
95
|
-
- @mastra/core@0.4.4-alpha.0
|
|
96
|
-
|
|
97
|
-
## 0.1.1
|
|
98
|
-
|
|
99
|
-
### Patch Changes
|
|
100
|
-
|
|
101
|
-
- bb4f447: Add support for commonjs
|
|
102
|
-
- Updated dependencies [0d185b1]
|
|
103
|
-
- Updated dependencies [ed55f1d]
|
|
104
|
-
- Updated dependencies [06aa827]
|
|
105
|
-
- Updated dependencies [0fd78ac]
|
|
106
|
-
- Updated dependencies [2512a93]
|
|
107
|
-
- Updated dependencies [e62de74]
|
|
108
|
-
- Updated dependencies [0d25b75]
|
|
109
|
-
- Updated dependencies [fd14a3f]
|
|
110
|
-
- Updated dependencies [8d13b14]
|
|
111
|
-
- Updated dependencies [3f369a2]
|
|
112
|
-
- Updated dependencies [3ee4831]
|
|
113
|
-
- Updated dependencies [4d4e1e1]
|
|
114
|
-
- Updated dependencies [bb4f447]
|
|
115
|
-
- Updated dependencies [108793c]
|
|
116
|
-
- Updated dependencies [5f28f44]
|
|
117
|
-
- Updated dependencies [dabecf4]
|
|
118
|
-
- @mastra/core@0.4.3
|
|
119
|
-
|
|
120
|
-
## 0.1.1-alpha.4
|
|
121
|
-
|
|
122
|
-
### Patch Changes
|
|
123
|
-
|
|
124
|
-
- Updated dependencies [dabecf4]
|
|
125
|
-
- @mastra/core@0.4.3-alpha.4
|
|
126
|
-
|
|
127
|
-
## 0.1.1-alpha.3
|
|
128
|
-
|
|
129
|
-
### Patch Changes
|
|
130
|
-
|
|
131
|
-
- bb4f447: Add support for commonjs
|
|
132
|
-
- Updated dependencies [0fd78ac]
|
|
133
|
-
- Updated dependencies [0d25b75]
|
|
134
|
-
- Updated dependencies [fd14a3f]
|
|
135
|
-
- Updated dependencies [3f369a2]
|
|
136
|
-
- Updated dependencies [4d4e1e1]
|
|
137
|
-
- Updated dependencies [bb4f447]
|
|
138
|
-
- @mastra/core@0.4.3-alpha.3
|
|
139
|
-
|
|
140
|
-
## 0.1.1-alpha.2
|
|
141
|
-
|
|
142
|
-
### Patch Changes
|
|
143
|
-
|
|
144
|
-
- Updated dependencies [2512a93]
|
|
145
|
-
- Updated dependencies [e62de74]
|
|
146
|
-
- @mastra/core@0.4.3-alpha.2
|
|
147
|
-
|
|
148
|
-
## 0.1.1-alpha.1
|
|
149
|
-
|
|
150
|
-
### Patch Changes
|
|
151
|
-
|
|
152
|
-
- Updated dependencies [0d185b1]
|
|
153
|
-
- Updated dependencies [ed55f1d]
|
|
154
|
-
- Updated dependencies [8d13b14]
|
|
155
|
-
- Updated dependencies [3ee4831]
|
|
156
|
-
- Updated dependencies [108793c]
|
|
157
|
-
- Updated dependencies [5f28f44]
|
|
158
|
-
- @mastra/core@0.4.3-alpha.1
|
|
159
|
-
|
|
160
|
-
## 0.1.1-alpha.0
|
|
161
|
-
|
|
162
|
-
### Patch Changes
|
|
163
|
-
|
|
164
|
-
- Updated dependencies [06aa827]
|
|
165
|
-
- @mastra/core@0.4.3-alpha.0
|
|
166
|
-
|
|
167
|
-
## 0.1.0
|
|
168
|
-
|
|
169
|
-
### Patch Changes
|
|
170
|
-
|
|
171
|
-
- aa72ec5: Fix ts in playai
|
|
172
|
-
- 0503a32: fix ts error
|
|
173
|
-
- 41d0166: deprecate @mastra/speech-playai for @mastra/voice-playai
|
|
174
|
-
- Updated dependencies [7fceae1]
|
|
175
|
-
- Updated dependencies [8d94c3e]
|
|
176
|
-
- Updated dependencies [99dcdb5]
|
|
177
|
-
- Updated dependencies [6cb63e0]
|
|
178
|
-
- Updated dependencies [f626fbb]
|
|
179
|
-
- Updated dependencies [e752340]
|
|
180
|
-
- Updated dependencies [eb91535]
|
|
181
|
-
- @mastra/core@0.4.2
|
|
182
|
-
|
|
183
|
-
## 0.1.0-alpha.4
|
|
184
|
-
|
|
185
|
-
### Patch Changes
|
|
186
|
-
|
|
187
|
-
- Updated dependencies [8d94c3e]
|
|
188
|
-
- Updated dependencies [99dcdb5]
|
|
189
|
-
- Updated dependencies [e752340]
|
|
190
|
-
- Updated dependencies [eb91535]
|
|
191
|
-
- @mastra/core@0.4.2-alpha.2
|
|
192
|
-
|
|
193
|
-
## 0.1.0-alpha.3
|
|
194
|
-
|
|
195
|
-
### Patch Changes
|
|
196
|
-
|
|
197
|
-
- Updated dependencies [6cb63e0]
|
|
198
|
-
- @mastra/core@0.4.2-alpha.1
|
|
199
|
-
|
|
200
|
-
## 0.1.0-alpha.2
|
|
201
|
-
|
|
202
|
-
### Patch Changes
|
|
203
|
-
|
|
204
|
-
- 41d0166: deprecate @mastra/speech-playai for @mastra/voice-playai
|
|
205
|
-
- Updated dependencies [7fceae1]
|
|
206
|
-
- Updated dependencies [f626fbb]
|
|
207
|
-
- @mastra/core@0.4.2-alpha.0
|
|
208
|
-
|
|
209
|
-
## 0.1.0 (2024-XX-XX)
|
|
210
|
-
|
|
211
|
-
This package replaces the deprecated @mastra/speech-playai package. All functionality has been migrated to this new package with a more consistent naming scheme.
|
|
212
|
-
|
|
213
|
-
### Changes from @mastra/speech-playai
|
|
214
|
-
|
|
215
|
-
- Package renamed from @mastra/speech-playai to @mastra/voice-playai
|
|
216
|
-
- API changes:
|
|
217
|
-
- `PlayAITTS` class renamed to `PlayAIVoice`
|
|
218
|
-
- `generate()` and `stream()` methods combined into `speak()`
|
|
219
|
-
- `voices()` method renamed to `getSpeakers()`
|
|
220
|
-
- Constructor configuration simplified
|
|
221
|
-
- Added support for text stream input
|
|
222
|
-
- Default speaker configuration added
|
|
223
|
-
- All core functionality remains the same
|
|
224
|
-
- Import paths should be updated from '@mastra/speech-playai' to '@mastra/voice-playai'
|
|
225
|
-
|
|
226
|
-
### Key Features Preserved
|
|
227
|
-
|
|
228
|
-
- High-quality voice synthesis
|
|
229
|
-
- Multiple voice options with rich metadata
|
|
230
|
-
- Streaming support
|
|
231
|
-
- Natural and expressive speech output
|
|
232
|
-
|
|
233
|
-
For a complete history of changes prior to the rename, please see the changelog of the original package.
|
package/eslint.config.js
DELETED
package/src/index.test.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { createWriteStream, mkdirSync } from 'fs';
|
|
2
|
-
import { writeFile } from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { Readable } from 'stream';
|
|
5
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { PlayAIVoice, PLAYAI_VOICES } from './index.js';
|
|
8
|
-
|
|
9
|
-
describe('PlayAI Voice Integration Tests', () => {
|
|
10
|
-
const voice = new PlayAIVoice({
|
|
11
|
-
speechModel: {
|
|
12
|
-
name: 'PlayDialog',
|
|
13
|
-
apiKey: process.env.PLAYAI_API_KEY!,
|
|
14
|
-
userId: process.env.PLAYAI_USER_ID!,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const outputDir = path.join(process.cwd(), 'test-outputs');
|
|
18
|
-
let voiceId: string;
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
// Create output directory if it doesn't exist
|
|
22
|
-
try {
|
|
23
|
-
mkdirSync(outputDir, { recursive: true });
|
|
24
|
-
} catch {
|
|
25
|
-
// Ignore if directory already exists
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const speakers = await voice.getSpeakers();
|
|
29
|
-
voiceId = speakers.find(
|
|
30
|
-
v => v.voiceId === 's3://voice-cloning-zero-shot/1591b954-8760-41a9-bc58-9176a68c5726/original/manifest.json',
|
|
31
|
-
)!.voiceId;
|
|
32
|
-
expect(voiceId).toBeDefined();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should verify available speakers', async () => {
|
|
36
|
-
const speakers = await voice.getSpeakers();
|
|
37
|
-
expect(speakers.length).toBeGreaterThan(0);
|
|
38
|
-
expect(speakers[0]).toHaveProperty('voiceId');
|
|
39
|
-
expect(speakers[0].voiceId).toBe(PLAYAI_VOICES[0].id);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should allow immediate playback while streaming', async () => {
|
|
43
|
-
// Create a longer text to ensure we get multiple chunks
|
|
44
|
-
const longText = 'This is a longer text that will be streamed. '.repeat(5);
|
|
45
|
-
|
|
46
|
-
const audioStream = await voice.speak(longText, {
|
|
47
|
-
speaker: voiceId,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Create a write stream to simulate real-time playback
|
|
51
|
-
const outputPath = path.join(outputDir, 'playai-streaming-output.mp3');
|
|
52
|
-
const writeStream = createWriteStream(outputPath);
|
|
53
|
-
|
|
54
|
-
let firstChunkTime: number | null = null;
|
|
55
|
-
let lastChunkTime: number | null = null;
|
|
56
|
-
let totalChunks = 0;
|
|
57
|
-
|
|
58
|
-
for await (const chunk of audioStream) {
|
|
59
|
-
if (!firstChunkTime) {
|
|
60
|
-
firstChunkTime = Date.now();
|
|
61
|
-
}
|
|
62
|
-
lastChunkTime = Date.now();
|
|
63
|
-
totalChunks++;
|
|
64
|
-
writeStream.write(chunk);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
writeStream.end();
|
|
68
|
-
expect(firstChunkTime).toBeDefined();
|
|
69
|
-
expect(lastChunkTime).toBeDefined();
|
|
70
|
-
expect(lastChunkTime! - firstChunkTime!).toBeGreaterThan(100); // Should take some time to receive all chunks
|
|
71
|
-
console.log(`Total streaming time: ${lastChunkTime! - firstChunkTime!}ms for ${totalChunks} chunks`);
|
|
72
|
-
}, 30000);
|
|
73
|
-
|
|
74
|
-
it('should test speak method', async () => {
|
|
75
|
-
const audioStream = await voice.speak('Hello from PlayAI!', {
|
|
76
|
-
speaker: voiceId,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const chunks: Buffer[] = [];
|
|
80
|
-
for await (const chunk of audioStream) {
|
|
81
|
-
chunks.push(Buffer.from(chunk));
|
|
82
|
-
}
|
|
83
|
-
const audioBuffer = Buffer.concat(chunks);
|
|
84
|
-
|
|
85
|
-
await writeFile(path.join(outputDir, 'playai-generate-output.mp3'), audioBuffer);
|
|
86
|
-
expect(audioBuffer.length).toBeGreaterThan(0);
|
|
87
|
-
}, 30000);
|
|
88
|
-
|
|
89
|
-
it('should handle stream input in speak method', async () => {
|
|
90
|
-
// Create a readable stream from text
|
|
91
|
-
const textStream = Readable.from(['Hello', ' from', ' stream', ' input!']);
|
|
92
|
-
|
|
93
|
-
const audioStream = await voice.speak(textStream, {
|
|
94
|
-
speaker: voiceId,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const chunks: Buffer[] = [];
|
|
98
|
-
for await (const chunk of audioStream) {
|
|
99
|
-
chunks.push(Buffer.from(chunk));
|
|
100
|
-
}
|
|
101
|
-
const audioBuffer = Buffer.concat(chunks);
|
|
102
|
-
|
|
103
|
-
await writeFile(path.join(outputDir, 'playai-stream-input-output.mp3'), audioBuffer);
|
|
104
|
-
expect(audioBuffer.length).toBeGreaterThan(0);
|
|
105
|
-
}, 30000);
|
|
106
|
-
|
|
107
|
-
it('should handle errors gracefully', async () => {
|
|
108
|
-
// Test with invalid voice ID
|
|
109
|
-
await expect(
|
|
110
|
-
voice.speak('Hello', {
|
|
111
|
-
speaker: 'invalid-voice-id',
|
|
112
|
-
}),
|
|
113
|
-
).rejects.toThrow();
|
|
114
|
-
|
|
115
|
-
// Test with empty text
|
|
116
|
-
await expect(
|
|
117
|
-
voice.speak('', {
|
|
118
|
-
speaker: voiceId,
|
|
119
|
-
}),
|
|
120
|
-
).rejects.toThrow();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should work with default configuration', async () => {
|
|
124
|
-
// Create instance with no args
|
|
125
|
-
const defaultVoice = new PlayAIVoice();
|
|
126
|
-
|
|
127
|
-
// Should use default model name and get API key and userId from env
|
|
128
|
-
const audioStream = await defaultVoice.speak('Testing default configuration');
|
|
129
|
-
|
|
130
|
-
const chunks: Buffer[] = [];
|
|
131
|
-
for await (const chunk of audioStream) {
|
|
132
|
-
chunks.push(Buffer.from(chunk));
|
|
133
|
-
}
|
|
134
|
-
const audioBuffer = Buffer.concat(chunks);
|
|
135
|
-
|
|
136
|
-
await writeFile(path.join(outputDir, 'playai-default-config-output.mp3'), audioBuffer);
|
|
137
|
-
expect(audioBuffer.length).toBeGreaterThan(0);
|
|
138
|
-
|
|
139
|
-
// Verify default speaker was used
|
|
140
|
-
const speakers = await defaultVoice.getSpeakers();
|
|
141
|
-
expect(speakers.length).toBeGreaterThan(0);
|
|
142
|
-
}, 30000);
|
|
143
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from 'stream';
|
|
2
|
-
|
|
3
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
4
|
-
|
|
5
|
-
interface PlayAIVoiceInfo {
|
|
6
|
-
name: string;
|
|
7
|
-
accent: string;
|
|
8
|
-
gender: 'M' | 'F';
|
|
9
|
-
age: 'Young' | 'Middle' | 'Old';
|
|
10
|
-
style: 'Conversational' | 'Narrative';
|
|
11
|
-
id: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const PLAYAI_VOICES: PlayAIVoiceInfo[] = [
|
|
15
|
-
{
|
|
16
|
-
name: 'Angelo',
|
|
17
|
-
accent: 'US',
|
|
18
|
-
gender: 'M',
|
|
19
|
-
age: 'Young',
|
|
20
|
-
style: 'Conversational',
|
|
21
|
-
id: 's3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'Arsenio',
|
|
25
|
-
accent: 'US African American',
|
|
26
|
-
gender: 'M',
|
|
27
|
-
age: 'Middle',
|
|
28
|
-
style: 'Conversational',
|
|
29
|
-
id: 's3://voice-cloning-zero-shot/65977f5e-a22a-4b36-861b-ecede19bdd65/original/manifest.json',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'Cillian',
|
|
33
|
-
accent: 'Irish',
|
|
34
|
-
gender: 'M',
|
|
35
|
-
age: 'Middle',
|
|
36
|
-
style: 'Conversational',
|
|
37
|
-
id: 's3://voice-cloning-zero-shot/1591b954-8760-41a9-bc58-9176a68c5726/original/manifest.json',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'Timo',
|
|
41
|
-
accent: 'US',
|
|
42
|
-
gender: 'M',
|
|
43
|
-
age: 'Middle',
|
|
44
|
-
style: 'Conversational',
|
|
45
|
-
id: 's3://voice-cloning-zero-shot/677a4ae3-252f-476e-85ce-eeed68e85951/original/manifest.json',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'Dexter',
|
|
49
|
-
accent: 'US',
|
|
50
|
-
gender: 'M',
|
|
51
|
-
age: 'Middle',
|
|
52
|
-
style: 'Conversational',
|
|
53
|
-
id: 's3://voice-cloning-zero-shot/b27bc13e-996f-4841-b584-4d35801aea98/original/manifest.json',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'Miles',
|
|
57
|
-
accent: 'US African American',
|
|
58
|
-
gender: 'M',
|
|
59
|
-
age: 'Young',
|
|
60
|
-
style: 'Conversational',
|
|
61
|
-
id: 's3://voice-cloning-zero-shot/29dd9a52-bd32-4a6e-bff1-bbb98dcc286a/original/manifest.json',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: 'Briggs',
|
|
65
|
-
accent: 'US Southern (Oklahoma)',
|
|
66
|
-
gender: 'M',
|
|
67
|
-
age: 'Old',
|
|
68
|
-
style: 'Conversational',
|
|
69
|
-
id: 's3://voice-cloning-zero-shot/71cdb799-1e03-41c6-8a05-f7cd55134b0b/original/manifest.json',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: 'Deedee',
|
|
73
|
-
accent: 'US African American',
|
|
74
|
-
gender: 'F',
|
|
75
|
-
age: 'Middle',
|
|
76
|
-
style: 'Conversational',
|
|
77
|
-
id: 's3://voice-cloning-zero-shot/e040bd1b-f190-4bdb-83f0-75ef85b18f84/original/manifest.json',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'Nia',
|
|
81
|
-
accent: 'US',
|
|
82
|
-
gender: 'F',
|
|
83
|
-
age: 'Young',
|
|
84
|
-
style: 'Conversational',
|
|
85
|
-
id: 's3://voice-cloning-zero-shot/831bd330-85c6-4333-b2b4-10c476ea3491/original/manifest.json',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: 'Inara',
|
|
89
|
-
accent: 'US African American',
|
|
90
|
-
gender: 'F',
|
|
91
|
-
age: 'Middle',
|
|
92
|
-
style: 'Conversational',
|
|
93
|
-
id: 's3://voice-cloning-zero-shot/adb83b67-8d75-48ff-ad4d-a0840d231ef1/original/manifest.json',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'Constanza',
|
|
97
|
-
accent: 'US Latin American',
|
|
98
|
-
gender: 'F',
|
|
99
|
-
age: 'Young',
|
|
100
|
-
style: 'Conversational',
|
|
101
|
-
id: 's3://voice-cloning-zero-shot/b0aca4d7-1738-4848-a80b-307ac44a7298/original/manifest.json',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: 'Gideon',
|
|
105
|
-
accent: 'British',
|
|
106
|
-
gender: 'M',
|
|
107
|
-
age: 'Old',
|
|
108
|
-
style: 'Narrative',
|
|
109
|
-
id: 's3://voice-cloning-zero-shot/5a3a1168-7793-4b2c-8f90-aff2b5232131/original/manifest.json',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'Casper',
|
|
113
|
-
accent: 'US',
|
|
114
|
-
gender: 'M',
|
|
115
|
-
age: 'Middle',
|
|
116
|
-
style: 'Narrative',
|
|
117
|
-
id: 's3://voice-cloning-zero-shot/1bbc6986-fadf-4bd8-98aa-b86fed0476e9/original/manifest.json',
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: 'Mitch',
|
|
121
|
-
accent: 'Australian',
|
|
122
|
-
gender: 'M',
|
|
123
|
-
age: 'Middle',
|
|
124
|
-
style: 'Narrative',
|
|
125
|
-
id: 's3://voice-cloning-zero-shot/c14e50f2-c5e3-47d1-8c45-fa4b67803d19/original/manifest.json',
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'Ava',
|
|
129
|
-
accent: 'Australian',
|
|
130
|
-
gender: 'F',
|
|
131
|
-
age: 'Middle',
|
|
132
|
-
style: 'Narrative',
|
|
133
|
-
id: 's3://voice-cloning-zero-shot/50381567-ff7b-46d2-bfdc-a9584a85e08d/original/manifest.json',
|
|
134
|
-
},
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
interface PlayAIConfig {
|
|
138
|
-
name?: 'PlayDialog' | 'Play3.0-mini';
|
|
139
|
-
apiKey?: string;
|
|
140
|
-
userId?: string;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export class PlayAIVoice extends MastraVoice {
|
|
144
|
-
private baseUrl = 'https://api.play.ai/api/v1';
|
|
145
|
-
private userId: string;
|
|
146
|
-
|
|
147
|
-
constructor({ speechModel, speaker }: { speechModel?: PlayAIConfig; speaker?: string } = {}) {
|
|
148
|
-
super({
|
|
149
|
-
speechModel: {
|
|
150
|
-
name: speechModel?.name ?? 'PlayDialog',
|
|
151
|
-
apiKey: speechModel?.apiKey ?? process.env.PLAYAI_API_KEY,
|
|
152
|
-
},
|
|
153
|
-
speaker: speaker ?? PLAYAI_VOICES[0]?.id,
|
|
154
|
-
});
|
|
155
|
-
const userId = speechModel?.userId ?? process.env.PLAYAI_USER_ID;
|
|
156
|
-
if (!userId) {
|
|
157
|
-
throw new Error('userId is required');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.userId = userId;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private async makeRequest(endpoint: string, payload?: any, method: 'GET' | 'POST' = 'POST') {
|
|
164
|
-
const headers = new Headers({
|
|
165
|
-
Authorization: `Bearer ${this.speechModel?.apiKey}`,
|
|
166
|
-
'Content-Type': 'application/json',
|
|
167
|
-
'X-USER-ID': this.userId,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
171
|
-
method,
|
|
172
|
-
headers,
|
|
173
|
-
body: payload ? JSON.stringify(payload) : undefined,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
if (!response.ok) {
|
|
177
|
-
const error = (await response.json()) as { message: string };
|
|
178
|
-
|
|
179
|
-
throw new Error(`PlayAI API Error: ${error.message || response.statusText}`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return response;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private async streamToString(stream: NodeJS.ReadableStream): Promise<string> {
|
|
186
|
-
const chunks: Buffer[] = [];
|
|
187
|
-
for await (const chunk of stream) {
|
|
188
|
-
chunks.push(Buffer.from(chunk));
|
|
189
|
-
}
|
|
190
|
-
return Buffer.concat(chunks).toString('utf-8');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async speak(input: string | NodeJS.ReadableStream, options?: { speaker?: string }): Promise<NodeJS.ReadableStream> {
|
|
194
|
-
const text = typeof input === 'string' ? input : await this.streamToString(input);
|
|
195
|
-
|
|
196
|
-
return this.traced(async () => {
|
|
197
|
-
const payload = {
|
|
198
|
-
text,
|
|
199
|
-
voice: options?.speaker || this.speaker,
|
|
200
|
-
model: this.speechModel?.name,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const response = await this.makeRequest('/tts/stream', payload);
|
|
204
|
-
if (!response.body) {
|
|
205
|
-
throw new Error('No response body received');
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Create a PassThrough stream for the audio
|
|
209
|
-
const stream = new PassThrough();
|
|
210
|
-
|
|
211
|
-
// Process the stream
|
|
212
|
-
const reader = response.body.getReader();
|
|
213
|
-
void (async () => {
|
|
214
|
-
try {
|
|
215
|
-
while (true) {
|
|
216
|
-
const { done, value } = await reader.read();
|
|
217
|
-
if (done) {
|
|
218
|
-
stream.end();
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
stream.write(value);
|
|
222
|
-
}
|
|
223
|
-
} catch (error) {
|
|
224
|
-
stream.destroy(error as Error);
|
|
225
|
-
}
|
|
226
|
-
})();
|
|
227
|
-
|
|
228
|
-
return stream;
|
|
229
|
-
}, 'voice.playai.speak')();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async listen(
|
|
233
|
-
_input: NodeJS.ReadableStream,
|
|
234
|
-
_options?: Record<string, unknown>,
|
|
235
|
-
): Promise<string | NodeJS.ReadableStream> {
|
|
236
|
-
throw new Error('PlayAI does not support speech recognition');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async getSpeakers() {
|
|
240
|
-
return this.traced(
|
|
241
|
-
() =>
|
|
242
|
-
Promise.resolve(
|
|
243
|
-
PLAYAI_VOICES.map(voice => ({
|
|
244
|
-
voiceId: voice.id,
|
|
245
|
-
name: voice.name,
|
|
246
|
-
accent: voice.accent,
|
|
247
|
-
gender: voice.gender,
|
|
248
|
-
age: voice.age,
|
|
249
|
-
style: voice.style,
|
|
250
|
-
})),
|
|
251
|
-
),
|
|
252
|
-
'voice.playai.voices',
|
|
253
|
-
)();
|
|
254
|
-
}
|
|
255
|
-
}
|
package/tsconfig.json
DELETED