目前正在使用亚马逊网络服务创建一个PCM音频文件,使用Polly并将其存储到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 bucket之间。
发布于 2020-03-22 12:13:43
我不想这么说,但是你已经得到了你想要的。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"
}
}这证实了你所看到的。因此,我的示例显示了如何使用命令行执行此操作,但是S3KeyPrefix所做的只是将文本添加到Polly生成的文件名之前。没有定义实际文件名的方法。
当您提交语音合成任务时,您应该捕获响应,它将告诉您TaskId,您知道一旦任务完成,它将是S3中的文件名。然后,您可以监视状态,并在完成后,将文件名更改为您想要的名称。
HTH
发布于 2021-08-31 14:58:17
简短回答:
Amazon Polly将这个神秘的TaskId添加到文件名的末尾。这事一点儿办法都没有。
如果您愿意,您可以在完成后重命名它。但您必须了解如何等待Polly SynthesisTask完成,以及如何在S3中重命名文件。我目前正在努力寻找等待任务完成的javascript文档。
https://stackoverflow.com/questions/58217760
复制相似问题