首页 > 解决方案 > 一次调用同时从 AWS Polly 获取 mp3 和 json(节省成本)

问题描述

我在这里问了一个问题,几秒钟后我自己回答了: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'
}

似乎 polly ui https://us-east-1.console.aws.amazon.com/polly/home/SynthesizeSpeech也分开做?

在此处输入图像描述

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

标签: jsonamazon-web-servicesmp3text-to-speechamazon-polly

解决方案


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


推荐阅读