{"id":101,"date":"2019-06-22T12:20:06","date_gmt":"2019-06-22T03:20:06","guid":{"rendered":"https:\/\/pocolog.bass-world.net\/tech\/?p=101"},"modified":"2019-06-22T12:20:06","modified_gmt":"2019-06-22T03:20:06","slug":"amazon-polly-sample-code","status":"publish","type":"post","link":"https:\/\/pocolog.bass-world.net\/tech\/2019\/amazon-polly-sample-code\/","title":{"rendered":"Amazon Polly \u306e\u8aad\u307f\u4e0a\u3052\u30c6\u30b9\u30c8 &#8211; \u30d7\u30ed\u30b0\u30e9\u30e0\u4f5c\u3063\u3066\u307f\u305f"},"content":{"rendered":"\n<p>Amazon AWS \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u53c2\u8003\u306b\u3001\u3061\u3087\u3063\u3068\u3060\u3051\u4fee\u6b63\u3057\u3066 Amazon Polly \u306e\u8aad\u307f\u4e0a\u3052\u30c6\u30b9\u30c8\u3092\u4f5c\u3063\u3066\u307f\u305f\u3002<br><a href=\"https:\/\/www.bass-world.net\/gadgets\/polly.html\">\u30b5\u30f3\u30d7\u30eb\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089\u3002<\/a><\/p>\n\n\n\n<p>\u4ee5\u4e0b\u304c\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/p>\n\n\n\n<!--more-->\n\n\n\n<blockquote><pre><code>&lt;h2&gt;&lt;a name = \"polly\" id = \"polly\"&gt;AWS Polly \u8aad\u307f\u4e0a\u3052\u30c6\u30b9\u30c8&lt;\/a&gt;&lt;\/h2&gt;\n&lt;div id=\"textToSynth\"&gt;\n&lt;textarea autofocus rows = \"10\" cols = \"83\" id = \"textEntry\" \n\t\tstyle = \"font-family: Arial,Arial, Helvetica, \u30e1\u30a4\u30ea\u30aa\"&gt;\nMany a morning hath he there been seen,\nWith tears augmenting the fresh morning dew.\nAdding to clouds more clouds with his deep sighs;\nBut all so soon as the all-cheering sun\nShould in the furthest east begin to draw\nThe shady curtains from Aurora's bed,\nAway from the light steals home my heavy son,\nAnd private in his chamber pens himself,\nShuts up his windows, locks far daylight out\nAnd makes himself an artificial night:\nBlack and portentous must this humour prove,\nUnless good counsel may the cause remove.\n&lt;\/textarea&gt;\n&lt;br \/&gt;\n&lt;select name = \"speaker\" id = \"speaker\"&gt;\n\t&lt;option value = \"Nicole\"&gt;\u30aa\u30fc\u30b9\u30c8\u30e9\u30ea\u30a2\u82f1\u8a9e - Nicole&lt;\/option&gt;\n\t&lt;option value = \"Russell\"&gt;\u30aa\u30fc\u30b9\u30c8\u30e9\u30ea\u30a2\u82f1\u8a9e - Russell&lt;\/option&gt;\n\t&lt;option value = \"Emma\"&gt;\u30a4\u30ae\u30ea\u30b9\u82f1\u8a9e - Emma&lt;\/option&gt;\n\t&lt;option value = \"Amy\"&gt;\u30a4\u30ae\u30ea\u30b9\u82f1\u8a9e - Amy&lt;\/option&gt;\n\t&lt;option value = \"Brian\"&gt;\u30a4\u30ae\u30ea\u30b9\u82f1\u8a9e - Brian&lt;\/option&gt;\n\t&lt;option value = \"Raveena\"&gt;\u30a4\u30f3\u30c9\u82f1\u8a9e - Raveena&lt;\/option&gt;\n\t&lt;option value = \"Aditi\"&gt;\u30a4\u30f3\u30c9\u82f1\u8a9e - Aditi&lt;\/option&gt;\n\t&lt;option value = \"Ivy\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Ivy&lt;\/option&gt;\n\t&lt;option value = \"Joanna\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Joanna&lt;\/option&gt;\n\t&lt;option value = \"Joey\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Joey&lt;\/option&gt;\n\t&lt;option value = \"Justin\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Justin&lt;\/option&gt;\n\t&lt;option value = \"Kendra\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Kendra&lt;\/option&gt;\n\t&lt;option value = \"Kimberly\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Kimberly&lt;\/option&gt;\n\t&lt;option value = \"Matthew\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Matthew&lt;\/option&gt;\n\t&lt;option value = \"Salli\"&gt;\u30a2\u30e1\u30ea\u30ab\u82f1\u8a9e - Salli&lt;\/option&gt;\n\t&lt;option value = \"Geraint\"&gt;\u30a6\u30a7\u30fc\u30eb\u30ba\u82f1\u8a9e - Geraint&lt;\/option&gt;\n\t&lt;option value = \"Hans\"&gt;\u30c9\u30a4\u30c4\u8a9e - Hans&lt;\/option&gt;\n\t&lt;option value = \"Marlene\"&gt;\u30c9\u30a4\u30c4\u8a9e - Marlene&lt;\/option&gt;\n\t&lt;option value = \"Vicki\"&gt;\u30c9\u30a4\u30c4\u8a9e - Vicki&lt;\/option&gt;\n\t&lt;option value = \"Chantal\"&gt;\u30ab\u30ca\u30c0\u30d5\u30e9\u30f3\u30b9\u8a9e - Chantal&lt;\/option&gt;\n\t&lt;option value = \"Mathieu\"&gt;\u30d5\u30e9\u30f3\u30b9\u8a9e - Mathieu&lt;\/option&gt;\n\t&lt;option value = \"Celine\"&gt;\u30d5\u30e9\u30f3\u30b9\u8a9e - Celine&lt;\/option&gt;\n\t&lt;option value = \"Lea\"&gt;\u30d5\u30e9\u30f3\u30b9\u8a9e - Lea&lt;\/option&gt;\n\t&lt;option value = \"Mizuki\"&gt;\u65e5\u672c\u8a9e - Mizuki&lt;\/option&gt;\n\t&lt;option value = \"Takumi\"&gt;\u65e5\u672c\u8a9e - Takumi&lt;\/option&gt;\n\t&lt;option value = \"Zhiyu\"&gt;\u4e2d\u56fd\u8a9e(\u30de\u30f3\u30c0\u30ea\u30f3) - Zhiyu&lt;\/option&gt;\n&lt;\/select&gt;\n&lt;button class=\"btn default\" onClick=\"speakText()\"&gt;\u97f3\u58f0\u5408\u6210&lt;\/button&gt;\n&lt;p id=\"result\"&gt;\u6587\u7ae0\u3092\u5165\u529b\u3057\u3066\u3001\u97f3\u58f0\u5408\u6210\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3002&lt;\/p&gt;\n&lt;\/div&gt;\n&lt;audio id=\"audioPlayback\" controls&gt;\n\t&lt;script src=\"https:\/\/sdk.amazonaws.com\/js\/aws-sdk-2.476.0.min.js\"&gt;\n        &lt;\/script&gt;\n\t&lt;source id=\"audioSource\" type=\"audio\/mp3\" src=\"\"&gt;\n&lt;\/audio&gt;\n&lt;script&gt;\n\t\/\/ Initialize the Amazon Cognito credentials provider\n\tAWS.config.region = '<em>YOUR_REGION<\/em>'; \n\tAWS.config.credentials = new AWS.CognitoIdentityCredentials(\n\t\t{IdentityPoolId: '<em>YOUR_CREDENTIALS<\/em>'});\n\t\n\t\/\/ Function invoked by button click\n\tfunction speakText() {\n\t\t\/\/ Create the JSON parameters for getSynthesizeSpeechUrl\n\t\tvar speechParams = {\n\t\t\tOutputFormat: \"mp3\",\n\t\t\tSampleRate: \"22050\",\n\t\t\tText: \"\",\n\t\t\tTextType: \"text\",\n\t\t\tVoiceId: \"Emma\"\n\t\t};\n\t\tspeechParams.Text =\n\t\t\tdocument.getElementById(\"textEntry\").value;\n\t\tspeechParams.VoiceId =\n\t\t\tdocument.getElementById(\"speaker\").value;\n\t\t\/\/ Create the Polly service object and presigner object\n\t\tvar polly = new AWS.Polly({apiVersion: '2016-06-10'});\n\t\tvar signer = \n\t\t\tnew AWS.Polly.Presigner(speechParams, polly)\n\n\t\t\/\/ Create presigned URL of synthesized speech file\n\t\tsigner.getSynthesizeSpeechUrl(speechParams,\n\t\t\tfunction(error, url) {\n\t\tif (error) {\n\t\t\tdocument.getElementById('result').innerHTML = error;\n\t\t} else {\n\t\t\tdocument.getElementById('audioSource').src = url;\n\t\t\tdocument.getElementById('audioPlayback').load();\n\t\t\tdocument.getElementById('result').innerHTML =\n\t\t\t\t\"\u8aad\u307f\u4e0a\u3052\u6e96\u5099\u5b8c\u4e86\";\n\t\t}\n\t\t});\n\t}\n&lt;\/script&gt;\n&lt;\/div&gt;&lt;!-- article --&gt;<\/code><\/pre><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Amazon AWS \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u53c2\u8003\u306b\u3001\u3061\u3087\u3063\u3068\u3060\u3051\u4fee\u6b63\u3057\u3066 Amazon Polly \u306e\u8aad\u307f\u4e0a\u3052\u30c6\u30b9\u30c8\u3092\u4f5c\u3063\u3066\u307f\u305f\u3002\u30b5\u30f3\u30d7\u30eb\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089\u3002 \u4ee5\u4e0b\u304c\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,9],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-amazon-aws","category-javascript"],"_links":{"self":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":0,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"wp:attachment":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}