GetSpeechSynthesisTask与 AWS SDK 或 CLI 配合使用 - AWS SDK 代码示例

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

GetSpeechSynthesisTask与 AWS SDK 或 CLI 配合使用

以下代码示例演示如何使用 GetSpeechSynthesisTask

CLI
AWS CLI

获取有关语音合成任务的信息

以下 get-speech-synthesis-task 示例检索有关指定语音合成任务的信息。

aws polly get-speech-synthesis-task \ --task-id 70b61c0f-57ce-4715-a247-cae8729dcce9

输出:

{ "SynthesisTask": { "TaskId": "70b61c0f-57ce-4715-a247-cae8729dcce9", "TaskStatus": "completed", "OutputUri": "https://s3.us-west-2.amazonaws.com/my-s3-bucket/70b61c0f-57ce-4715-a247-cae8729dcce9.mp3", "CreationTime": 1603911042.689, "RequestCharacters": 1311, "OutputFormat": "mp3", "TextType": "text", "VoiceId": "Joanna" } }

有关更多信息,请参阅《Amazon Polly 开发人员指南》中的创建长音频文件

Python
SDK for Python (Boto3)
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整实例,了解如何进行设置和运行。

class PollyWrapper: """Encapsulates Amazon Polly functions.""" def __init__(self, polly_client, s3_resource): """ :param polly_client: A Boto3 Amazon Polly client. :param s3_resource: A Boto3 Amazon Simple Storage Service (Amazon S3) resource. """ self.polly_client = polly_client self.s3_resource = s3_resource self.voice_metadata = None def get_speech_synthesis_task(self, task_id): """ Gets metadata about an asynchronous speech synthesis task, such as its status. :param task_id: The ID of the task to retrieve. :return: Metadata about the task. """ try: response = self.polly_client.get_speech_synthesis_task(TaskId=task_id) task = response["SynthesisTask"] logger.info("Got synthesis task. Status is %s.", task["TaskStatus"]) except ClientError: logger.exception("Couldn't get synthesis task %s.", task_id) raise else: return task
  • 有关 API 的详细信息,请参阅适用GetSpeechSynthesisTaskPython 的AWS SDK (Boto3) API 参考