Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Betabot #81

Merged
merged 16 commits into from
Mar 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bender: I love this planet! I've got wealth, fame, and access to the …
…depths of sleaze that those things bring.
  • Loading branch information
wootosmash committed Jan 12, 2020
commit e4ce82bf27095ca3b3eb77c3310f4f27ae8f4a16
75 changes: 35 additions & 40 deletions src/services/tts/AmazonTextToSpeechAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,50 +100,45 @@ class AmazonTextToSpeechAPI extends TextToSpeechService {
* @param {*} request
* @param {*} callback (err, audio) => {...}
*/
getAudioContent (request, callback) {
async getAudioContent (request, callback) {

var self = this;

self.doBookkeeping(request);
AmazonTextToSpeechAPI.polly.textToSpeech(request, (err, audioStream) => {
if (err) {
Common.error(request);
Common.error(err);
callback(new Error(err), null);
return;
}
try {

var ld = new lame.Decoder({
sampleRate: 22050,
channels: lame.MONO,
signed: true,
float: false,
bitDepth: 16,
});

var resample = new samplerate({
// Value can be from 0 to 4 or using enum. 0 is the best quality and the slowest.
type: samplerate.SRC_SINC_MEDIUM_QUALITY,
// Stereo
channels: 1,
// Sample rate of source
fromRate: 22050,
// bit depth of source. Valid values: 16 or 32
fromDepth: 16,
// Desired sample rate
toRate: 48000,
// Desired bit depth. Valid values: 16 or 32
toDepth: 16
});

callback(null, audioStream.pipe(ld).pipe(resample).pipe(new prism.opus.Encoder({rate: 48000, channels: 1, frameSize: 960 })));
}
catch(ex)
{
callback(ex, null);
}
});
try {

let audioStream = await AmazonTextToSpeechAPI.polly.textToSpeech(request);
var ld = new lame.Decoder({
sampleRate: 22050,
channels: lame.MONO,
signed: true,
float: false,
bitDepth: 16,
});

var resample = new samplerate({
// Value can be from 0 to 4 or using enum. 0 is the best quality and the slowest.
type: samplerate.SRC_SINC_MEDIUM_QUALITY,
// Stereo
channels: 1,
// Sample rate of source
fromRate: 22050,
// bit depth of source. Valid values: 16 or 32
fromDepth: 16,
// Desired sample rate
toRate: 48000,
// Desired bit depth. Valid values: 16 or 32
toDepth: 16
});

callback(null, audioStream.pipe(ld).pipe(resample).pipe(new prism.opus.Encoder({rate: 48000, channels: 1, frameSize: 960 })));
}
catch( err) {
Common.error(request);
Common.error(err);
callback(new Error(err), null);
return;
}
}

getVoices() {
Expand Down