From 1dc6b4e8f7415106655ba257bfb6f76be6240d75 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Wed, 28 Oct 2020 18:24:20 -0300 Subject: [PATCH] adds showSpeakerLabel config parameter (#17) --- src/AwsTranscribe.ts | 14 ++++++++++++-- src/types.ts | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/AwsTranscribe.ts b/src/AwsTranscribe.ts index 09f8d8c..e80ac03 100644 --- a/src/AwsTranscribe.ts +++ b/src/AwsTranscribe.ts @@ -8,17 +8,23 @@ export class AwsTranscribe { private accessKeyId!: string private secretAccessKey!: string private sessionToken: string | undefined + private showSpeakerLabel?: boolean constructor(config?: ClientConfig) { // get from environment if config not provided this.setAccessKeyId(config?.accessKeyId || process.env.AWS_ACCESS_KEY_ID) this.setSecretAccessKey(config?.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY) this.setSessionToken(config?.sessionToken || process.env.AWS_SESSION_TOKEN) + this.setShowSpeakerLabel(config?.showSpeakerLabel || false) } private createPreSignedUrl(config: TranscribeStreamConfig) { - const { region, languageCode, sampleRate } = config + const { region, languageCode, sampleRate, showSpeakerLabel } = config const endpoint = "transcribestreaming." + region + ".amazonaws.com:8443" + let query = "language-code=" + languageCode + "&media-encoding=pcm&sample-rate=" + sampleRate + if (showSpeakerLabel) { + query += '&show-speaker-label=true' + } return createPresignedURL( "GET", @@ -33,7 +39,7 @@ export class AwsTranscribe { protocol: "wss", expires: 15, region: region, - query: "language-code=" + languageCode + "&media-encoding=pcm&sample-rate=" + sampleRate, + query: query } ) } @@ -58,4 +64,8 @@ export class AwsTranscribe { setSessionToken(sessionToken: string | undefined) { this.sessionToken = sessionToken } + + setShowSpeakerLabel(showSpeakerLabel: boolean | false) { + this.showSpeakerLabel = showSpeakerLabel + } } diff --git a/src/types.ts b/src/types.ts index c3facd8..2f14f2a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,12 +22,14 @@ export interface ClientConfig { accessKeyId?: string secretAccessKey?: string sessionToken?: string + showSpeakerLabel?: boolean } export interface TranscribeStreamConfig { region: AVAILABLE_REGIONS languageCode: LANGUAGES sampleRate: number + showSpeakerLabel?: boolean } export interface PresignedUrlHeaders {