AWS SDK を使用して Amazon Polly の発音レキシコンを一覧表示する - AWS SDK コードサンプル

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK を使用して Amazon Polly の発音レキシコンを一覧表示する

次のコード例は、Amazon Polly 発音レキシコンを一覧表示する方法を示しています。

.NET
AWS SDK for .NET
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

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}"); } } }
  • API の詳細については、「 API リファレンスListLexicons」の「」を参照してください。 AWS SDK for .NET

CLI
AWS CLI

レキシコンを一覧表示するには

次の list-lexicons の例は、発音レキシコンを一覧表示します。

aws polly list-lexicons

出力:

{ "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 } } ] }

詳細については、「Amazon Polly デベロッパーガイド」の「 ListLexicons オペレーションの使用」を参照してください。

  • API の詳細については、「 コマンドリファレンスListLexicons」の「」を参照してください。 AWS CLI

Java
SDK for Java 2.x
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

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); } } }
  • API の詳細については、「 API リファレンスListLexicons」の「」を参照してください。 AWS SDK for Java 2.x

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 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
  • API の詳細については、 ListLexicons AWS SDK for Python (Boto3) API リファレンスの「」を参照してください。

Ruby
SDK for Ruby
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

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
  • API の詳細については、「 API リファレンスListLexicons」の「」を参照してください。 AWS SDK for Ruby

Rust
SDK for Rust
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

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(()) }
  • API の詳細については、ListLexiconsAWS「 SDK for Rust API リファレンス」の「」を参照してください。