Skip to content

Commit

Permalink
fix(all): Removal of MSFT cog. services.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jun 16, 2021
1 parent 820ff0c commit 7f970ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 54 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"ibm-watson": "6.1.1",
"js-beautify": "1.13.13",
"marked": "2.0.7",
"microsoft-cognitiveservices-speech-sdk": "1.14.1",
"ms-rest-azure": "3.0.0",
"nexmo": "2.9.1",
"node-cron": "3.0.0",
Expand Down
47 changes: 0 additions & 47 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,53 +297,6 @@ export class GBConversationalService {
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> {
return new Promise<string>(async (resolve, reject) => {
try {
Expand Down
13 changes: 7 additions & 6 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,13 @@ export class WhatsappDirectLine extends GBService {

public async sendTextAsAudioToDevice(to, msg) {

const url = await GBConversationalService.getAudioBufferFromText(
this.min.instance.speechKey,
this.min.instance.cloudLocation,
msg, this.locale
);

// DISABLED:
// const url = await GBConversationalService.getAudioBufferFromText(
// this.min.instance.speechKey,
// this.min.instance.cloudLocation,
// msg, this.locale
// );
const url = 'https://';
await this.sendFileToDevice(to, url, 'Audio', msg);
}

Expand Down

0 comments on commit 7f970ee

Please sign in to comment.