Skip to content

Commit

Permalink
fix(core.gbapp): Added IBM for TTS and removed MSFT while it does not…
Browse files Browse the repository at this point in the history
… compile on AZR.
  • Loading branch information
rodrigorodriguez committed Dec 31, 2021
1 parent 2a81604 commit 12c9bea
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,29 +306,30 @@ export class GBConversationalService {

const params = {
text: text,
accept: 'audio/ogg;codecs=vorbis', // ; rate=44100
accept: 'audio/wav; rate=44100',
voice: 'pt-BR_IsabelaVoice'
};

// Migrated to IBM from MSFT, as it own package do not compile on Azure Web App.

let res = await textToSpeech.synthesize(params);
const waveFilename = `work/tmp${name}.pcm`;

let audio = '';
audio = await textToSpeech.repairWavHeaderStream(res.result);
fs.writeFileSync(waveFilename, audio);

const oggFilenameOnly = `tmp${name}.ogg`;
const oggFilename = `work/${oggFilenameOnly}`;

let body = '';
res.result.on('data',(chunck) => {
body += chunck;
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);

res.result.on('end', () => {
fs.writeFileSync(oggFilename, body);
res.statusCode = 200;
});

let url = urlJoin(GBServer.globals.publicAddress, 'audios', oggFilenameOnly);
resolve(url);

} catch (error) {
reject(error);
}
Expand Down

0 comments on commit 12c9bea

Please sign in to comment.