0

我已经集成了我的 Javascript AWS SDK,并在没有服务器的情况下向 API 发送了一个请求。一切正常,但问题是,端点“忽略”了 VoiceId。

问题:端点总是返回带有 VoiceID 'Ivy' 的 mp3。

voice例如,我发送Justin

JS

   getVoice(text, voice) {

   let awsCredentials = new AWS.Credentials("XXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXX");
   let settings = {
       awsCredentials: awsCredentials,
       awsRegion: "us-west-2",
       pollyVoiceId: voice,
       cacheSpeech: false
   }

   AWS.config.credentials = settings.awsCredentials;
   AWS.config.region = settings.awsRegion;

   let speechfile = new Promise(function (successCallback, errorCallback) {
        var polly = new AWS.Polly();
        var params = {
            OutputFormat: 'mp3',
            TextType: "ssml",
            Text: text,
            VoiceId: settings.pollyVoiceId
        }
        polly.synthesizeSpeech(params, function (error, data) {
            if (error) {
                errorCallback(error)
            } else {
                let audiostream = data.AudioStream;
                successCallback(audiostream);
            }
        });
    });
    return speechfile;
 }
4

1 回答 1

0

发现问题。我的服务中不允许使用 var 'voice'。

 getVoice(text, currentVoice) {

   let voi = currentVoice;


   let awsCredentials = new AWS.Credentials("xxxxxxxxxx", "xxxxxxxx");
   let settings = {
       awsCredentials: awsCredentials,
       awsRegion: "us-west-1",
       cacheSpeech: false
   }

   AWS.config.credentials = settings.awsCredentials;
   AWS.config.region = settings.awsRegion;

   let speechfile = new Promise(function (successCallback, errorCallback) {
        var polly = new AWS.Polly();
        var params = {
            LanguageCode: "en-US",
            OutputFormat: 'mp3',
            TextType: "ssml",
            Text: text,
            VoiceId: voi
        }
        polly.synthesizeSpeech(params, function (error, data) {
            if (error) {
                errorCallback(error)
            } else {
                //alert(text + data.AudioStream);
                let audiostream = data.AudioStream;
                successCallback(audiostream);
            }
        });
    });
    return speechfile;
    // end getVoice
 }
于 2018-09-04T10:03:09.657 回答