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
{ | |
imageUrl: "http://iamge.com/image.jpg", | |
structure: [ | |
{ | |
x_sup: 103.3, | |
y_sup: 19, | |
x_inf: 119, | |
y_inf: 38 | |
}, | |
{ |
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
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)) | |
... | |
} |
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
const someReallyUsefullFunction = (text) => { | |
... | |
// Break in parts small enough to be handle by Polly API | |
const parts = divideTextEnoughToBeHandleByPolly(text) | |
... | |
} |
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
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}` | |
} | |
}) |
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
// 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 |
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
import aws from 'aws-sdk' | |
// Create a Polly client | |
const polly = new aws.Polly({ | |
signatureVersion: ‘v4’, | |
region: ‘eu-west-1’ | |
}) |
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
/** | |
* 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) => { |