-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
85 lines (79 loc) · 3.31 KB
/
index2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!--
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
-->
<!--
snippet-sourcedescription:[polly.html demonstrates browser access to Amazon Polly.]
snippet-service:[Amazon Polly]
snippet-keyword:[HTML]
snippet-keyword:[Amazon Polly]
snippet-keyword:[Code Sample]
snippet-sourcetype:[full-example]
snippet-sourcedate:[2019-02-25]
snippet-sourceauthor:[AWS]
// ABOUT THIS BROWSER SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at
// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-started-browser.html
-->
<!-- snippet-start:[Polly.HTML.BrowserExample.complete] -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AWS SDK for JavaScript - Browser Getting Started Application</title>
</head>
<body>
<div id="textToSynth">
<input autofocus size="23" type="text" id="textEntry" value="It's very good to meet you."/>
<button class="btn default" onClick="speakText()">Synthesize</button>
<p id="result">Enter text above then click Synthesize</p>
</div>
<audio id="audioPlayback" controls>
<source id="audioSource" type="audio/mp3" src="">
</audio>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.410.0.min.js"></script>
<!-- snippet-start:[Polly.HTML.BrowserExample.config] -->
<script type="text/javascript">
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: 'us-east-2:4686738e-be9e-446e-a2c2-b332ab95d0a6'});
// Function invoked by button click
function speakText() {
// Create the JSON parameters for getSynthesizeSpeechUrl
var speechParams = {
OutputFormat: "mp3",
SampleRate: "16000",
Text: "",
TextType: "text",
VoiceId: "Matthew"
};
speechParams.Text = document.getElementById("textEntry").value;
<!-- snippet-end:[Polly.HTML.BrowserExample.config] -->
<!-- snippet-start:[Polly.HTML.BrowserExample.synthesize] -->
// Create the Polly service object and presigner object
var polly = new AWS.Polly({apiVersion: '2016-06-10'});
var signer = new AWS.Polly.Presigner(speechParams, polly)
// Create presigned URL of synthesized speech file
signer.getSynthesizeSpeechUrl(speechParams, function(error, url) {
if (error) {
document.getElementById('result').innerHTML = error;
} else {
document.getElementById('audioSource').src = url;
document.getElementById('audioPlayback').load();
document.getElementById('result').innerHTML = "Speech ready to play.";
}
});
}
</script>
<!-- snippet-end:[Polly.HTML.BrowserExample.synthesize] -->
</body>
</html>
<!-- snippet-end:[Polly.HTML.BrowserExample.complete] -->