Skip to content

Instantly share code, notes, and snippets.

@anaptfox
Last active May 24, 2020 00:14
Show Gist options
  • Save anaptfox/64951815358ba545f94ff864c02887da to your computer and use it in GitHub Desktop.
Save anaptfox/64951815358ba545f94ff864c02887da to your computer and use it in GitHub Desktop.
Node.js Amazon Polly to speaker example.
// Load the SDK
const AWS = require('aws-sdk')
const Stream = require('stream')
const Speaker = require('speaker')
// Create an Polly client
const Polly = new AWS.Polly({
signatureVersion: 'v4',
region: 'us-east-1'
})
// Create the Speaker instance
const Player = new Speaker({
channels: 1,
bitDepth: 16,
sampleRate: 16000
})
let params = {
'Text': 'Hi, my name is @anaptfox.',
'OutputFormat': 'pcm',
'VoiceId': 'Kimberly'
}
Polly.synthesizeSpeech(params, (err, data) => {
if (err) {
console.log(err.code)
} else if (data) {
if (data.AudioStream instanceof Buffer) {
// Initiate the source
var bufferStream = new Stream.PassThrough()
// convert AudioStream into a readable stream
bufferStream.end(data.AudioStream)
// Pipe into Player
bufferStream.pipe(Player)
}
}
})
@stuarttayler
Copy link

Hi, thanks for this! Just wondering, do you get "Illegal instruction: 4" in the console when running this? It works as expected but just wondering what's causing the error message...

@tmcpro
Copy link

tmcpro commented Feb 16, 2017

@jaumard
Copy link

jaumard commented Aug 25, 2017

Thanks for this it works but process is killed after the sentence :( Process finished with exit code 132 (interrupted by signal 4: SIGILL)

@lomosapience
Copy link

Process finished with exit code 132 (interrupted by signal 4: SIGILL)
Did anyone manage this?

@pete-rai
Copy link

pete-rai commented Feb 5, 2018

The "Illegal instruction 4" and "code 132..." issues is a problem with the speaker node module. Read the comments section in my revised Gist which shows you how to fix that issue. Also it allows you to change voices and chain sentences.

@abigyani
Copy link

How to stop the Player in middle?

@mimiqkz
Copy link

mimiqkz commented May 24, 2020

how to include this in an nextjs typescript project ?

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