fix(all): Removal of MSFT cog. services.
This commit is contained in:
parent
820ff0ca92
commit
7f970ee77f
3 changed files with 7 additions and 54 deletions
|
@ -85,7 +85,6 @@
|
||||||
"ibm-watson": "6.1.1",
|
"ibm-watson": "6.1.1",
|
||||||
"js-beautify": "1.13.13",
|
"js-beautify": "1.13.13",
|
||||||
"marked": "2.0.7",
|
"marked": "2.0.7",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "1.14.1",
|
|
||||||
"ms-rest-azure": "3.0.0",
|
"ms-rest-azure": "3.0.0",
|
||||||
"nexmo": "2.9.1",
|
"nexmo": "2.9.1",
|
||||||
"node-cron": "3.0.0",
|
"node-cron": "3.0.0",
|
||||||
|
|
|
@ -297,53 +297,6 @@ export class GBConversationalService {
|
||||||
await min.whatsAppDirectLine.sendToDevice(mobile, message);
|
await min.whatsAppDirectLine.sendToDevice(mobile, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getAudioBufferFromText(speechKey, cloudRegion, text, locale): Promise<string> {
|
|
||||||
return new Promise<string>(async (resolve, reject) => {
|
|
||||||
const name = GBAdminService.getRndReadableIdentifier();
|
|
||||||
|
|
||||||
const waveFilename = `work/tmp${name}.pcm`;
|
|
||||||
const sdk = require('microsoft-cognitiveservices-speech-sdk');
|
|
||||||
sdk.Recognizer.enableTelemetry(false);
|
|
||||||
|
|
||||||
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(waveFilename);
|
|
||||||
var speechConfig = sdk.SpeechConfig.fromSubscription(speechKey, cloudRegion);
|
|
||||||
|
|
||||||
var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
|
|
||||||
|
|
||||||
try {
|
|
||||||
speechConfig.speechSynthesisLanguage = locale;
|
|
||||||
speechConfig.speechSynthesisVoiceName = 'pt-BR-FranciscaNeural';
|
|
||||||
|
|
||||||
synthesizer.speakTextAsync(text, result => {
|
|
||||||
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
|
|
||||||
let raw = Buffer.from(result.audioData);
|
|
||||||
fs.writeFileSync(waveFilename, raw);
|
|
||||||
GBLog.info(`Audio data byte size: ${result.audioData.byteLength}.`);
|
|
||||||
const oggFilenameOnly = `tmp${name}.ogg`;
|
|
||||||
const oggFilename = `work/${oggFilenameOnly}`;
|
|
||||||
|
|
||||||
const output = fs.createWriteStream(oggFilename);
|
|
||||||
const transcoder = new prism.FFmpeg({
|
|
||||||
args: ['-analyzeduration', '0', '-loglevel', '0', '-f', 'opus', '-ar', '16000', '-ac', '1']
|
|
||||||
});
|
|
||||||
|
|
||||||
fs.createReadStream(waveFilename).pipe(transcoder).pipe(output);
|
|
||||||
|
|
||||||
let url = urlJoin(GBServer.globals.publicAddress, 'audios', oggFilenameOnly);
|
|
||||||
resolve(url);
|
|
||||||
} else {
|
|
||||||
const error = 'Speech synthesis canceled, ' + result.errorDetails;
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
synthesizer.close();
|
|
||||||
synthesizer = undefined;
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async getTextFromAudioBuffer(speechKey, cloudRegion, buffer, locale): Promise<string> {
|
public static async getTextFromAudioBuffer(speechKey, cloudRegion, buffer, locale): Promise<string> {
|
||||||
return new Promise<string>(async (resolve, reject) => {
|
return new Promise<string>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -443,12 +443,13 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
public async sendTextAsAudioToDevice(to, msg) {
|
public async sendTextAsAudioToDevice(to, msg) {
|
||||||
|
|
||||||
const url = await GBConversationalService.getAudioBufferFromText(
|
// DISABLED:
|
||||||
this.min.instance.speechKey,
|
// const url = await GBConversationalService.getAudioBufferFromText(
|
||||||
this.min.instance.cloudLocation,
|
// this.min.instance.speechKey,
|
||||||
msg, this.locale
|
// this.min.instance.cloudLocation,
|
||||||
);
|
// msg, this.locale
|
||||||
|
// );
|
||||||
|
const url = 'https://';
|
||||||
await this.sendFileToDevice(to, url, 'Audio', msg);
|
await this.sendFileToDevice(to, url, 'Audio', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue