Pre-Recorded Audio Transcription

The Deepgram Prerecorded Client has a prerecorded API 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

ctx := context.Background()

URL := "https://my-domain.com/files/MyAudio.mp3"

options := PreRecordedTranscriptionOptions{
	Punctuate:  true,
	Diarize:    true,
	Language:   "en-US",
}

res, err := dg.FromURL(ctx, URL, options)

Sending a Local File

ctx := context.Background()

filePath := "./MyAudio.mp3"

options := PreRecordedTranscriptionOptions{
	Punctuate:  true,
	Diarize:    true,
	Language:   "en-US",
}

res, 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.

ctx := context.Background()

// myStream could be something like a file, HTTP stream, etc

options := PreRecordedTranscriptionOptions{
	Punctuate:  true,
	Diarize:    true,
	Language:   "en-US",
}

res, 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.preRecorded 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.

// context
ctx := context.Background()

//client
c := client.NewWithDefaults()
dg := prerecorded.New(c)

// transcription options
options := PreRecordedTranscriptionOptions{
	Punctuate:  true,
	Diarize:    true,
	Language:   "en-US",
}	

// send URL
URL := "https://my-domain.com/files/my-conversation.mp3"
res, err := dg.FromURL(ctx, URL, options)
if err != nil {
	log.Fatalf("FromURL failed. Err: %v\n", err)
}

// do something with the result
log.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 on how you might transcribe an audio source.