jbc-dssi 1.1.157 → 1.1.159
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/edge-tts.js +7 -8
- package/lib/sec-ms-gec.cjs +61 -0
- package/package.json +1 -1
package/lib/edge-tts.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import SecMsGec from '
|
|
3
|
+
import SecMsGec from './sec-ms-gec.cjs';
|
|
4
4
|
|
|
5
5
|
const { hashSecMsGecV2 } = SecMsGec;
|
|
6
6
|
|
|
7
7
|
export const EDGE_VOICES = [
|
|
8
8
|
{ id: 'zh-CN-XiaoxiaoNeural', name: '晓晓', gender: '女声', note: '温暖自然' },
|
|
9
9
|
{ id: 'zh-CN-XiaoyiNeural', name: '晓伊', gender: '女声', note: '活泼' },
|
|
10
|
-
{ id: 'zh-CN-XiaoxuanNeural', name: '晓萱', gender: '女声', note: '知性' },
|
|
11
|
-
{ id: 'zh-CN-XiaochenNeural', name: '晓辰', gender: '女声', note: '温柔' },
|
|
12
|
-
{ id: 'zh-CN-XiaohanNeural', name: '晓涵', gender: '女声', note: '亲和' },
|
|
13
|
-
{ id: 'zh-CN-XiaomengNeural', name: '晓梦', gender: '女声', note: '甜' },
|
|
14
|
-
{ id: 'zh-CN-XiaomoNeural', name: '晓墨', gender: '女声', note: '沉稳' },
|
|
15
|
-
{ id: 'zh-CN-XiaoruiNeural', name: '晓睿', gender: '女声', note: '成熟' },
|
|
16
10
|
{ id: 'zh-CN-YunxiNeural', name: '云希', gender: '男声', note: '阳光' },
|
|
17
11
|
{ id: 'zh-CN-YunyangNeural', name: '云扬', gender: '男声', note: '专业播报' },
|
|
18
12
|
{ id: 'zh-CN-YunjianNeural', name: '云健', gender: '男声', note: '浑厚' },
|
|
19
13
|
{ id: 'zh-CN-YunxiaNeural', name: '云夏', gender: '男声', note: '少年' },
|
|
20
|
-
{ id: 'zh-CN-YunzeNeural', name: '云泽', gender: '男声', note: '稳重' },
|
|
21
14
|
{ id: 'zh-CN-liaoning-XiaobeiNeural', name: '晓北', gender: '女声', note: '东北话' },
|
|
22
15
|
{ id: 'zh-CN-shaanxi-XiaoniNeural', name: '晓妮', gender: '女声', note: '陕西话' },
|
|
16
|
+
{ id: 'zh-HK-HiuGaaiNeural', name: '曉佳', gender: '女声', note: '粤语' },
|
|
17
|
+
{ id: 'zh-HK-HiuMaanNeural', name: '曉曼', gender: '女声', note: '粤语' },
|
|
18
|
+
{ id: 'zh-HK-WanLungNeural', name: '雲龍', gender: '男声', note: '粤语' },
|
|
19
|
+
{ id: 'zh-TW-HsiaoChenNeural', name: '曉臻', gender: '女声', note: '台湾国语' },
|
|
20
|
+
{ id: 'zh-TW-HsiaoYuNeural', name: '曉雨', gender: '女声', note: '台湾国语' },
|
|
21
|
+
{ id: 'zh-TW-YunJheNeural', name: '雲哲', gender: '男声', note: '台湾国语' },
|
|
23
22
|
];
|
|
24
23
|
|
|
25
24
|
export const DEFAULT_EDGE_VOICE = 'zh-CN-XiaoxiaoNeural';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashSecMsGecV2 = hashSecMsGecV2;
|
|
4
|
+
// Sec-MS-GEC v2 is "<CS64 checksum>-<SHA-256>" of Edge's copyright line followed by the v1 input.
|
|
5
|
+
// Worked out from the analysis in https://github.com/rany2/edge-tts/pull/492.
|
|
6
|
+
const EDGE_COPYRIGHT = "Copyright (C) Microsoft Corporation. All rights reserved.";
|
|
7
|
+
const SWAP_FIRST_WORD = { swappedWord: 0xEF0569FB, swappedSum: 0x76F50F34, swappedProduct: 0xC3EFEA97 };
|
|
8
|
+
const SWAP_SECOND_WORD = { swappedWord: 0xC31713DB, swappedSum: 0x1881CE3C, swappedProduct: 0x35BD1EC9 };
|
|
9
|
+
const MIX_FIRST_WORD = [0xCF98B111, 0x87085B9F, 0x12CEB96D, 0x257E1D83];
|
|
10
|
+
const MIX_SECOND_WORD = [0xA27416F5, 0xD38396FF, 0x7C932B89, 0xBFA49F69];
|
|
11
|
+
async function hashSecMsGecV2(ticksAndToken) {
|
|
12
|
+
const message = new TextEncoder().encode(EDGE_COPYRIGHT + ticksAndToken);
|
|
13
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", message));
|
|
14
|
+
return `${toUpperHex(cs64(message, digest))}-${toUpperHex(digest)}`;
|
|
15
|
+
}
|
|
16
|
+
function cs64(message, digest) {
|
|
17
|
+
const digestView = new DataView(digest.buffer, digest.byteOffset, digest.byteLength);
|
|
18
|
+
const firstKey = (digestView.getUint32(0, true) | 1) >>> 0;
|
|
19
|
+
const secondKey = (digestView.getUint32(4, true) | 1) >>> 0;
|
|
20
|
+
// The message is read as little-endian 32-bit word pairs, zero-padded to a whole pair.
|
|
21
|
+
const padded = new Uint8Array(Math.ceil(message.length / 8) * 8);
|
|
22
|
+
padded.set(message);
|
|
23
|
+
const words = new DataView(padded.buffer);
|
|
24
|
+
let swapSum = 0;
|
|
25
|
+
let lastSwap = 0;
|
|
26
|
+
let mix = 0;
|
|
27
|
+
let mixSum = 0;
|
|
28
|
+
for (let offset = 0; offset < padded.length; offset += 8) {
|
|
29
|
+
const firstWord = words.getUint32(offset, true);
|
|
30
|
+
const secondWord = words.getUint32(offset + 4, true);
|
|
31
|
+
const firstSwap = swapTerm(firstWord, firstKey, SWAP_FIRST_WORD);
|
|
32
|
+
lastSwap = swapTerm(secondWord, secondKey, SWAP_SECOND_WORD);
|
|
33
|
+
swapSum = (swapSum + firstSwap + lastSwap) >>> 0;
|
|
34
|
+
mix = swapAndMultiply(Math.imul(mix + firstWord, firstKey), MIX_FIRST_WORD);
|
|
35
|
+
mixSum = (mixSum + mix) >>> 0;
|
|
36
|
+
mix = swapAndMultiply(Math.imul(mix + secondWord, secondKey), MIX_SECOND_WORD);
|
|
37
|
+
mixSum = (mixSum + mix) >>> 0;
|
|
38
|
+
}
|
|
39
|
+
const checksum = new Uint8Array(8);
|
|
40
|
+
const checksumView = new DataView(checksum.buffer);
|
|
41
|
+
checksumView.setUint32(0, lastSwap ^ mix, true);
|
|
42
|
+
checksumView.setUint32(4, swapSum ^ mixSum, true);
|
|
43
|
+
return checksum;
|
|
44
|
+
}
|
|
45
|
+
function swapTerm(word, key, multipliers) {
|
|
46
|
+
const sum = Math.imul(word, key) + Math.imul(swapHalves(word), multipliers.swappedWord);
|
|
47
|
+
const product = Math.imul(swapHalves(sum), multipliers.swappedSum) >>> 0;
|
|
48
|
+
return (Math.imul(swapHalves(product), multipliers.swappedProduct) + product) >>> 0;
|
|
49
|
+
}
|
|
50
|
+
function swapAndMultiply(value, multipliers) {
|
|
51
|
+
for (const multiplier of multipliers) {
|
|
52
|
+
value = Math.imul(swapHalves(value), multiplier) >>> 0;
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function swapHalves(value) {
|
|
57
|
+
return ((value << 16) | (value >>> 16)) >>> 0;
|
|
58
|
+
}
|
|
59
|
+
function toUpperHex(bytes) {
|
|
60
|
+
return Array.from(bytes, b => b.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
61
|
+
}
|