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