Amazon Polly API
Hello Buildshipers!
I am trying to create a workflow that connects to Amazon Polly API. Is this possible? I am a total noob when it comes to buildship. If you have any tips or ideas i am totaly focused on your returns.
Now, i am here:
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
const AWS_REGION = process.env.AWS_REGION;
if (!AWS_ACCESS_KEY_ID !AWS_REGION) {
throw new Error('AWS credentials or region are not set in environment variables');
}
export default async function synthesizeSpeech({
text,
voiceId,
format = 'mp3',
sampleRate = '8000',
textType = 'text',
region,
engine = 'neural',
languageCode
}) {
const awsRegion = region || AWS_REGION;
if (!awsRegion) {
throw new Error('Region is missing');
}
const client = new PollyClient({
region: awsRegion,
credentials: {
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY
}
});
const input = {
Text: text,
OutputFormat: format,
VoiceId: voiceId,
SampleRate: sampleRate,
TextType: textType,
Engine: engine,
LanguageCode: languageCode
};
const command = new SynthesizeSpeechCommand(input);
try {
const { AudioStream, ContentType } = await client.send(command);
if (AudioStream && ContentType === 'audio/mpeg') {
let audioBuffer = [];
for await (let chunk of AudioStream) {
audioBuffer.push(chunk);
}
return Buffer.concat(audioBuffer).toString('base64');
}
throw new Error('AudioStream is empty or ContentType is not MP3');
} catch (error) {
throw new Error(
}
}
/
Cheers!
I am trying to create a workflow that connects to Amazon Polly API. Is this possible? I am a total noob when it comes to buildship. If you have any tips or ideas i am totaly focused on your returns.
Now, i am here:
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
const AWS_REGION = process.env.AWS_REGION;
if (!AWS_ACCESS_KEY_ID !AWS_REGION) {
throw new Error('AWS credentials or region are not set in environment variables');
}
export default async function synthesizeSpeech({
text,
voiceId,
format = 'mp3',
sampleRate = '8000',
textType = 'text',
region,
engine = 'neural',
languageCode
}) {
const awsRegion = region || AWS_REGION;
if (!awsRegion) {
throw new Error('Region is missing');
}
const client = new PollyClient({
region: awsRegion,
credentials: {
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY
}
});
const input = {
Text: text,
OutputFormat: format,
VoiceId: voiceId,
SampleRate: sampleRate,
TextType: textType,
Engine: engine,
LanguageCode: languageCode
};
const command = new SynthesizeSpeechCommand(input);
try {
const { AudioStream, ContentType } = await client.send(command);
if (AudioStream && ContentType === 'audio/mpeg') {
let audioBuffer = [];
for await (let chunk of AudioStream) {
audioBuffer.push(chunk);
}
return Buffer.concat(audioBuffer).toString('base64');
}
throw new Error('AudioStream is empty or ContentType is not MP3');
} catch (error) {
throw new Error(
Error synthesizing speech: ${error.message});}
}
/
Cheers!
Solution
Hi @Hërzouz You can also generate a node with AI fir the Amazon Polly API - https://www.youtube.com/watch?v=AawYfYW8xu0
YouTubeBuildShip
Get started with BuildShip for FREE
https://buildship.com
A Low-code Visual Backend Builder with AI
Chat and build together with a community of no-code/low-code developers: https://buildship.com/discord
Tweets: https://twitter.com/buildshipapp
#nocode #backend #apibuilder #lowcode #cronjob #scheduledtask #backgroundjob #googlecloud #ope...
A Low-code Visual Backend Builder with AI
#nocode #backend #apibuilder #lowcode #cronjob #scheduledtask #backgroundjob #googlecloud #ope...

