Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
adds showSpeakerLabel config parameter (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyfadeev authored Oct 28, 2020
1 parent ed630a0 commit 1dc6b4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/AwsTranscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
)
}
Expand All @@ -58,4 +64,8 @@ export class AwsTranscribe {
setSessionToken(sessionToken: string | undefined) {
this.sessionToken = sessionToken
}

setShowSpeakerLabel(showSpeakerLabel: boolean | false) {
this.showSpeakerLabel = showSpeakerLabel
}
}
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1dc6b4e

Please sign in to comment.