natural-language-api-google/utils/convertAudioToLinear16.js

16 lines
519 B
JavaScript

const ffmpeg = require('fluent-ffmpeg')
async function convertToLINEAR16(inputFile, outputFile) {
return new Promise((resolve, reject) => {
ffmpeg(inputFile)
.audioCodec('pcm_s16le') // Set the audio codec to LINEAR16
.audioFrequency(16000) // Set the sample rate to 16,000 Hz
.audioChannels(1)
.on('end', () => resolve(outputFile))
.on('error', (err) => reject(err))
.save(outputFile)
})
}
module.exports = convertToLINEAR16