Pre-Recorded Audio Transcription

The Deepgram has a package that allows you to request transcripts for pre-recorded audio. To request a transcript for a pre-recorded particular audio file, you’ll use one of the following functions depending on your audio source:

Pre-recorded Transcription Parameters

The input parameters for the three types of Prerecorded transcription (FromFile, FromStream, and FromURL) are geared toward the type of audio source.

ParameterTypeDescription
ctxContextGo Context
sourceFilePath, io.Reader, or URLProvides the source of audio to transcribe
optionsObjectParameters to filter requests. See below.

Sending a URL

Go
1ctx := context.Background()
2
3URL := "https://my-domain.com/files/MyAudio.mp3"
4
5options := PreRecordedTranscriptionOptions{
6 Punctuate: true,
7 Diarize: true,
8 Language: "en-US",
9}
10
11res, err := dg.FromURL(ctx, URL, options)

Sending a Local File

Go
1ctx := context.Background()
2
3filePath := "./MyAudio.mp3"
4
5options := PreRecordedTranscriptionOptions{
6 Punctuate: true,
7 Diarize: true,
8 Language: "en-US",
9}
10
11res, err := dg.FromFile(ctx, filePath, options)

NOTE: When attempting to access a file for transcription, make sure you have the correct file permissions for the user on the filesystem.

Sending an io.Reader

The io.Reader is a standard Go interface used primarily for streaming bytes from various sources. These sources could include files, HTTP(S) endpoints, etc. Anything that implements this interface can be passed to stream bytes for transcription.

Go
1ctx := context.Background()
2
3// myStream could be something like a file, HTTP stream, etc
4
5options := PreRecordedTranscriptionOptions{
6 Punctuate: true,
7 Diarize: true,
8 Language: "en-US",
9}
10
11res, err := dg.FromStream(ctx, myStream, options)

Pre-recorded Transcription Options

Additional transcription options can be provided for pre-recorded transcriptions. They are provided as an object as the second parameter of the transcription function. Each of these parameters maps to a feature in the Deepgram API. Reference the features documentation to learn the appropriate features for your request.

Pre-recorded Transcription Example Request

Using the transcription from a URL functionality above (FromURL), the required inputs are a Go Context, a URL, and additional transcription options. The output will be of type `PreRecordedResponse’, which contains the conversation transcription based on the options provided.

Go
1// context
2ctx := context.Background()
3
4//client
5c := client.NewRESTWithDefaults()
6dg := prerecorded.New(c)
7
8// transcription options
9options := PreRecordedTranscriptionOptions{
10 Punctuate: true,
11 Diarize: true,
12 Language: "en-US",
13}
14
15// send URL
16URL := "https://my-domain.com/files/my-conversation.mp3"
17res, err := dg.FromURL(ctx, URL, options)
18if err != nil {
19 log.Fatalf("FromURL failed. Err: %v\n", err)
20}
21
22// do something with the result
23log.Printf("result: %v\n", res)

Where To Find Additional Examples

The repository has a good collection of live audio transcription examples. You can find links to them in the README. Each example below will attempt to provide different options for transcribing an audio source.

For larger files, you might need to increase the default HTTP Timeout setting, which is 300 seconds (or 5 mins).

Built with