Verwendung von GetSpeechSynthesisTask mit einem AWS-SDK oder CLI - AWS-SDK-Codebeispiele

Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs verfügbar.

Verwendung von GetSpeechSynthesisTask mit einem AWS-SDK oder CLI

Die folgenden Code-Beispiele zeigen, wie GetSpeechSynthesisTask verwendet wird.

CLI
AWS CLI

So rufen Sie Informationen über eine Sprachsyntheseaufgabe ab

Im folgenden get-speech-synthesis-task-Beispiel werden Informationen über die angegebene Sprachsyntheseaufgabe abgerufen.

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

Ausgabe:

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

Weitere Informationen finden Sie unter Erstellen von langen Audiodateien im Amazon-Polly-Entwicklerhandbuch.

Python
SDK für Python (Boto3)
Anmerkung

Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel- einrichten und ausführen.

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
  • Weitere API-Informationen finden Sie unter GetSpeechSynthesisTask in der API-Referenz zum AWS SDK für Python (Boto3).