File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 "version" : " 1.3.0" ,
44 "description" : " An SDK for the Deepgram automated speech recognition platform" ,
55 "main" : " dist/index.js" ,
6+ "browser" : " dist/browser/index.js" ,
67 "types" : " dist/index.d.ts" ,
78 "scripts" : {
89 "build" : " tsc -p ./" ,
Original file line number Diff line number Diff line change 1+ import { DefaultOptions } from "../constants" ;
2+
3+ import { Transcriber } from "./transcription" ;
4+
5+ export class Deepgram {
6+ private _apiUrl : string ;
7+ private _apiKey : string ;
8+
9+ transcription : Transcriber ;
10+
11+ constructor ( apiKey : string , apiUrl ?: string ) {
12+ this . _apiKey = apiKey ;
13+ this . _apiUrl = apiUrl || DefaultOptions . apiUrl ;
14+
15+ this . _validateOptions ( ) ;
16+
17+ this . transcription = new Transcriber ( this . _apiKey , this . _apiUrl ) ;
18+ }
19+
20+ /**
21+ * Ensures that the provided options were provided
22+ */
23+ private _validateOptions ( ) {
24+ if ( ! this . _apiKey || this . _apiKey . trim ( ) . length === 0 ) {
25+ throw new Error ( "DG: API key is required" ) ;
26+ }
27+
28+ if ( ! this . _apiUrl || this . _apiUrl . trim ( ) . length === 0 ) {
29+ throw new Error ( "DG: API url should be a valid url or not provided" ) ;
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ import {
2+ LiveTranscriptionOptions ,
3+ } from "../../types" ;
4+ import querystring from "querystring" ;
5+ export class Transcriber {
6+ constructor ( private _credentials : string , private _apiUrl : string ) { }
7+
8+ /**
9+ * Opens a websocket to Deepgram's API for live transcriptions
10+ * @param options Options to modify transcriptions
11+ */
12+ live ( options ?: LiveTranscriptionOptions ) : WebSocket {
13+ return new WebSocket (
14+ `wss://${ this . _apiUrl } /v1/listen?${ querystring . stringify ( options ) } ` ,
15+ [ "token" , this . _credentials ]
16+ ) ;
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments