This post will cover how to set up Deepgram for live transcriptions in your Vue.js application. We'll set up Deepgram in a single HTML file with the Vue.js
include and no other dependencies.
Before We Start
You will need a free Deepgram API Key.
Setting Up a Vue Project With a Script Include
Create an index.html file and open it in a code editor. Set up a Vue project:
Get Microphone Data
This code will be written in the created() lifecycle method - meaning it will happen immediately.
Firstly, ask the user for access to their mic:
Next, plug the stream into a MediaRecorder so we can later access the raw data from the accessed microphone:
Remember that if you are creating Vue components, data must be a function that returns an object.
Connect to Deepgram
Create a button which will begin transcription. Trigger a new begin() method with it's clicked:
Take a moment to get a free Deepgram API Key before continuing.
Use the browser native WebSocket interface to connect to Deepgram's live transcription server. Store the WebSocket instance in data:
This WebSocket creates a 2-way connection with Deepgram. See the language=de in the URL? That's telling it you'll be speaking German. We have loads of supported languages to check out!
Send Data to Deepgram
Once the WebSocket connection is open, start sending mic data:
Receive Transcript Results
You are currently sending data through our persistent connection to Deepgram every 0.25 seconds. You will receive transcripts back nearly as often - it's time to write the handling code.
Refresh your browser, and you should see transcripts showing in your console.
Show Transcripts On Page
First, create a new transcripts property in data with an empty array:
Then, instead of logging transcripts, add them to this array:
Finally, update your HTML to display items from the array:
Your page should look like this once you've spoken a couple of phrases:
Wrapping Up
The final code looks like this:
This is the most simple implementation with Vue and is written for clarity over conciseness. If you want to learn more about Vue 3, including its setup() function and composables, then Sandra wrote an excellent tutorial series on Vue 3.
If you have questions, please feel free to message us on Twitter, @DeepgramDevs.
If you have any feedback about this post, or anything else around Deepgram, we'd love to hear from you. Please let us know in our GitHub discussions .
Unlock language AI at scale with an API call.
Get conversational intelligence with transcription and understanding on the world's best speech AI platform.