aiTextToSpeech working without folder and s3 bucket manipulation
parent
f1198c21de
commit
c934f45726
|
@ -37,7 +37,6 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Generate a folder name based on current timestamp and random digits
|
|
||||||
function generateTimestampWithRandomDigits() {
|
function generateTimestampWithRandomDigits() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const formattedDate = now.toISOString().replace('T', '_').replace(/\..+/, '').replace(/:/g, '-');
|
const formattedDate = now.toISOString().replace('T', '_').replace(/\..+/, '').replace(/:/g, '-');
|
||||||
|
@ -48,21 +47,17 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
const folder = generateTimestampWithRandomDigits();
|
const folder = generateTimestampWithRandomDigits();
|
||||||
const folderName = `audio_files/${folder}`;
|
const folderName = `audio_files/${folder}`;
|
||||||
|
|
||||||
// Request Polly to synthesize speech
|
|
||||||
const data = await polly.synthesizeSpeech(params).promise();
|
const data = await polly.synthesizeSpeech(params).promise();
|
||||||
const audioBuffer = data.AudioStream;
|
const audioBuffer = data.AudioStream;
|
||||||
|
|
||||||
// Prepare the text file as a buffer
|
|
||||||
const textBuffer = Buffer.from(text, 'utf-8');
|
const textBuffer = Buffer.from(text, 'utf-8');
|
||||||
|
|
||||||
// Prepare the form data to send via POST request
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file1', audioBuffer, 'speech.mp3');
|
formData.append('file1', audioBuffer, 'speech.mp3');
|
||||||
formData.append('file2', textBuffer, 'text.txt');
|
formData.append('file2', textBuffer, 'text.txt');
|
||||||
// formData.append('folder', folderName); // Send folder name as form data
|
// formData.append('folder', folderName); // Send folder name
|
||||||
// formData.append('bucket', 'docs'); // Adjust bucket if needed
|
// formData.append('bucket', 'docs'); // Adjust bucket
|
||||||
|
|
||||||
// Send the POST request to upload the files
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'https://preschool-curriculum.in/api/one/v1/file/upload',
|
'https://preschool-curriculum.in/api/one/v1/file/upload',
|
||||||
formData,
|
formData,
|
||||||
|
@ -74,7 +69,6 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return success response with URLs from the response
|
|
||||||
res.json({
|
res.json({
|
||||||
message: 'Speech generated and saved successfully',
|
message: 'Speech generated and saved successfully',
|
||||||
fileUrls: response.data.urls,
|
fileUrls: response.data.urls,
|
||||||
|
|
Loading…
Reference in New Issue