Skip to content

Commit d554465

Browse files
Initial documentation for Whisper Tutorial
1 parent 85ade05 commit d554465

File tree

1 file changed

+27
-45
lines changed

1 file changed

+27
-45
lines changed

src/content/docs/workers-ai/tutorials/build-a-workers-ai-whisper-with-chunking.mdx

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
updated: 2025-03-04
2+
updated: 2025-04-03
33
difficulty: Beginner
44
pcx_content_type: tutorial
55
title: Whisper-large-v3-turbo with Cloudflare Workers AI
@@ -13,21 +13,17 @@ In this tutorial you will learn how to:
1313
- **Handle large files:** Split large audio files into smaller chunks for processing, which helps overcome memory and execution time limitations.
1414
- **Deploy using Cloudflare Workers:** Create a scalable, low‑latency transcription pipeline in a serverless environment.
1515

16-
## Step 1: Create a New Cloudflare Worker Project
16+
## 1: Create a new Cloudflare Worker project
1717

1818
import { Render, PackageManagers, WranglerConfig } from "~/components";
1919

20-
This guide will instruct you through setting up and deploying your first Workers AI project. You will use [Workers](/workers/), a Workers AI binding, and a large language model (LLM) to deploy your first AI-powered application on the Cloudflare global network.
21-
2220
<Render file="prereqs" product="workers" />
2321

24-
## 1. Create a Worker project
25-
2622
You will create a new Worker project using the `create-cloudflare` CLI (C3). [C3](https://github.com/cloudflare/workers-sdk/tree/main/packages/create-cloudflare) is a command-line tool designed to help you set up and deploy new applications to Cloudflare.
2723

28-
Create a new project named `hello-ai` by running:
24+
Create a new project named `whisper-tutorial` by running:
2925

30-
<PackageManagers type="create" pkg="cloudflare@latest" args={"hello-ai"} />
26+
<PackageManagers type="create" pkg="cloudflare@latest" args={"whisper-tutorial"} />
3127

3228
Running `npm create cloudflare@latest` will prompt you to install the [`create-cloudflare` package](https://www.npmjs.com/package/create-cloudflare), and lead you through setup. C3 will also install [Wrangler](/workers/wrangler/), the Cloudflare Developer Platform CLI.
3329

@@ -41,15 +37,15 @@ Running `npm create cloudflare@latest` will prompt you to install the [`create-c
4137
}}
4238
/>
4339

44-
This will create a new `hello-ai` directory. Your new `hello-ai` directory will include:
40+
This will create a new `whisper-tutorial` directory. Your new `whisper-tutorial` directory will include:
4541

4642
- A `"Hello World"` [Worker](/workers/get-started/guide/#3-write-code) at `src/index.ts`.
4743
- A [`wrangler.jsonc`](/workers/wrangler/configuration/) configuration file.
4844

4945
Go to your application directory:
5046

5147
```sh
52-
cd hello-ai
48+
cd whisper-tutorial
5349
```
5450

5551
## 2. Connect your Worker to Workers AI
@@ -69,43 +65,31 @@ binding = "AI"
6965

7066
Your binding is [available in your Worker code](/workers/reference/migrate-to-module-workers/#bindings-in-es-modules-format) on [`env.AI`](/workers/runtime-apis/handlers/fetch/).
7167

72-
3. **Navigate to Your Project Directory:**
73-
74-
```
75-
cd whisper-tutorial
76-
```
77-
78-
## Step 2: Configure Wrangler
68+
## 3. Configure Wrangler
7969

80-
1. **Enable Node.js Compatibility:**
70+
In your wrangler file, add or update the following settings to enable Node.js APIs and polyfills (with a compatibility date of 2024‑09‑23 or later):
8171

82-
In your `wrangler.toml` file, add or update the following settings to enable Node.js APIs and polyfills (with a compatibility date of 2024‑09‑23 or later):
72+
<WranglerConfig>
8373

84-
```
74+
```toml title="wrangler.toml"
75+
compatibility_flags = [ "nodejs_compat" ]
8576
compatibility_date = "2024-09-23"
86-
nodejs_compat = true
8777
```
8878

89-
2. **Add the AI Binding:**
90-
91-
In the same file, add an AI binding so that you can use Cloudflare’s AI models in your Worker:
92-
93-
```
94-
[ai]
95-
binding = "AI"
96-
```
79+
</WranglerConfig>
9780

98-
## Step 3: Full TypeScript Code – Handling Large Audio Files with Chunking
81+
## 4. Handling large audio files with chunking
9982

10083
Replace the contents of your `src/index.ts` file with the following integrated code. This sample demonstrates how to:
10184

10285
- Extract an audio file URL from the query parameters.
10386
- Fetch the audio file while explicitly following redirects.
104-
- Split the audio file into smaller chunks (e.g., 1MB chunks).
105-
- Transcribe each chunk using the Whisperlarge‑v3‑turbo model via the Cloudflare AI binding.
87+
- Split the audio file into smaller chunks (such as, 1MB chunks).
88+
- Transcribe each chunk using the Whisper-large-v3-turbo model via the Cloudflare AI binding.
10689
- Return the aggregated transcription as plain text.
10790

108-
```
91+
```ts
92+
10993
import { Buffer } from "node:buffer";
11094
import type { Ai } from "workers-ai";
11195

@@ -197,21 +181,19 @@ export default {
197181
} satisfies ExportedHandler<Env>;
198182
```
199183

200-
---
201-
202-
## Step 4: Develop, Test, and Deploy
184+
## 5. Develop, test, and deploy
203185

204-
1. **Run the Worker Locally:**
186+
1. **Run the Worker locally:**
205187

206-
Use Wrangler's development mode to test your Worker locally:
188+
Use wrangler's development mode to test your Worker locally:
207189

208-
```
190+
```sh
209191
npx wrangler dev --remote
210192
```
211193

212-
Open your browser and visit [http://localhost:8787](http://localhost:8787), or use curl:
194+
Open your browser and go to [http://localhost:8787](http://localhost:8787), or use curl:
213195

214-
```
196+
```sh
215197
curl "http://localhost:8787?url=https://raw.githubusercontent.com/your-username/your-repo/main/your-audio-file.mp3"
216198
```
217199

@@ -223,15 +205,15 @@ curl "http://localhost:8787?url=https://raw.githubusercontent.com/your-username/
223205

224206
Once testing is complete, deploy your Worker with:
225207

226-
```
208+
```sh
227209
npx wrangler deploy
228210
```
229211

230-
3. **Test the Deployed Worker:**
212+
3. **Test the deployed Worker:**
231213

232214
After deployment, test your Worker by passing the audio URL as a query parameter:
233215

234-
```
216+
```sh
235217
curl "https://<your-worker-subdomain>.workers.dev?url=https://raw.githubusercontent.com/your-username/your-repo/main/your-audio-file.mp3"
236218
```
237219

@@ -241,4 +223,4 @@ If successful, the Worker will return a transcript of the audio file:
241223

242224
```sh
243225
This is the transcript of the audio...
244-
``
226+
```

0 commit comments

Comments
 (0)