Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Speech Synthesis using AWS Serviceless Architecture

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Structure diagram

The user inputs text through the front page, converts it into speech through a series of services in the background, and displays it in the front section, and provides download function. The whole service does not use a server! The user inputs text to submit; the page passes information to Lambda function NewPost through API code to write DynamoDB, and passes postId to SNS;SNS passes postId to Lambda function Convert, function Convert queries text data through DynamoDB through postId, and calls Polly to perform Text To Speech; function Convert stores synthesized speech files in S3, and updates database status; The user can obtain relevant information of Text To Speech through GET. II. Service deployment 2.1. Creating DynamoDB table

Very simple, write a table name, write a primary key, the other default.

Table name:posts

Primary key:id

2.2 Creating S3

We create two S3 buckets, one for static web pages and one for audio from Text To Speech.

2.2.1 Static web bucket name is freely determined by everyone. The name I choose here is pollywebsite; open public access permissions; enable static website hosting function; add bucket policy so that public users can access it. The policy is as follows: { "Version": "2012-10-17", "Id": "Policy1562738599054", "Statement": [ { "Sid": "Stmt1562738571491", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::wz-pollywebsite/*" } ]}2.2.2. The name of the audio storage bucket is arbitrary. I call it pollyaudio here; open public access. 2.3 Create SNS Topic name everyone arbitrarily set, I call it new_posts here. 2.4 Create permissions for Lambda

From the architecture diagram, we know that our Lambda function interacts with multiple components and requires relevant permissions. We create a Role for it through IAM.

Select Lambda where the selected service uses this Role; create the Role first without adding Policy; you can write the role name as you like, I call it LamdbaPostsReaderRole here; add Inline Policy for the Role, and the policy rules are as follows: { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "s3:PutObject", "polly:SynthesizeSpeech", "logs:CreateLogStream", "sns:Publish", "dynamodb:PutItem", "dynamodb:Scan", "dynamodb:Query", "dynamodb:UpdateItem", "s3:GetBucketLocation", "logs:CreateLogGroup", "logs:PutLogEvents", "s3:PutObjectAcl" ], "Resource": "*" } ]}2.5, create Lambda NewPost function name everyone freely write, I write wz_NewPost here; run environment everyone choose Python 3.7. Fill in the Python code and configure the code environment variables; assign the roles we created earlier to the functions. 2.6, create Lambda GetPosts function name everyone freely write, I write wz_GetPosts here; run environment everyone choose Python 3.7. Fill in the Python code and configure the code environment variables; assign the roles we created earlier to the functions. 2.7 Create Lambda Convert function name everyone write their own, I write wz_ConvertToAudio here; run environment everyone choose Python 3.7. Fill in the relevant Python code and configure the code environment variables; specify the role we created earlier for the function; this function takes a long time, you can adjust the function execution time to one minute; add the SNS we created as a trigger. 2.8 Create API GatewayAPI name Everyone write freely, I write PostReaderAPI here, style is REST; create a GET method, select wz_GetPosts function, add URL Query String Parameters;GET method enables CORS; create Mapping Templates, type is application/json, content is as follows: { "postId" : "$input.params ('postId ')"} Create a POST method by selecting the wz_GetPosts function. 2.9 Upload the front-end code to S32.10. Create a domain name resolution.

Note that if the domain alias resolves to the S3 bucket, the bucket name must be the same as the domain name, so I need to modify the bucket website name.

III. Verification

Test address: http://polly.wzlinux.com

Deployment tutorial video: edu.51cto.com/course/18818.html

Welcome to scan the code to get more information

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 220

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report