File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const { createClient } = require ( "../../dist/main/index" ) ;
2+ const fs = require ( "fs" ) ;
3+ const path = require ( "path" ) ;
4+
5+ const transcribeUrl = async ( ) => {
6+ const deepgram = createClient ( process . env . DEEPGRAM_API_KEY ) ;
7+ const { result : token , error : tokenError } = await deepgram . auth . grantToken ( ) ;
8+ if ( tokenError ) {
9+ throw tokenError ;
10+ }
11+ console . log ( "Token" , token ) ;
12+
13+ console . log ( "Transcribing URL" , "https://dpgr.am/spacewalk.wav" ) ;
14+ deepgram . token = token . access_token ;
15+ const { result, error } = await deepgram . listen . prerecorded . transcribeUrl (
16+ {
17+ url : "https://dpgr.am/spacewalk.wav" ,
18+ } ,
19+ {
20+ model : "nova-3" ,
21+ keyterm : [ "spacewalk" ] ,
22+ }
23+ ) ;
24+
25+ if ( error ) console . error ( error ) ;
26+ if ( ! error ) console . dir ( result , { depth : 5 } ) ;
27+ } ;
28+
29+ transcribeUrl ( ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { DeepgramVersionError } from "./lib/errors";
22import {
33 AbstractClient ,
44 AgentLiveClient ,
5+ AuthRestClient ,
56 ListenClient ,
67 ManageClient ,
78 ReadClient ,
@@ -91,6 +92,10 @@ export default class DeepgramClient extends AbstractClient {
9192 return new AgentLiveClient ( this . options , endpoint ) ;
9293 }
9394
95+ get auth ( ) : AuthRestClient {
96+ return new AuthRestClient ( this . options ) ;
97+ }
98+
9499 /**
95100 * @deprecated
96101 * @see https://dpgr.am/js-v3
Original file line number Diff line number Diff line change 1+ export interface GrantTokenResponse {
2+ access_token : string ;
3+ expires_in : number ;
4+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ export * from "./GetProjectUsageRequestsSchema";
2626export * from "./GetProjectUsageSummaryResponse" ;
2727export * from "./GetProjectUsageSummarySchema" ;
2828export * from "./GetTokenDetailsResponse" ;
29+ export * from "./GrantTokenResponse" ;
2930export * from "./ListOnPremCredentialsResponse" ;
3031export * from "./LiveConfigOptions" ;
3132export * from "./LiveMetadataEvent" ;
Original file line number Diff line number Diff line change 1+ import { isDeepgramError } from "../lib/errors" ;
2+ import type { DeepgramResponse } from "../lib/types/DeepgramResponse" ;
3+ import type { GrantTokenResponse } from "../lib/types/GrantTokenResponse" ;
4+ import { AbstractRestClient } from "./AbstractRestClient" ;
5+
6+ export class AuthRestClient extends AbstractRestClient {
7+ public namespace : string = "auth" ;
8+
9+ public async grantToken (
10+ endpoint = ":version/auth/grant"
11+ ) : Promise < DeepgramResponse < GrantTokenResponse > > {
12+ try {
13+ const requestUrl = this . getRequestUrl ( endpoint ) ;
14+ const result : GrantTokenResponse = await this . post ( requestUrl , "" ) . then ( ( result ) =>
15+ result . json ( )
16+ ) ;
17+
18+ return { result, error : null } ;
19+ } catch ( error ) {
20+ if ( isDeepgramError ( error ) ) {
21+ return { result : null , error } ;
22+ }
23+
24+ throw error ;
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export * from "./AbstractClient";
22export * from "./AbstractLiveClient" ;
33export * from "./AbstractRestClient" ;
44export * from "./AgentLiveClient" ;
5+ export * from "./AuthRestClient" ;
56export * from "./ListenClient" ;
67export * from "./ListenLiveClient" ;
78export * from "./ListenRestClient" ;
You can’t perform that action at this time.
0 commit comments