AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或GetLexicon
一起使用 CLI
以下代码示例演示如何使用 GetLexicon
。
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 using System; using System.Threading.Tasks; using Amazon.Polly; using Amazon.Polly.Model; /// <summary> /// Retrieves information about a specific Amazon Polly lexicon. /// </summary> public class GetLexicon { public static async Task Main(string[] args) { string lexiconName = "SampleLexicon"; var client = new AmazonPollyClient(); await GetPollyLexiconAsync(client, lexiconName); } public static async Task GetPollyLexiconAsync(AmazonPollyClient client, string lexiconName) { var getLexiconRequest = new GetLexiconRequest() { Name = lexiconName, }; try { var response = await client.GetLexiconAsync(getLexiconRequest); Console.WriteLine($"Lexicon:\n Name: {response.Lexicon.Name}"); Console.WriteLine($"Content: {response.Lexicon.Content}"); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } } }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 GetLexicon” 中的。
-
- CLI
-
- AWS CLI
-
检索词典的内容
以下
get-lexicon
示例检索指定的发音词典内容。aws polly get-lexicon \ --name
w3c
输出:
{ "Lexicon": { "Content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<lexicon version=\"1.0\" \n xmlns= \"http://www.w3.org/2005/01/pronunciation-lexicon\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n xsi:schemaLocation=\"http://www.w3.org/2005/01/pronunciation-lexicon \n http://www.w3.org/TR/2007/CR-pronunciation- lexicon-20071212/pls.xsd\"\n alphabet=\"ipa\" \n xml:lang=\"en-US\">\n <lexeme>\n <grapheme>W3C</grapheme>\n <alias>World Wide Web Consortium</alias>\n </lexeme>\n</lexicon>\n", "Name": "w3c" }, "LexiconAttributes": { "Alphabet": "ipa", "LanguageCode": "en-US", "LastModified": 1603908910.99, "LexiconArn": "arn:aws:polly:us-west-2:880185128111:lexicon/w3c", "LexemesCount": 1, "Size": 492 } }
有关更多信息,请参阅 Amazon Polly 开发者指南中的使用 GetLexicon 操作。
-
有关API详细信息,请参阅 “GetLexicon AWS CLI
命令参考”。
-
- Python
-
- SDK适用于 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_lexicon(self, name): """ Gets metadata and contents of an existing lexicon. :param name: The name of the lexicon to retrieve. :return: The retrieved lexicon. """ try: response = self.polly_client.get_lexicon(Name=name) logger.info("Got lexicon %s.", name) except ClientError: logger.exception("Couldn't get lexicon %s.", name) raise else: return response
-
有关API详细信息,请参阅GetLexicon中的 AWS SDKPython (Boto3) API 参考。
-
DescribeVoices
GetSpeechSynthesisTask