Skip to content

Instantly share code, notes, and snippets.

{
imageUrl: "http://iamge.com/image.jpg",
structure: [
{
x_sup: 103.3,
y_sup: 19,
x_inf: 119,
y_inf: 38
},
{
const someReallyUsefullFunction = async (text) => {
// Break in parts small enough to be handle by Polly API
const parts = divideTextEnoughToBeHandleByPolly(text)
// Concat AudioStreams in one Buffer
const audioStreams = audios.map(a => a.AudioStream)
const buffer = Buffer.concat(audioStreams, audioStreams.reduce((len, a) => len + a.length, 0))
...
}
@Feawel
Feawel / polly_parts.js
Last active March 19, 2017 12:02
Divide a text in parts, to be handle by Polly API
const someReallyUsefullFunction = (text) => {
...
// Break in parts small enough to be handle by Polly API
const parts = divideTextEnoughToBeHandleByPolly(text)
...
}
const writeAudioStreamToS3 = ( audioStream, filename ) =>
putObject(aws_publicBucket, filename, audioStream,'audio/mp3').then( res => {
if(!res.ETag) throw res
else return {
msg: 'File successfully generated.',
ETag: res.ETag,
url: `https://s3-eu-west-1.amazonaws.com/${aws_publicBucket}/${filename}`
}
})
@Feawel
Feawel / polly_audiogeneration.js
Created February 11, 2017 16:53
Nodejs script using polly API to return an audio stream (through a promise)
// Generate audio from Polly and check if output is a Buffer
const generatePollyAudio = (text, voiceId) => {
const params = {
Text: text,
OutputFormat: 'mp3',
VoiceId: voiceId // see Polly API for the list http://docs.aws.amazon.com/fr_fr/polly/latest/dg/API_Voice.html#API_Voice_Contents
}
return polly.synthesizeSpeech(params).promise().then( audio => {
if (audio.AudioStream instanceof Buffer) return audio
@Feawel
Feawel / polly_init.js
Created February 11, 2017 16:47
AWS Polly initialisation
import aws from 'aws-sdk'
// Create a Polly client
const polly = new aws.Polly({
signatureVersion: ‘v4’,
region: ‘eu-west-1’
})
@Feawel
Feawel / polly.js
Last active June 2, 2017 03:13
AWS Polly use example using nodejs async / await
/**
* Use as proxy between front and AWS Polly API
* Everything come in querystring
* voiceId : see Polly API for the list http://docs.aws.amazon.com/fr_fr/polly/latest/dg/API_Voice.html#API_Voice_Contents
* type :
* - file (default) : generate mp3 file on public bucket
* - stream : stream response
*/
export const textToSpeech = async (req, res) => {