Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS SDK または CLI PutLexicon
で を使用する
次のサンプルコードは、PutLexicon
を使用する方法を説明しています。
- .NET
-
- AWS SDK for .NET
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 using System; using System.Threading.Tasks; using Amazon.Polly; using Amazon.Polly.Model; /// <summary> /// Creates a new Amazon Polly lexicon using the AWS SDK for .NET. /// </summary> public class PutLexicon { public static async Task Main() { string lexiconContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<lexicon version=\"1.0\" xmlns=\"http://www.w3.org/2005/01/pronunciation-lexicon\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"http://www.w3.org/2005/01/pronunciation-lexicon http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd\" " + "alphabet=\"ipa\" xml:lang=\"en-US\">" + "<lexeme><grapheme>test1</grapheme><alias>test2</alias></lexeme>" + "</lexicon>"; string lexiconName = "SampleLexicon"; var client = new AmazonPollyClient(); var putLexiconRequest = new PutLexiconRequest() { Name = lexiconName, Content = lexiconContent, }; try { var response = await client.PutLexiconAsync(putLexiconRequest); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully created Lexicon: {lexiconName}."); } else { Console.WriteLine($"Could not create Lexicon: {lexiconName}."); } } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.Message); } } }
-
API の詳細については、AWS SDK for .NET API リファレンスの「PutLexicon」を参照してください。
-
- CLI
-
- AWS CLI
-
レキシコンを保存するには
次の
put-lexicon
の例は、指定された発音レキシコンを保存します。example.pls
ファイルは W3C PLS 準拠のレキシコンを指定します。aws polly put-lexicon \ --name
w3c
\ --contentfile://example.pls
example.pls
の内容{ <?xml version="1.0" encoding="UTF-8"?> <lexicon version="1.0" xmlns="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd" alphabet="ipa" xml:lang="en-US"> <lexeme> <grapheme>W3C</grapheme> <alias>World Wide Web Consortium</alias> </lexeme> </lexicon> }
このコマンドでは何も出力されません。
詳細については、「Amazon Polly ディベロッパーガイド」の「PutLexicon オペレーションの使用」を参照してください。
-
API の詳細については、AWS CLI コマンドリファレンスの「PutLexicon
」を参照してください。
-
- 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 create_lexicon(self, name, content): """ Creates a lexicon with the specified content. A lexicon contains custom pronunciations. :param name: The name of the lexicon. :param content: The content of the lexicon. """ try: self.polly_client.put_lexicon(Name=name, Content=content) logger.info("Created lexicon %s.", name) except ClientError: logger.exception("Couldn't create lexicon %s.") raise
-
API の詳細については、AWS SDK for Python (Boto3) API リファレンスの「PutLexicon」を参照してください。
-
- Rust
-
- SDK for Rust
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 async fn make_lexicon(client: &Client, name: &str, from: &str, to: &str) -> Result<(), Error> { let content = format!("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <lexicon version=\"1.0\" xmlns=\"http://www.w3.org/2005/01/pronunciation-lexicon\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3.org/2005/01/pronunciation-lexicon http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd\" alphabet=\"ipa\" xml:lang=\"en-US\"> <lexeme><grapheme>{}</grapheme><alias>{}</alias></lexeme> </lexicon>", from, to); client .put_lexicon() .name(name) .content(content) .send() .await?; println!("Added lexicon"); Ok(()) }
-
API の詳細については、AWS SDK for Rust API リファレンスの「PutLexicon
」を参照してください。
-