aiTextToSpeech working without folder and s3 bucket manipulation

galleryApi
Kar 2024-11-18 19:14:04 +05:30
parent f1198c21de
commit c934f45726
1 changed files with 2 additions and 8 deletions

View File

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