fix azure cannot download mp3 if encodingMp3 = true

This commit is contained in:
Quan HL
2024-05-03 19:43:45 +07:00
parent c0fab2880b
commit 7f904930ae

View File

@@ -96,17 +96,27 @@ router.post('/Synthesize', async(req, res) => {
let readStream = fs.createReadStream(filePath);
if (['nuance', 'nvidia'].includes(cred.vendor) ||
(
process.env.JAMBONES_TTS_TRIM_SILENCE &&
(process.env.JAMBONES_TTS_TRIM_SILENCE || !process.env.JAMBONES_DISABLE_TTS_STREAMING) &&
['microsoft', 'azure'].includes(cred.vendor)
)
) {
if (encodingMp3) {
readStream = readStream
.pipe(new PCMToMP3Encoder({
readStream = pipeline(
readStream,
new PCMToMP3Encoder({
channels: 1,
sampleRate: 8000,
bitRate: 128
}, logger));
}, logger),
(err) => {
if (err) {
logger.error('ttscache/Synthesize failed:', err);
if (!res.headersSent) {
res.status(500).end('Server error');
}
}
}
);
} else {
contentType = 'application/octet-stream';
}