Live Streaming Audio Transcription
The Deepgram has a package that allows you to request transcripts for real-time streaming audio. To request a transcript for a live streaming audio, you’ll use one of the following functions depending on your audio source:
Live Transcription Parameters
The input parameters for Live/Streaming transcription consist of two parts:
- What options do you want to transcribe the live audio stream
- Obtaining notifications for transcription events
Options are provided via the LiveTranscriptionOptions struct to be provided in the NewWebSocket
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.
The Callback Interface defines what you want to do with the transcription as it happens in real-time. You can receive notifications of two events: Message/Transcriptions and Metadata.
Initiating a Connection
Creating a Live Client can be done by using the following code:
Define Options for the Client
ClientOptions
defines any options for the client. When creating a new Deepgram LiveTranscription
client, pass in the optional config options.
A common config option would be to enable the KeepAlive option with EnableKeepAlive
:
Read more about KeepAlive in this comprehensive guide.
Events
The live transcription client fires the following events:
Implementing an Event Callback Listener
To receive transcription events, the LiveMessageCallback interface needs to be implemented as defined below:
Sending Data/Streams
Go is a very stream-oriented language. Many helpful interfaces are provided natively and, if utilized correctly, dramatically simplify the implementation of your client. The Live Client implements the io.Writer interface, which means one can read data from your audio source and push it into the Deepgram Client.
What this ends up looking like on the client side is:
Closing the Connection
When finished with the Live stream, you can safely close the stream by calling the following function on the client.
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 attempts to provide different options for trancribing. Each example below will attempt to provide different options on how you might transcribe a live-streaming source.
- From a Microphone - examples/streaming/microphone
- From a HTTP Endpoint - examples/streaming/http