Skip to content

Deepgram example task #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions docs/guides/examples/deepgram-transcribe-audio.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: "Transcribe audio using Deepgram"
sidebarTitle: "Deepgram audio transcription"
description: "This example will show you how to transcribe audio using Deepgram's speech recognition API with Trigger.dev."
---

## Overview

Transcribe audio using [Deepgram's](https://developers.deepgram.com/docs/introduction) speech recognition API.

## Key Features

- Transcribe audio from a URL
- Use the Nova 2 model for transcription

## Task code

```ts trigger/deepgramTranscription.ts
import { createClient } from "@deepgram/sdk";
import { logger, task } from "@trigger.dev/sdk/v3";

// Initialize the Deepgram client, using your Deepgram API key (you can find this in your Deepgram account settings).
const deepgram = createClient(process.env.DEEPGRAM_SECRET_KEY);

export const deepgramTranscription = task({
id: "deepgram-transcribe-audio",
run: async (payload: { audioUrl: string }) => {
const { audioUrl } = payload;

logger.log("Transcribing audio from URL", { audioUrl });

// Transcribe the audio using Deepgram
const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
{
url: audioUrl,
},
{
model: "nova-2", // Use the Nova 2 model for the transcription
smart_format: true, // Automatically format transcriptions to improve readability
diarize: true, // Recognize speaker changes and assign a speaker to each word in the transcript
}
);

if (error) {
logger.error("Failed to transcribe audio", { error });
throw error;
}

console.dir(result, { depth: null });

// Extract the transcription from the result
const transcription = result.results.channels[0].alternatives[0].paragraphs?.transcript;

logger.log(`Generated transcription: ${transcription}`);

return {
result,
};
},
});
```

## Testing your task

To test this task in the dashboard, you can use the following payload:

```json
{
"audioUrl": "https://dpgr.am/spacewalk.wav"
}
```
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"pages": [
"guides/examples/intro",
"guides/examples/dall-e3-generate-image",
"guides/examples/deepgram-transcribe-audio",
"guides/examples/ffmpeg-video-processing",
"guides/examples/open-ai-with-retrying",
"guides/examples/pdf-to-image",
Expand Down