@zhin.js/speech 1.0.1 → 1.0.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/lib/tts/edge.d.ts.map +1 -1
- package/lib/tts/edge.js +3 -4
- package/lib/tts/edge.js.map +1 -1
- package/package.json +3 -3
- package/src/tts/edge.ts +5 -6
package/lib/tts/edge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../src/tts/edge.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAA2C,MAAM,aAAa,CAAC;AAInG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../src/tts/edge.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAA2C,MAAM,aAAa,CAAC;AAInG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW,CAsBpE"}
|
package/lib/tts/edge.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
3
|
import { readFile, unlink } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
|
-
const
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
8
|
export function createEdgeTtsProvider(config) {
|
|
9
9
|
return {
|
|
10
10
|
id: 'edge',
|
|
@@ -14,9 +14,8 @@ export function createEdgeTtsProvider(config) {
|
|
|
14
14
|
const pitch = config.pitch || '+0Hz';
|
|
15
15
|
const cmd = config.edgeTtsCommand || 'edge-tts';
|
|
16
16
|
const tmpFile = join(tmpdir(), `zhin-tts-${randomBytes(8).toString('hex')}.mp3`);
|
|
17
|
-
const safeText = input.text.replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
18
17
|
try {
|
|
19
|
-
await
|
|
18
|
+
await execFileAsync(cmd, ['--voice', voice, `--rate=${rate}`, `--pitch=${pitch}`, '--text', input.text, '--write-media', tmpFile], { timeout: 30_000 });
|
|
20
19
|
const data = await readFile(tmpFile);
|
|
21
20
|
return { data, format: 'mp3' };
|
|
22
21
|
}
|
package/lib/tts/edge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge.js","sourceRoot":"","sources":["../../src/tts/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"edge.js","sourceRoot":"","sources":["../../src/tts/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,UAAU,qBAAqB,CAAC,MAAiB;IACrD,OAAO;QACL,EAAE,EAAE,MAAM;QACV,KAAK,CAAC,UAAU,CAAC,KAAyB;YACxC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,IAAI,sBAAsB,CAAC;YACpE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC;YAClC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC;YACrC,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,IAAI,UAAU,CAAC;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,YAAY,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACjF,IAAI,CAAC;gBACH,MAAM,aAAa,CACjB,GAAG,EACH,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,IAAI,EAAE,EAAE,WAAW,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EACxG,EAAE,OAAO,EAAE,MAAM,EAAE,CACpB,CAAC;gBACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACrC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACjC,CAAC;oBAAS,CAAC;gBACT,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/speech",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "STT/TTS for Zhin.js (Whisper + edge/openai/azure/custom TTS); optional peer of zhin.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@zhin.js/core": "1.3.
|
|
37
|
+
"@zhin.js/core": "1.3.4"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@zhin.js/core": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
|
-
"@zhin.js/core": "1.3.
|
|
46
|
+
"@zhin.js/core": "1.3.4"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|
package/src/tts/edge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
3
|
import { readFile, unlink } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
@@ -6,7 +6,7 @@ import { join } from 'node:path';
|
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
7
|
import type { TTSConfig, TtsProvider, TtsSynthesizeInput, TtsSynthesizeResult } from '../types.js';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
10
|
|
|
11
11
|
export function createEdgeTtsProvider(config: TTSConfig): TtsProvider {
|
|
12
12
|
return {
|
|
@@ -17,11 +17,10 @@ export function createEdgeTtsProvider(config: TTSConfig): TtsProvider {
|
|
|
17
17
|
const pitch = config.pitch || '+0Hz';
|
|
18
18
|
const cmd = config.edgeTtsCommand || 'edge-tts';
|
|
19
19
|
const tmpFile = join(tmpdir(), `zhin-tts-${randomBytes(8).toString('hex')}.mp3`);
|
|
20
|
-
const safeText = input.text.replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
21
|
-
|
|
22
20
|
try {
|
|
23
|
-
await
|
|
24
|
-
|
|
21
|
+
await execFileAsync(
|
|
22
|
+
cmd,
|
|
23
|
+
['--voice', voice, `--rate=${rate}`, `--pitch=${pitch}`, '--text', input.text, '--write-media', tmpFile],
|
|
25
24
|
{ timeout: 30_000 },
|
|
26
25
|
);
|
|
27
26
|
const data = await readFile(tmpFile);
|