Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-edge-tts

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-edge-tts - npm Package Compare versions

Comparing version 1.2.5 to 1.2.6

dist/drm.d.ts

119

dist/edge-tts.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,2 +8,3 @@ exports.EdgeTTS = void 0;

const https_proxy_agent_1 = require("https-proxy-agent");
const drm_1 = require("./drm");
class EdgeTTS {

@@ -30,15 +22,14 @@ constructor({ voice = 'zh-CN-XiaoyiNeural', lang = 'zh-CN', outputFormat = 'audio-24khz-48kbitrate-mono-mp3', saveSubtitles = false, proxy, rate = 'default', pitch = 'default', volume = 'default', timeout = 10000 } = {}) {

}
_connectWebSocket() {
return __awaiter(this, void 0, void 0, function* () {
const wsConnect = new ws_1.WebSocket(`wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=6A5AA1D4EAFF4E9FB37E23D68491D6F4`, {
host: 'speech.platform.bing.com',
origin: 'chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
},
agent: this.proxy ? new https_proxy_agent_1.HttpsProxyAgent(this.proxy) : undefined
});
return new Promise((resolve) => {
wsConnect.on('open', () => {
wsConnect.send(`Content-Type:application/json; charset=utf-8\r\nPath:speech.config\r\n\r\n
async _connectWebSocket() {
const wsConnect = new ws_1.WebSocket(`wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=${drm_1.TRUSTED_CLIENT_TOKEN}&Sec-MS-GEC=${(0, drm_1.generateSecMsGecToken)()}&Sec-MS-GEC-Version=1-${drm_1.CHROMIUM_FULL_VERSION}`, {
host: 'speech.platform.bing.com',
origin: 'chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
},
agent: this.proxy ? new https_proxy_agent_1.HttpsProxyAgent(this.proxy) : undefined
});
return new Promise((resolve) => {
wsConnect.on('open', () => {
wsConnect.send(`Content-Type:application/json; charset=utf-8\r\nPath:speech.config\r\n\r\n
{

@@ -58,4 +49,3 @@ "context": {

`);
resolve(wsConnect);
});
resolve(wsConnect);
});

@@ -69,3 +59,2 @@ });

subFile.forEach((cue, index) => {
var _a, _b;
let fullPart = '';

@@ -78,3 +67,3 @@ let stepIndex = 0;

}
else if (subChars[sci] === ((_b = (_a = subFile === null || subFile === void 0 ? void 0 : subFile[index + 1]) === null || _a === void 0 ? void 0 : _a.part) === null || _b === void 0 ? void 0 : _b[0])) {
else if (subChars[sci] === subFile?.[index + 1]?.part?.[0]) {
subCharIndex = sci;

@@ -91,45 +80,44 @@ break;

}
ttsPromise(text, audioPath) {
return __awaiter(this, void 0, void 0, function* () {
const _wsConnect = yield this._connectWebSocket();
return new Promise((resolve, reject) => {
let audioStream = (0, node_fs_1.createWriteStream)(audioPath);
let subFile = [];
let timeout = setTimeout(() => reject('Timed out'), this.timeout);
_wsConnect.on('message', (data, isBinary) => __awaiter(this, void 0, void 0, function* () {
if (isBinary) {
let separator = 'Path:audio\r\n';
let index = data.indexOf(separator) + separator.length;
let audioData = data.subarray(index);
audioStream.write(audioData);
async ttsPromise(text, audioPath) {
const _wsConnect = await this._connectWebSocket();
return new Promise((resolve, reject) => {
let audioStream = (0, node_fs_1.createWriteStream)(audioPath);
let subFile = [];
let timeout = setTimeout(() => reject('Timed out'), this.timeout);
_wsConnect.on('message', async (data, isBinary) => {
if (isBinary) {
let separator = 'Path:audio\r\n';
let index = data.indexOf(separator) + separator.length;
let audioData = data.subarray(index);
audioStream.write(audioData);
}
else {
let message = data.toString();
if (message.includes('Path:turn.end')) {
audioStream.end();
_wsConnect.close();
if (this.saveSubtitles) {
this._saveSubFile(subFile, text, audioPath);
}
clearTimeout(timeout);
resolve();
}
else {
let message = data.toString();
if (message.includes('Path:turn.end')) {
audioStream.end();
_wsConnect.close();
if (this.saveSubtitles) {
this._saveSubFile(subFile, text, audioPath);
}
clearTimeout(timeout);
resolve();
}
else if (message.includes('Path:audio.metadata')) {
let splitTexts = message.split('\r\n');
try {
let metadata = JSON.parse(splitTexts[splitTexts.length - 1]);
metadata['Metadata'].forEach((element) => {
subFile.push({
part: element['Data']['text']['Text'],
start: Math.floor(element['Data']['Offset'] / 10000),
end: Math.floor((element['Data']['Offset'] + element['Data']['Duration']) / 10000)
});
else if (message.includes('Path:audio.metadata')) {
let splitTexts = message.split('\r\n');
try {
let metadata = JSON.parse(splitTexts[splitTexts.length - 1]);
metadata['Metadata'].forEach((element) => {
subFile.push({
part: element['Data']['text']['Text'],
start: Math.floor(element['Data']['Offset'] / 10000),
end: Math.floor((element['Data']['Offset'] + element['Data']['Duration']) / 10000)
});
}
catch (_a) { }
});
}
catch { }
}
}));
let requestId = (0, node_crypto_1.randomBytes)(16).toString('hex');
_wsConnect.send(`X-RequestId:${requestId}\r\nContent-Type:application/ssml+xml\r\nPath:ssml\r\n\r\n
}
});
let requestId = (0, node_crypto_1.randomBytes)(16).toString('hex');
_wsConnect.send(`X-RequestId:${requestId}\r\nContent-Type:application/ssml+xml\r\nPath:ssml\r\n\r\n
` + `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${this.lang}">

@@ -142,3 +130,2 @@ <voice name="${this.voice}">

</speak>`);
});
});

@@ -145,0 +132,0 @@ }

{
"name": "node-edge-tts",
"version": "1.2.5",
"version": "1.2.6",
"description": "node-edge-tts is a module that using Microsoft Edge's online TTS (Text-to-Speech) service on the Node.js",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc