根据最近的AWS公告,Polly的新角色限制为3,000 - 是先前限制1,500的两倍。
以前,我的应用程序的字符数限制为1,450,以便考虑我以编程方式添加到用户输入的字符。鉴于上述公告,我认为将我的角色限制增加到2,950是安全的。但是,我的音频文件是空的(0 kb),我超过大约2,450个字符。我对此感到困惑,当然如果可能的话,我想额外使用500个字符。
这是我的代码:
var AWS = require('aws-sdk'),
fs = require('fs');
const Fs = require('fs')
const path = require('path');
AWS.config.loadFromPath(path.join(__dirname, 'config.json'));
var mysql = require('mysql');
var localfile = path.join(__dirname, 'myverse.mp3');
var connection = mysql.createConnection({
connectionLimit : 10,
host : '...',
user : '...',
password : '...',
database: '...',
});
[some irrelevant code omitted here.]
connection.query('SELECT versetext, book, mp3, id, reference, userid FROM publicverses where mp3 = "empty" limit 1',
function (error, results, fields) {
console.log(error);
var scripture = results[0].versetext + ".";
var userid = results[0].userid;
var book = results[0].book;
var reference = results[0].reference.replace(":", " verse ").replace(",", " and ");
if (reference.includes("-")){
var reference = reference.replace("verse", "verses");
}
console.log(scripture + " " + book.replace("1", "first").replace("2", "second").replace("3", "third") + " " + reference);
var myverse = "<speak><prosody volume='x-loud'><break time='1s'/>" + scripture + " " + book.replace("1", "first").replace("2", "second").replace("3", "third") + " " + reference + "<break time='1s'/></prosody></speak>";
var link = "https://s3.amazonaws.com/publicverses/" + book.replace(/ /g, "")+reference.replace(/ /g, "")+"_user"+userid+"_"+randomnumber+".mp3";
writeit();
fs.createWriteStream(localfile);
var myvalue = fs.createReadStream(localfile);
setTimeout(uploadit, 2000)
function linkit(){
'use strict';
connection.query('update publicverses set mp3 = ? where mp3 = "empty" limit 1', [link],
function (error, results, fields) {
console.log(error)
})
}
function writeit() {
'use strict';
const Polly = new AWS.Polly({
signatureVersion: 'v4',
region: 'us-east-1'
})
let params = {
'Text': myverse.replace(" Job ", " Jobe "),
'LexiconNames': [ 'kjv' ],
'TextType': 'ssml',
'OutputFormat': 'mp3',
'VoiceId': 'Matthew'
}
Polly.synthesizeSpeech(params, (err, data) => {
if (err) {
console.log(err.code)
} else if (data) {
if (data.AudioStream instanceof Buffer) {
Fs.writeFile("./myverse.mp3", data.AudioStream, function(err) {
if (err) {
return console.log(err)
}
console.log("Verse recorded successfully!")
})
}
}
})
}
function uploadit () {
'use strict';
console.log('Preparing to upload the verse.')
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
var uploadParams = {Bucket: 'publicverses', key: '/test.mp3', Body: myvalue, ACL: 'public-read'};
var file = 'MyVerse.mp3';
var fs = require('fs');
var fileStream = fs.createReadStream(file);
fileStream.on('error', function(err) {
console.log('File Error', err);
});
uploadParams.Body = fileStream;
var path = require('path');
uploadParams.Key = book.replace(/ /g, "")+reference.replace(/ /g, "")+"_user"+userid+"_"+randomnumber+".mp3";
// call S3 to retrieve upload file to specified bucket
s3.upload (uploadParams, function (err, data) {
if (err) {
console.log("Error", err);
} if (data) {
console.log("Upload Success", data.Location);
linkit();
addanother();
}
});
}
});
}