let filePath;
try {
// Each lesson has a default voice (defaultVoice under Lesson table).
// Generate the audio using this default voice.
const lesson = sentence.get('lesson');
const voice = await getVoiceByLesson(lesson);
filePath = await convertTextToSpeech(content, fileName, voice);
// Code to upload the file to my server. I don't think it is related to the bug because the local files (before uploading) are cut off themselves
...
console.log('Audio file successfully saved to the server.');
} catch (e) {
console.error('An error occurred:', e);
throw e; // Re-throw the error after logging
} finally {
// Ensure the temporary file is deleted
if (filePath) {
try {
await fs.unlink(filePath);
console.log(`Temporary file ${filePath} deleted.`);
} catch (unlinkErr) {
console.error(`Failed to delete temporary file: ${unlinkErr}`);
}
}
}
Note:
I want to delete the file after uploading the audio to my server, to delete I use this code await fs.unlink(filePath);
I also tried not to delete the file and got the same issue with the uploaded files on server (play the audio files using my app)
I also play the audio files locally (my Mac), some are good, some are incomplete (cut off)
Same issue happens when I deploy the code to my Linux server
Expected behavior
The output files (.mp3 files) should not be cut off.
Version of the Cognitive Services Speech SDK
microsoft-cognitiveservices-speech-sdk": "^1.40.0
Platform, Operating System, and Programming Language
OS: Mac (Macbook Pro M1 - MacOS 15)
Programming language: JavaScript (I have another Python script running on the same Mac, but it works well)
Hello,
I'm using Javascript SDK to convert text (multiple short sentences, each API call for each sentence) to speech (.mp3 file). Here is the code:
Then I call it from like below:
Note:
await fs.unlink(filePath);
Expected behavior
The output files (.mp3 files) should not be cut off.
Version of the Cognitive Services Speech SDK
microsoft-cognitiveservices-speech-sdk": "^1.40.0
Platform, Operating System, and Programming Language