Last active
May 24, 2020 00:14
-
-
Save anaptfox/64951815358ba545f94ff864c02887da to your computer and use it in GitHub Desktop.
Node.js Amazon Polly to speaker example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
} | |
}) |
Thanks for this it works but process is killed after the sentence :( Process finished with exit code 132 (interrupted by signal 4: SIGILL)
Process finished with exit code 132 (interrupted by signal 4: SIGILL)
Did anyone manage this?
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.
How to stop the Player in middle?
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
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...