Skip to content

Commit 27e8f5c

Browse files
authored
Added deepgram transcription example (#1372)
1 parent fff1c0a commit 27e8f5c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Transcribe audio using Deepgram"
3+
sidebarTitle: "Deepgram audio transcription"
4+
description: "This example will show you how to transcribe audio using Deepgram's speech recognition API with Trigger.dev."
5+
---
6+
7+
## Overview
8+
9+
Transcribe audio using [Deepgram's](https://developers.deepgram.com/docs/introduction) speech recognition API.
10+
11+
## Key Features
12+
13+
- Transcribe audio from a URL
14+
- Use the Nova 2 model for transcription
15+
16+
## Task code
17+
18+
```ts trigger/deepgramTranscription.ts
19+
import { createClient } from "@deepgram/sdk";
20+
import { logger, task } from "@trigger.dev/sdk/v3";
21+
22+
// Initialize the Deepgram client, using your Deepgram API key (you can find this in your Deepgram account settings).
23+
const deepgram = createClient(process.env.DEEPGRAM_SECRET_KEY);
24+
25+
export const deepgramTranscription = task({
26+
id: "deepgram-transcribe-audio",
27+
run: async (payload: { audioUrl: string }) => {
28+
const { audioUrl } = payload;
29+
30+
logger.log("Transcribing audio from URL", { audioUrl });
31+
32+
// Transcribe the audio using Deepgram
33+
const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
34+
{
35+
url: audioUrl,
36+
},
37+
{
38+
model: "nova-2", // Use the Nova 2 model for the transcription
39+
smart_format: true, // Automatically format transcriptions to improve readability
40+
diarize: true, // Recognize speaker changes and assign a speaker to each word in the transcript
41+
}
42+
);
43+
44+
if (error) {
45+
logger.error("Failed to transcribe audio", { error });
46+
throw error;
47+
}
48+
49+
console.dir(result, { depth: null });
50+
51+
// Extract the transcription from the result
52+
const transcription = result.results.channels[0].alternatives[0].paragraphs?.transcript;
53+
54+
logger.log(`Generated transcription: ${transcription}`);
55+
56+
return {
57+
result,
58+
};
59+
},
60+
});
61+
```
62+
63+
## Testing your task
64+
65+
To test this task in the dashboard, you can use the following payload:
66+
67+
```json
68+
{
69+
"audioUrl": "https://dpgr.am/spacewalk.wav"
70+
}
71+
```

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
"pages": [
280280
"guides/examples/intro",
281281
"guides/examples/dall-e3-generate-image",
282+
"guides/examples/deepgram-transcribe-audio",
282283
"guides/examples/ffmpeg-video-processing",
283284
"guides/examples/open-ai-with-retrying",
284285
"guides/examples/pdf-to-image",

0 commit comments

Comments
 (0)