Jay_11
08/11/2025, 4:25 PMKings_big💫
08/11/2025, 5:16 PMconst { createClient, LiveTranscriptionEvents } = require("@deepgram/sdk");
const EventEmitter = require("events");
const express = require("express");
const http = require("http");
class TranscriptionService extends EventEmitter {
constructor(apiKey) {
super();
this.deepgramClient = createClient(apiKey);
this.deepgramLive = this.deepgramClient.listen.live({
encoding: "linear16",
channels: 2,
sample_rate: 16000,
models: "nova-2",
smart_format: true,
interim_results: true,
});
this.deepgramLive.on(LiveTranscriptionEvents.Transcript, (event) => {
this.handleTranscript(event);
});
}
handleTranscript(transcription) {
const { channel_index, alternatives } = transcription.channel || {};
if (!alternatives || alternatives[0].confidence < 0.85) return; // Only process if confidence is above 85%
const text = alternatives[0].transcript.trim();
const channel = channel_index ? channel_index[0] : 0;
console.log(`Channel ${channel}: ${text}`);
}
}
// Express server setup
const app = express();
const server = http.createServer(app);
app.get("/", (req, res) => {
res.send("Custom Transcriber Service is running");
});
const apiKey = process.env.DEEPGRAM_API_KEY; // Your Deepgram API Key
const transcriptionService = new TranscriptionService(apiKey);
server.listen(3001, () => {
console.log('Server running at http://localhost:3001');
});
- Frontend Integration:
Use WebSocket to stream audio from the frontend to your backend server.
Ensure audio is captured in linear16 format, with a sample rate of 16000 Hz.
Ensure you have the following dependencies installed: @deepgram/sdk, express, and ws. For detailed implementation, refer to the Custom Transcriber documentation which explains setting up a server using Vapi with Deepgram.
Feel free to adjust the confidence threshold or logging level to fit your specific requirements.