Skip to content

Commit e198f7c

Browse files
committed
Add mixed tutorials (batch 25)
1 parent 49f07d9 commit e198f7c

9 files changed

Lines changed: 640 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Transcribe: Transcribe audio to text
2+
3+
## Source
4+
5+
https://docs.aws.amazon.com/transcribe/latest/dg/getting-started.html
6+
7+
## Use case
8+
9+
- **ID**: transcribe/getting-started
10+
- **Level**: beginner
11+
- **Core actions**: `transcribe:StartTranscriptionJob`
12+
13+
## Steps
14+
15+
1. Create a sample audio file (WAV with silence)
16+
2. Upload to S3
17+
3. Start a transcription job
18+
4. Wait for completion
19+
5. Get results
20+
6. List transcription jobs
21+
22+
## Resources created
23+
24+
| Resource | Type |
25+
|----------|------|
26+
| `transcribe-tut-<random>` | S3 bucket |
27+
| `tut-job-<random>` | Transcription job |
28+
29+
## Cost
30+
31+
Transcribe pricing is per second of audio transcribed. This tutorial transcribes 1 second, costing a fraction of a cent.
32+
33+
## Duration
34+
35+
~16 seconds
36+
37+
## Related docs
38+
39+
- [Getting started with Amazon Transcribe](https://docs.aws.amazon.com/transcribe/latest/dg/getting-started.html)
40+
- [Amazon Transcribe API reference](https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html)
41+
- [Supported languages](https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html)
42+
- [Amazon Transcribe pricing](https://aws.amazon.com/transcribe/pricing/)
43+
44+
---
45+
46+
## Appendix: Generation details
47+
48+
| Field | Value |
49+
|-------|-------|
50+
| Generation date | 2026-04-14 |
51+
| Source script | New, 106 lines |
52+
| Script test result | EXIT 0, 16s, 6 steps, no issues |
53+
| Issues encountered | None |
54+
| Iterations | v1 |
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Transcribe audio to text with Amazon Transcribe
2+
3+
This tutorial shows you how to create a sample audio file, upload it to Amazon S3, start a transcription job with Amazon Transcribe, wait for the job to complete, retrieve the results, and list recent transcription jobs.
4+
5+
## Prerequisites
6+
7+
- AWS CLI configured with credentials and a default region
8+
- Python 3 installed (used to generate a WAV file)
9+
- Permissions for `transcribe:StartTranscriptionJob`, `transcribe:GetTranscriptionJob`, `transcribe:ListTranscriptionJobs`, `transcribe:DeleteTranscriptionJob`, `s3:CreateBucket`, `s3:PutObject`, `s3:DeleteObject`, `s3:DeleteBucket`
10+
11+
## Step 1: Create a sample audio file
12+
13+
Generate a 1-second WAV file containing silence using Python. This gives Transcribe a valid audio file to process without needing an external recording.
14+
15+
```bash
16+
python3 -c "
17+
import struct, wave
18+
with wave.open('/tmp/sample.wav', 'w') as w:
19+
w.setnchannels(1)
20+
w.setsampwidth(2)
21+
w.setframerate(16000)
22+
w.writeframes(struct.pack('<' + 'h' * 16000, *([0] * 16000)))
23+
"
24+
```
25+
26+
The file is 16 kHz mono PCM, which is the recommended format for Amazon Transcribe. One second of silence produces a ~32 KB file.
27+
28+
## Step 2: Upload to S3
29+
30+
Create an S3 bucket and upload the audio file. Transcribe reads input from S3.
31+
32+
```bash
33+
BUCKET_NAME="transcribe-tut-$(openssl rand -hex 4)-$(aws sts get-caller-identity --query 'Account' --output text)"
34+
35+
aws s3api create-bucket --bucket "$BUCKET_NAME"
36+
aws s3 cp /tmp/sample.wav "s3://$BUCKET_NAME/sample.wav" --quiet
37+
```
38+
39+
For regions other than `us-east-1`, the script adds `--create-bucket-configuration LocationConstraint=$REGION`.
40+
41+
## Step 3: Start a transcription job
42+
43+
Start an asynchronous transcription job pointing to the uploaded audio.
44+
45+
```bash
46+
JOB_NAME="tut-job-$(openssl rand -hex 4)"
47+
48+
aws transcribe start-transcription-job \
49+
--transcription-job-name "$JOB_NAME" \
50+
--language-code en-US \
51+
--media "MediaFileUri=s3://$BUCKET_NAME/sample.wav" \
52+
--output-bucket-name "$BUCKET_NAME" \
53+
--query 'TranscriptionJob.{Name:TranscriptionJobName,Status:TranscriptionJobStatus}' \
54+
--output table
55+
```
56+
57+
`--language-code` specifies the language of the audio. `--output-bucket-name` tells Transcribe where to write the JSON result file. Without it, Transcribe uses a service-managed bucket.
58+
59+
## Step 4: Wait for completion
60+
61+
Poll the job status until it reaches `COMPLETED` or `FAILED`.
62+
63+
```bash
64+
for i in $(seq 1 30); do
65+
STATUS=$(aws transcribe get-transcription-job \
66+
--transcription-job-name "$JOB_NAME" \
67+
--query 'TranscriptionJob.TranscriptionJobStatus' --output text)
68+
echo " Status: $STATUS"
69+
[ "$STATUS" = "COMPLETED" ] || [ "$STATUS" = "FAILED" ] && break
70+
sleep 5
71+
done
72+
```
73+
74+
Most short audio files complete within 15–30 seconds. The script polls every 5 seconds with a 150-second timeout.
75+
76+
## Step 5: Get results
77+
78+
Retrieve the transcript URI from the completed job.
79+
80+
```bash
81+
aws transcribe get-transcription-job \
82+
--transcription-job-name "$JOB_NAME" \
83+
--query 'TranscriptionJob.Transcript.TranscriptFileUri' --output text
84+
```
85+
86+
The result is a JSON file in your S3 bucket containing the transcript text, confidence scores, and word-level timestamps. Since the input was silence, the transcript will be empty or minimal.
87+
88+
## Step 6: List transcription jobs
89+
90+
List recent completed transcription jobs.
91+
92+
```bash
93+
aws transcribe list-transcription-jobs --status COMPLETED \
94+
--query 'TranscriptionJobSummaries[:3].{Name:TranscriptionJobName,Status:TranscriptionJobStatus,Created:CreationTime}' \
95+
--output table
96+
```
97+
98+
You can filter by `--status` (`QUEUED`, `IN_PROGRESS`, `COMPLETED`, `FAILED`) and by `--job-name-contains` to find specific jobs.
99+
100+
## Cleanup
101+
102+
Delete the transcription job and the S3 bucket:
103+
104+
```bash
105+
aws transcribe delete-transcription-job --transcription-job-name "$JOB_NAME"
106+
aws s3 rm "s3://$BUCKET_NAME" --recursive
107+
aws s3 rb "s3://$BUCKET_NAME"
108+
```
109+
110+
Amazon Transcribe charges per second of audio transcribed. This tutorial transcribes 1 second of audio, costing a fraction of a cent. The S3 bucket is also deleted during cleanup.
111+
112+
The script automates all steps including cleanup:
113+
114+
```bash
115+
bash amazon-transcribe-gs.sh
116+
```
117+
118+
## Related resources
119+
120+
- [Getting started with Amazon Transcribe](https://docs.aws.amazon.com/transcribe/latest/dg/getting-started.html)
121+
- [Amazon Transcribe API reference](https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html)
122+
- [Supported languages](https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html)
123+
- [Amazon Transcribe pricing](https://aws.amazon.com/transcribe/pricing/)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
# Tutorial: Transcribe audio to text with Amazon Transcribe
3+
# Source: https://docs.aws.amazon.com/transcribe/latest/dg/getting-started.html
4+
5+
WORK_DIR=$(mktemp -d)
6+
LOG_FILE="$WORK_DIR/transcribe-$(date +%Y%m%d-%H%M%S).log"
7+
exec > >(tee -a "$LOG_FILE") 2>&1
8+
9+
REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}}
10+
if [ -z "$REGION" ]; then
11+
echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1"
12+
exit 1
13+
fi
14+
export AWS_DEFAULT_REGION="$REGION"
15+
ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
16+
echo "Region: $REGION"
17+
18+
RANDOM_ID=$(openssl rand -hex 4)
19+
BUCKET_NAME="transcribe-tut-${RANDOM_ID}-${ACCOUNT_ID}"
20+
JOB_NAME="tut-job-${RANDOM_ID}"
21+
22+
handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }
23+
trap 'handle_error $LINENO' ERR
24+
25+
cleanup() {
26+
echo ""
27+
echo "Cleaning up resources..."
28+
aws transcribe delete-transcription-job --transcription-job-name "$JOB_NAME" 2>/dev/null && echo " Deleted job $JOB_NAME"
29+
if aws s3 ls "s3://$BUCKET_NAME" > /dev/null 2>&1; then
30+
aws s3 rm "s3://$BUCKET_NAME" --recursive --quiet 2>/dev/null
31+
aws s3 rb "s3://$BUCKET_NAME" 2>/dev/null && echo " Deleted bucket $BUCKET_NAME"
32+
fi
33+
rm -rf "$WORK_DIR"
34+
echo "Cleanup complete."
35+
}
36+
37+
# Step 1: Create a sample audio file (WAV with silence)
38+
echo "Step 1: Creating sample audio file"
39+
python3 -c "
40+
import struct, wave
41+
with wave.open('$WORK_DIR/sample.wav', 'w') as w:
42+
w.setnchannels(1)
43+
w.setsampwidth(2)
44+
w.setframerate(16000)
45+
w.writeframes(struct.pack('<' + 'h' * 16000, *([0] * 16000)))
46+
"
47+
echo " Created sample.wav (1 second, 16kHz mono)"
48+
49+
# Step 2: Upload to S3
50+
echo "Step 2: Uploading to S3"
51+
if [ "$REGION" = "us-east-1" ]; then
52+
aws s3api create-bucket --bucket "$BUCKET_NAME" > /dev/null
53+
else
54+
aws s3api create-bucket --bucket "$BUCKET_NAME" \
55+
--create-bucket-configuration LocationConstraint="$REGION" > /dev/null
56+
fi
57+
aws s3 cp "$WORK_DIR/sample.wav" "s3://$BUCKET_NAME/sample.wav" --quiet
58+
echo " Uploaded to s3://$BUCKET_NAME/sample.wav"
59+
60+
# Step 3: Start transcription job
61+
echo "Step 3: Starting transcription job: $JOB_NAME"
62+
aws transcribe start-transcription-job \
63+
--transcription-job-name "$JOB_NAME" \
64+
--language-code en-US \
65+
--media "MediaFileUri=s3://$BUCKET_NAME/sample.wav" \
66+
--output-bucket-name "$BUCKET_NAME" \
67+
--query 'TranscriptionJob.{Name:TranscriptionJobName,Status:TranscriptionJobStatus}' --output table
68+
69+
# Step 4: Wait for completion
70+
echo "Step 4: Waiting for transcription to complete..."
71+
for i in $(seq 1 30); do
72+
STATUS=$(aws transcribe get-transcription-job --transcription-job-name "$JOB_NAME" \
73+
--query 'TranscriptionJob.TranscriptionJobStatus' --output text)
74+
echo " Status: $STATUS"
75+
[ "$STATUS" = "COMPLETED" ] || [ "$STATUS" = "FAILED" ] && break
76+
sleep 5
77+
done
78+
79+
# Step 5: Get results
80+
echo "Step 5: Transcription results"
81+
if [ "$STATUS" = "COMPLETED" ]; then
82+
RESULT_URI=$(aws transcribe get-transcription-job --transcription-job-name "$JOB_NAME" \
83+
--query 'TranscriptionJob.Transcript.TranscriptFileUri' --output text)
84+
echo " Result URI: $RESULT_URI"
85+
echo " (Audio was silence, so transcript will be empty or minimal)"
86+
else
87+
echo " Job status: $STATUS"
88+
fi
89+
90+
# Step 6: List jobs
91+
echo "Step 6: Listing transcription jobs"
92+
aws transcribe list-transcription-jobs --status COMPLETED \
93+
--query 'TranscriptionJobSummaries[:3].{Name:TranscriptionJobName,Status:TranscriptionJobStatus,Created:CreationTime}' --output table 2>/dev/null || \
94+
echo " No completed jobs"
95+
96+
echo ""
97+
echo "Tutorial complete."
98+
echo "Do you want to clean up all resources? (y/n): "
99+
read -r CHOICE
100+
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
101+
cleanup
102+
else
103+
echo "Manual cleanup:"
104+
echo " aws transcribe delete-transcription-job --transcription-job-name $JOB_NAME"
105+
echo " aws s3 rm s3://$BUCKET_NAME --recursive && aws s3 rb s3://$BUCKET_NAME"
106+
fi

tuts/118-amazon-lex-gs/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Lex: Create a chatbot
2+
3+
Create an Amazon Lex V2 chatbot with an IAM role, English locale, and a sample intent, then build the bot locale.
4+
5+
## Source
6+
7+
https://docs.aws.amazon.com/lexv2/latest/dg/getting-started.html
8+
9+
## Use case
10+
11+
- **ID**: lex/getting-started
12+
- **Level**: intermediate
13+
- **Core actions**: `lexv2-models:CreateBot`, `lexv2-models:CreateIntent`, `lexv2-models:CreateBotLocale`, `lexv2-models:BuildBotLocale`
14+
15+
## Steps
16+
17+
1. Create an IAM role for the bot
18+
2. Create a bot
19+
3. Create an English locale
20+
4. Create an OrderPizza intent with sample utterances
21+
5. Build the bot locale
22+
6. Describe the bot
23+
24+
## Resources created
25+
26+
| Resource | Type |
27+
|----------|------|
28+
| `tut-bot-<random>` | Lex V2 bot |
29+
| `lex-tut-role-<random>` | IAM role (with Polly policy) |
30+
31+
## Duration
32+
33+
~40 seconds
34+
35+
## Cost
36+
37+
No charge for bot creation. Lex charges per text or speech request when the bot processes conversations. This tutorial does not send conversation requests.
38+
39+
## Related docs
40+
41+
- [Getting started with Amazon Lex V2](https://docs.aws.amazon.com/lexv2/latest/dg/getting-started.html)
42+
- [Creating a bot](https://docs.aws.amazon.com/lexv2/latest/dg/build-create.html)
43+
- [Adding intents](https://docs.aws.amazon.com/lexv2/latest/dg/build-intents.html)
44+
- [Amazon Lex pricing](https://aws.amazon.com/lex/pricing/)
45+
46+
---
47+
48+
## Appendix
49+
50+
| Field | Value |
51+
|-------|-------|
52+
| Date | 2026-04-14 |
53+
| Script lines | 106 |
54+
| Exit code | 0 |
55+
| Runtime | 40s |
56+
| Steps | 6 |
57+
| Issues | Fixed bot/locale wait timing |
58+
| Version | v1 |

0 commit comments

Comments
 (0)