Jinsu Park

Initial commit

Showing 1 changed file with 53 additions and 0 deletions
1 +## Polly
2 +
3 +> Polly는 text를 음성으로 변환해주는 AWS의 한 서비스이다.
4 +
5 +### 권한 (Cognito service)
6 +
7 +모든 AWS는 이용하려면 그를 위한 자격 증명이 필요하다.
8 +브라우저에서 이용자가 바로 AWS 서비스를 이용하려면 AWS 서비스를 이용하기위한 자격증명이 필요하지만, IAM User의 Credential을
9 +웹페이지 코드에 공개하는 것은 바람직하지않다.
10 +`Cognito` 는 이런 경우에 웹페이지에서의 인증, 인가 상태와 AWS 서비스를 위한 인증, 인가를 연동할 수 있도록 해주는 AWS의 한 서비스이다.
11 +
12 +우리는 인증되지않은 사용자도 Polly를 통해 TTS(text to speech) 기능을 이용할 수 있도록 Cognito의 자격 증명 풀을 생성했고, 그들은 Polly full access 권한을 갖는다.
13 +
14 +### 사용 방법
15 +
16 +```html
17 +<script src="https://sdk.amazonaws.com/js/aws-sdk-2.796.0.min.js"></script>
18 +```
19 +
20 +브라우저에서 javascript AWS SDK를 설치한다(불러온다).
21 +
22 +```html
23 +<script>
24 +<!-- Polly 사용하기 위한 자격증명을 설정한다. -->
25 +AWS.config.region = 'ap-northeast-2';
26 +AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: 'ap-northeast-2:03db97c9-a857-45f3-be6e-3cf84d6f619b'});
27 +const polly = new AWS.Polly({
28 + signatureVersion: 'v4',
29 + region: 'ap-northeast-2',
30 +});
31 +
32 +let params = {
33 + 'Text': '반가워 친구야~',
34 + 'OutputFormat': 'mp3',
35 + 'VoiceId': 'Seoyeon'
36 +};
37 +let tts = new AWS.Polly.Presigner(params, polly)
38 +
39 +
40 +// Create presigned URL of synthesized speech file
41 +tts.getSynthesizeSpeechUrl(params, function(error, url) {
42 + if (error) {
43 + } else {
44 + setTimeout(()=>{
45 + console.log("실행")
46 + let audio = new Audio(url)
47 + audio.play()
48 + .then(delete audio);
49 + }, 3000)
50 + }
51 +})
52 +</script>
53 +```