一次致电即可从AWS Polly获取mp3和json(节省成本)

时间:2019-07-13 20:11:50

标签: json amazon-web-services mp3 text-to-speech amazon-polly

我在这里问了一个问题,几秒钟后我一个人回答了:Get mp3 and speech mark from Amazon Polly using NodeJs

我想知道是否必须打两次电话才能获取文本的json和mp3吗?

let params = {
    'Text': 'Hi, my name is Soley. We are building something amazing!',
    'OutputFormat': 'json',
    'VoiceId': 'Matthew',
    'SpeechMarkTypes': ['word', 'sentence']
}

let params = {
    'Text': 'Hi, my name is Soley. We are building something amazing!',
    'OutputFormat': 'mp3',
    'VoiceId': 'Matthew'
}

似乎波莉ui https://us-east-1.console.aws.amazon.com/polly/home/SynthesizeSpeech还要分开做吗?

enter image description here

^没有mp3的下载链接,仅在请求json时播放按钮。

1 个答案:

答案 0 :(得分:1)

SynthesizeSpeech API只能为输出格式采用一个参数,因此,您必须调用它两次。

 OutputFormat

    The format in which the returned output will be encoded. 
    For audio stream, this will be mp3, ogg_vorbis, or pcm. 
    For speech marks, this will be json.

    When pcm is used, the content returned is audio/pcm in a signed 16-bit, 
    1 channel (mono), little-endian format.

    Type: String

    Valid Values: json | mp3 | ogg_vorbis | pcm

    Required: Yes

https://docs.aws.amazon.com/polly/latest/dg/API_SynthesizeSpeech.html