Skip to content

Instantly share code, notes, and snippets.

@anaptfox
Created December 13, 2016 13:54
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anaptfox/6ea8fcf6ae9f3a9617ebc9b3eccbd894 to your computer and use it in GitHub Desktop.
Save anaptfox/6ea8fcf6ae9f3a9617ebc9b3eccbd894 to your computer and use it in GitHub Desktop.
Node.js Amazon Polly to file example.
// Load the SDK
const AWS = require('aws-sdk')
const Fs = require('fs')
// Create an Polly client
const Polly = new AWS.Polly({
signatureVersion: 'v4',
region: 'us-east-1'
})
let params = {
'Text': 'Hi, my name is @anaptfox.',
'OutputFormat': 'mp3',
'VoiceId': 'Kimberly'
}
Polly.synthesizeSpeech(params, (err, data) => {
if (err) {
console.log(err.code)
} else if (data) {
if (data.AudioStream instanceof Buffer) {
Fs.writeFile("./speech.mp3", data.AudioStream, function(err) {
if (err) {
return console.log(err)
}
console.log("The file was saved!")
})
}
}
})
@jersonjunior
Copy link

The sound is very low, I tried to use <prosody volume = + 20dB> Hi, my name is @anaptfox., but it is not accepting the prosody

'Text': 'Hi, my name is @anaptfox.'

@owntheweb-archive
Copy link

@jersonjunior: ssml tags will be accepted if setting 'TextType': 'ssml', in params. :)

@daveRanjan
Copy link

how to get file in wav format?

@jersonjunior
Copy link

jersonjunior commented Nov 22, 2017

I use this:
var output = child_process.execSync('lame --decode ' + argv.mp3 + ' ' + '-b 8000' + ' ' + argv.wav + '.wav');

To convert in wav 8000hz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment