3

目前使用 AWS 服务通过 Polly 创建一个 PCM 音频文件并将其存储到 S3 存储桶中。该应用程序使用 AWS lambda 完成所有这些工作。

我正在使用“StartSpeechSynthesisTaskRequest”,它允许用户向 amazon Polly 创建一个请求,并将文件直接传送到用户选择的指定 S3 存储桶中。

我遇到的问题是,一旦运行代码,我最终会得到一个像这样的文件名:

“MY_FILE_NAME.a1f9999f-f00r-6h45-j2ks-pd7fcc9sfw77.pcm”

我想要的是:

“MY_FILE_NAME.pcm”

为什么会发生这种额外的事情?有人得到这个问题的答案吗?

我已经发布了下面的代码。

StartSpeechSynthesisTaskRequest startSpeechSynthesisRequest = new StartSpeechSynthesisTaskRequest()
                        // Required parameters
                        .withOutputFormat(PCM_FORMAT)
                        .withOutputS3BucketName(s3BucketName) <--- S3 bucket location/name
                        .withText(GREETING_FORMAT)
                        .withVoiceId(EMMA_VOICE_ID)
                        // Optional parameters
                        .withOutputS3KeyPrefix("MY_FILE_NAME") <--- my file desired name
                        .withEngine(NEURAL_ENGINE)
                        .withLanguageCode(ENGB_LANGUAGE_CODE)
                        .withSampleRate(SAMPLE_RATE)
                        .withTextType(SSML_TEXT_TYPE);
                pollyClient.startSpeechSynthesisTask(startSpeechSynthesisRequest);

更新:

如果我打印“startSpeechSynthesisRequest”,在它使用所有参数构建后,它将完全按照我的需要打印“withOutputS3KeyPrefix”。polly 和 S3 存储桶之间出现了问题。

4

2 回答 2

0

简短的回答:

Amazon PollyTaskId在文件名的末尾添加了这个神秘的含义。你对此无能为力。

如果你愿意,你可以在完成后重命名它。但是您必须了解如何等待 PollySynthesisTask完成,以及如何在 S3 中重命名文件。我目前正在努力寻找等待任务完成的任何 javascript 文档。

于 2021-08-31T14:58:17.400 回答
0

我不想这么说,但你得到了你所要求的。Polly 的输出文件是 requestId。您正在请求 S3 对象的前缀,该前缀附加到 Polly 对象。

如果我运行这个:

aws polly start-speech-synthesis-task \
--voice-id Joanna \
--output-format mp3 \
--output-s3-bucket-name BUCKET \
--text "This audio sample was created using Amazon Polly and the AWS Command Line Interface." \
--region us-west-2

回复是

{
    "SynthesisTask": {
        "TaskId": "020437c3-256f-4cd4-97d5-6785a8e477f4",
        "TaskStatus": "scheduled",
        "OutputUri": "https://s3.us-west-2.amazonaws.com/BUCKET/020437c3-256f-4cd4-97d5-6785a8e477f4.mp3",
        "CreationTime": 1584849572.835,
        "RequestCharacters": 84,
        "OutputFormat": "mp3",
        "TextType": "text",
        "VoiceId": "Joanna"
    }
}

注意输出 URI - 文件名是 TaskId。

如果我添加 S3KeyPrefix


aws polly start-speech-synthesis-task \
--voice-id Joanna \
--output-format mp3 \
--output-s3-bucket-name BUCKET \
--output-s3-key-prefix MY_FILE_NAME \
--text "This audio sample was created using Amazon Polly and the AWS Command Line Interface." \
--region us-west-2

这会产生响应

{
    "SynthesisTask": {
        "TaskId": "c887dc20-998e-47e3-9eaf-47db32aa2aa9",
        "TaskStatus": "scheduled",
        "OutputUri": "https://s3.us-west-2.amazonaws.com/BUCKET/MY_FILE_NAME.c887dc20-998e-47e3-9eaf-47db32aa2aa9.mp3",
        "CreationTime": 1584849928.825,
        "RequestCharacters": 84,
        "OutputFormat": "mp3",
        "TextType": "text",
        "VoiceId": "Joanna"
    }
}

这证实了您所看到的。因此,我的示例显示使用 CLI 执行此操作,但 S3KeyPrefix 所做的只是将文本添加到 Polly 生成的文件名。没有定义实际文件名的方法。

当您提交语音合成任务时,您应该捕获响应,它会告诉您 TaskId,您知道任务完成后它将成为 S3 中的文件名。然后,您可以监控状态,完成后,将文件名更改为您想要的任何名称。

高温高压

于 2020-03-22T04:13:43.273 回答