Amazon s3 Google Action-使用Amazon Polly将文本合成语音

Amazon s3 Google Action-使用Amazon Polly将文本合成语音,amazon-s3,google-cloud-functions,aws-sdk,dialogflow-es,actions-on-google,Amazon S3,Google Cloud Functions,Aws Sdk,Dialogflow Es,Actions On Google,我决定构建一个Google Action(通过Dialogflow V2),通过Amazon Polly将文本转换为语音(声音听起来不像Google的声音那么机械) 总的来说,这是可行的,通常会导致请求者返回上传的位置。但有时它不会等待上传完成,也不会播放生成的语音。但上传始终有效,当第二次尝试触发意图时,它会像应该的那样返回mp3文件 我正在使用Nodejs 8、dialogflow和“firebase函数”、“dialogflow实现”和“aws sdk”库 当用户键入某些内容并与Reque

我决定构建一个Google Action(通过Dialogflow V2),通过Amazon Polly将文本转换为语音(声音听起来不像Google的声音那么机械)

总的来说,这是可行的,通常会导致请求者返回上传的位置。但有时它不会等待上传完成,也不会播放生成的语音。但上传始终有效,当第二次尝试触发意图时,它会像应该的那样返回mp3文件

我正在使用Nodejs 8、dialogflow和“firebase函数”、“dialogflow实现”和“aws sdk”库

当用户键入某些内容并与RequestPaird意图匹配时,将调用RequestPaird函数。然后我尝试将用户的查询转换为语音,但这并不总是有效的

index.js

async function requestApplause(agent) {
        let baseLink = "https://s3-eu-west-1.amazonaws.com/link";
        let randomApplauseLink1 = "https://s3-eu-west-1.amazonaws.com/link/file.mp3";
        var link = "";
        var text = "";
        let givenName = request.body.queryResult.parameters["given-name"];
        if (givenName !== "") {
            givenName = givenName.toLowerCase();
            link = baseLink + givenName + "-applause.mp3";
            text = "Great f**** job, " + givenName;
            let location = await textToSpeech(text, givenName);
            agent.add("<speak> <audio src='" + link + "'>An error occurred if you heard this -> Great job, name</audio> " +
                "<audio src='" + randomApplauseLink1 + "'>error occurred -> Applause missing :(</audio> </speak>");
             //   + "<audio src='" + randomApplauseLink1 + "'</speak>")
        }
    }


async function textToSpeech(textToSynthesize, givenName) {
        let voiceId = 'Joanna';
        let text = textToSynthesize; //, filename = 'speech-demo-1.mp3', type = 'file' }
        var fileName = '';
        if (givenName !== "") {
            fileName = givenName + "-applause.mp3";
        } else {
            fileName= "random-applause.mp3"
        }
        let type = 'mp3';

        try {
            let audio = await generatePollyAudio(text, voiceId);

            let location = await uploadToS3(audio, fileName);

            return location
        }
        catch (e) {
            if(e.errorCode && e.error) {
                console.log('error textToSpeech function');
            }
        }
    }


async function uploadToS3(data, fileName) {
    let s3params = {
        Body: data.AudioStream,
        Bucket: "<bucket-name>",
        Key: fileName,
        ACL: "public-read"
    };

    var req = await s3.putObject(s3params, function(resp) {
        console.log(arguments);
        console.log('successfully uplaoded....')
    }).send(function(err, data) {
        console.log("FINISHED UPLOADING");
        if (err) {
            console.log('errrrorrrrrr')
        }
    });

}

//Generate audio from Polly and check if output is a Buffer
function generatePollyAudio(text, voiceId) {
    const params = {
        Text: text,
        OutputFormat: 'mp3',
        VoiceId: voiceId
    };

    return polly.synthesizeSpeech(params).promise().then( audio => {
        if (audio.AudioStream instanceof Buffer) {
            return audio;
        } else throw 'AudioStream is not a Buffer.'
    });
}
异步函数(代理){ 让baseLink=”https://s3-eu-west-1.amazonaws.com/link"; 让我们来看看ApplauseLK1=”https://s3-eu-west-1.amazonaws.com/link/file.mp3"; var link=“”; var text=“”; 让givenName=request.body.queryResult.parameters[“给定名称”]; 如果(givenName!==“”){ givenName=givenName.toLowerCase(); link=baseLink+givenName+“-paird.mp3”; text=“伟大的f****工作,”+givenName; let location=等待textToSpeech(text,givenName); add(“如果您听到这个->很棒的工作,名称,则发生错误”+ “出现错误->缺少掌声:(”;
// + "你能更新你的问题来说明这些函数是如何被调用的吗?看起来你正在使用dialogflow实现库并构建一个Google操作,对吗?@Captive我更新了它,我确实在使用dialogflow实现库在上传数据到S3和使用它之间存在某种传播延迟吗可访问?当您调用
时,等待s3.putObject(…).send(…)
它是在等待
putObject
还是
send
?听起来确实比谷歌的更机器人化?大多数人倾向于相反的说法,尽管我猜这取决于文本。使用GCP解决方案可能会更容易集成,而且可能更快,因为请求不需要离开同一个数据中心。