Verwendung ListLexicons mit einem AWS SDK oder CLI - AWS SDK-Codebeispiele

Weitere AWS SDK-Beispiele sind im Repo AWS Doc SDK Examples GitHub verfügbar.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Verwendung ListLexicons mit einem AWS SDK oder CLI

Die folgenden Codebeispiele zeigen, wie es verwendet wirdListLexicons.

.NET
AWS SDK for .NET
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

using System; using System.Threading.Tasks; using Amazon.Polly; using Amazon.Polly.Model; /// <summary> /// Lists the Amazon Polly lexicons that have been defined. By default, /// lists the lexicons that are defined in the same AWS Region as the default /// user. To view Amazon Polly lexicons that are defined in a different AWS /// Region, supply it as a parameter to the Amazon Polly constructor. /// </summary> public class ListLexicons { public static async Task Main() { var client = new AmazonPollyClient(); var request = new ListLexiconsRequest(); try { Console.WriteLine("All voices: "); do { var response = await client.ListLexiconsAsync(request); request.NextToken = response.NextToken; response.Lexicons.ForEach(lexicon => { var attributes = lexicon.Attributes; Console.WriteLine($"Name: {lexicon.Name}"); Console.WriteLine($"\tAlphabet: {attributes.Alphabet}"); Console.WriteLine($"\tLanguageCode: {attributes.LanguageCode}"); Console.WriteLine($"\tLastModified: {attributes.LastModified}"); Console.WriteLine($"\tLexemesCount: {attributes.LexemesCount}"); Console.WriteLine($"\tLexiconArn: {attributes.LexiconArn}"); Console.WriteLine($"\tSize: {attributes.Size}"); }); } while (request.NextToken is not null); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } }
  • Einzelheiten zur API finden Sie ListLexiconsin der AWS SDK for .NET API-Referenz.

CLI
AWS CLI

Um Ihre Lexika aufzulisten

Das folgende list-lexicons Beispiel listet Ihre Aussprachelexika auf.

aws polly list-lexicons

Ausgabe:

{ "Lexicons": [ { "Name": "w3c", "Attributes": { "Alphabet": "ipa", "LanguageCode": "en-US", "LastModified": 1603908910.99, "LexiconArn": "arn:aws:polly:us-east-2:123456789012:lexicon/w3c", "LexemesCount": 1, "Size": 492 } } ] }

Weitere Informationen finden Sie unter Verwenden des ListLexicons Vorgangs im Amazon Polly Developer Guide.

  • Einzelheiten zur API finden Sie ListLexiconsin der AWS CLI Befehlsreferenz.

Java
SDK für Java 2.x
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.polly.PollyClient; import software.amazon.awssdk.services.polly.model.ListLexiconsResponse; import software.amazon.awssdk.services.polly.model.ListLexiconsRequest; import software.amazon.awssdk.services.polly.model.LexiconDescription; import software.amazon.awssdk.services.polly.model.PollyException; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListLexicons { public static void main(String args[]) { PollyClient polly = PollyClient.builder() .region(Region.US_WEST_2) .build(); listLexicons(polly); polly.close(); } public static void listLexicons(PollyClient client) { try { ListLexiconsRequest listLexiconsRequest = ListLexiconsRequest.builder() .build(); ListLexiconsResponse listLexiconsResult = client.listLexicons(listLexiconsRequest); List<LexiconDescription> lexiconDescription = listLexiconsResult.lexicons(); for (LexiconDescription lexDescription : lexiconDescription) { System.out.println("The name of the Lexicon is " + lexDescription.name()); } } catch (PollyException e) { System.err.println("Exception caught: " + e); System.exit(1); } } }
  • Einzelheiten zur API finden Sie ListLexiconsin der AWS SDK for Java 2.x API-Referenz.

Python
SDK für Python (Boto3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository 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 list_lexicons(self): """ Lists lexicons in the current account. :return: The list of lexicons. """ try: response = self.polly_client.list_lexicons() lexicons = response["Lexicons"] logger.info("Got %s lexicons.", len(lexicons)) except ClientError: logger.exception( "Couldn't get %s.", ) raise else: return lexicons
  • Einzelheiten zur API finden Sie ListLexiconsin AWS SDK for Python (Boto3) API Reference.

Ruby
SDK für Ruby
Anmerkung

Es gibt noch mehr dazu. GitHub Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

require "aws-sdk-polly" # In v2: require 'aws-sdk' begin # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new resp = polly.list_lexicons resp.lexicons.each do |l| puts l.name puts " Alphabet:" + l.attributes.alphabet puts " Language:" + l.attributes.language puts end rescue StandardError => ex puts "Could not get lexicons" puts "Error message:" puts ex.message end
  • Einzelheiten zur API finden Sie ListLexiconsin der AWS SDK for Ruby API-Referenz.

Rust
SDK für Rust
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

async fn show_lexicons(client: &Client) -> Result<(), Error> { let resp = client.list_lexicons().send().await?; println!("Lexicons:"); let lexicons = resp.lexicons(); for lexicon in lexicons { println!(" Name: {}", lexicon.name().unwrap_or_default()); println!( " Language: {:?}\n", lexicon .attributes() .as_ref() .map(|attrib| attrib .language_code .as_ref() .expect("languages must have language codes")) .expect("languages must have attributes") ); } println!(); println!("Found {} lexicons.", lexicons.len()); println!(); Ok(()) }
  • Einzelheiten zur API finden Sie ListLexiconsin der API-Referenz zum AWS SDK für Rust.