我正在尝试从 TTS API 生成音频文件。音频文件正在保存在项目的根目录中,但
CreateReamStream
似乎无法读取它。
AWS ERROR Error: ENOENT: no such file or directory, lstat 'DO_FILE_929918.mp3'
我可以看到磁盘上的文件,我可以很好地播放音频。但是没有任何内容被上传到存储桶中。如果我用
Body: stream
替换 Body: fileName
音频文件被上传但它不包含任何音频和它的 0kb.
await TextToSpeech(apiKey, text, voice_id, fileName)
console.log(`Success, Audio saved as: ${fileName}`)
let stream = fs.createReadStream(fileName);
const spacesEndpoint = new aws.Endpoint('<endpoint>')
const s3 = new aws.S3({
endpoint: spacesEndpoint,
accessKeyId: process.env.AWSACCESSKEYID,
secretAccessKey: process.env.SECRETACCESSKEY,
})
const awsres = await s3.putObject({
Bucket: '<bucket>',
Key: `${fileName}`,
Body: stream,
ACL: 'public-read',
},
(err, data) => {
if (err) return console.log('AWS ERROR', err)
}
)
// this aws url/path gets saved in the database
const narrationUrl = await `https://<endpoint>${awsres.httpRequest.path}`