style: run format:apply

This commit is contained in:
2026-02-11 02:36:38 -03:00
parent c44f92f777
commit 85c35021b5
+45 -36
View File
@@ -3,13 +3,13 @@ import { TTSModule, TTSResponse } from '../tts';
import * as https from 'https';
import { WebSocket } from 'ws'
import { WebSocket } from 'ws';
import { Logger } from '../../utils/log';
const CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4";
const AZURE_ENDPOINT = "speech.platform.bing.com";
const CLIENT_TOKEN = '6A5AA1D4EAFF4E9FB37E23D68491D6F4';
const AZURE_ENDPOINT = 'speech.platform.bing.com';
const READALOUD_PATH = `/consumer/speech/synthesize/readaloud`
const READALOUD_PATH = `/consumer/speech/synthesize/readaloud`;
const WEBSOCKET_URL = `wss://${AZURE_ENDPOINT}${READALOUD_PATH}/edge/v1?TrustedClientToken=${CLIENT_TOKEN}`;
const VOICES_PATH = `${READALOUD_PATH}/voices/list?TrustedClientToken=${CLIENT_TOKEN}`;
@@ -59,26 +59,25 @@ class AzureTTS implements TTSModule {
}
async getVoices(): Promise<Array<string> | undefined> {
if (this.voices)
return this.voices;
if (this.voices) return this.voices;
const options: https.RequestOptions = {
hostname: AZURE_ENDPOINT,
path: `${VOICES_PATH}&Sec-MS-GEC=${this.genSecToken()}&Sec-MS-GEC-Version=${SEC_VERSION}`,
method: 'GET',
headers: {
'Pragma': 'no-cache',
Pragma: 'no-cache',
'Cache-Control': 'no-cache',
'User-Agent': USER_AGENT,
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Authority": "speech.platform.bing.com",
"Sec-CH-UA": `" Not;A Brand";v="99", "Microsoft Edge";v="${CHROME_VERSION.split('.')[0]}", "Chromium";v="${CHROME_VERSION.split('.')[0]}"`,
"Sec-CH-UA-Mobile": "?0",
"Accept": "*/*",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
Authority: 'speech.platform.bing.com',
'Sec-CH-UA': `" Not;A Brand";v="99", "Microsoft Edge";v="${CHROME_VERSION.split('.')[0]}", "Chromium";v="${CHROME_VERSION.split('.')[0]}"`,
'Sec-CH-UA-Mobile': '?0',
Accept: '*/*',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty'
}
};
@@ -95,7 +94,7 @@ class AzureTTS implements TTSModule {
throw err;
});
res.on('aborted', () => {
throw new Error('Response aborted')
throw new Error('Response aborted');
});
});
req.end();
@@ -143,8 +142,8 @@ class AzureTTS implements TTSModule {
host: 'speech.platform.bing.com',
origin: 'chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold',
headers: {
'Pragma': 'no-cache',
'User-Agent': USER_AGENT,
Pragma: 'no-cache',
'User-Agent': USER_AGENT
}
});
@@ -173,10 +172,10 @@ class AzureTTS implements TTSModule {
this.handleIncomingMessage(data, isBinary);
});
this.ws.on('close', (code/*, reason*/) => {
this.ws.on('close', (/*code, reason*/) => {
this.ready = false;
// this.log.verbose(`WS Closed: ${code}`);
this.rejectAllPending(new Error("Connection closed"));
this.rejectAllPending(new Error('Connection closed'));
this.scheduleReconnect();
});
@@ -210,8 +209,11 @@ class AzureTTS implements TTSModule {
if (message.includes('Path:turn.end')) {
request.resolve({ data: Buffer.concat(request.audioBuff) });
this.pendingRequests.delete(reqId);
} else if (message.includes('Path:turn.error') || message.includes('Path:error')) {
request.reject(new Error("Azure synthesis error"));
} else if (
message.includes('Path:turn.error') ||
message.includes('Path:error')
) {
request.reject(new Error('Azure synthesis error'));
this.pendingRequests.delete(reqId);
}
}
@@ -225,28 +227,35 @@ class AzureTTS implements TTSModule {
}
private genSecToken(): string {
const ticks = BigInt(Math.floor((Date.now() / 1000) + Number(WIN_EPOCH))) * 10000000n
const roundedTicks = ticks - (ticks % 3000000000n)
const ticks =
BigInt(Math.floor(Date.now() / 1000 + Number(WIN_EPOCH))) * 10000000n;
const roundedTicks = ticks - (ticks % 3000000000n);
const strToHash = `${roundedTicks}${CLIENT_TOKEN}`
const strToHash = `${roundedTicks}${CLIENT_TOKEN}`;
const hash = createHash('sha256')
hash.update(strToHash, 'ascii')
const hash = createHash('sha256');
hash.update(strToHash, 'ascii');
return hash.digest('hex').toUpperCase()
return hash.digest('hex').toUpperCase();
}
private escapeXml(unsafe: string): string {
return unsafe.replace(/[<>&"']/g, (c) => {
switch (c) {
case '<': return '&lt;'
case '>': return '&gt;'
case '&': return '&amp;'
case '"': return '&quot;'
case "'": return '&apos;'
default: return c
case '<':
return '&lt;';
case '>':
return '&gt;';
case '&':
return '&amp;';
case '"':
return '&quot;';
case "'":
return '&apos;';
default:
return c;
}
})
});
}
}