From 85c35021b5f39e88f08869217c2ff4c692950f16 Mon Sep 17 00:00:00 2001 From: neru Date: Wed, 11 Feb 2026 02:36:38 -0300 Subject: [PATCH] style: run format:apply --- src/modules/tts-modes/azure.ts | 81 +++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/src/modules/tts-modes/azure.ts b/src/modules/tts-modes/azure.ts index dea6032..7a5d1ef 100644 --- a/src/modules/tts-modes/azure.ts +++ b/src/modules/tts-modes/azure.ts @@ -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 | 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 '<' - case '>': return '>' - case '&': return '&' - case '"': return '"' - case "'": return ''' - default: return c + case '<': + return '<'; + case '>': + return '>'; + case '&': + return '&'; + case '"': + return '"'; + case "'": + return '''; + default: + return c; } - }) + }); } }