Based on the knowledge sources provided, I can see that there are a few issues with your approach to connecting to Deepgram's live transcription service using WebSockets in React Native. Let me provide some guidance:
-
Deepgram API Connection:
Deepgram's live transcription API uses WebSockets, but it doesn't use Socket.io. Instead, you should use a standard WebSocket connection.
-
Connection URL:
The URL you're using is incorrect. According to the Deepgram API Reference (https://developers.deepgram.com/reference/listen-live), the correct WebSocket URL for live transcription is:
wss://api.deepgram.com/v1/listen
- Authentication:
The API key should be passed as a WebSocket subprotocol, not as a header.
Here's a corrected version of your code that should work with React Native:
import { createClient } from "@deepgram/sdk";
const API_KEY = 'YOUR_API_KEY';
const deepgram = createClient(API_KEY);
const live = deepgram.listen.live({
language: 'en-US',
model: 'nova-2',
smart_format: true
});
live.addListener('open', () => {
console.log('Connection opened.');
});
live.addListener('transcriptReceived', (transcription) => {
console.log('Transcript:', transcription);
});
live.addListener('error', (error) => {
console.error('Error:', error);
});
live.addListener('close', () => {
console.log('Connection closed.');
});
This code uses the Deepgram JavaScript SDK, which handles the WebSocket connection and authentication for you. It's a more reliable way to connect to Deepgram's services in a JavaScript environment like React Native.
Remember to replace 'YOUR_API_KEY' with your actual Deepgram API key.