-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ffb6f7
commit b7149bc
Showing
8 changed files
with
92 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# speech to input | ||
# speech to element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const README_URL = 'https://github.com/OvidijusParsiunas/speech-to-element'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {SpeechConfig} from 'microsoft-cognitiveservices-speech-sdk'; | ||
import {AzureOptions} from '../../types/options'; | ||
import {README_URL} from '../../consts/readme'; | ||
|
||
export class AzureSpeechConfig { | ||
private static getNewSpeechConfig(sdkSpeechConfig: typeof SpeechConfig, options: AzureOptions) { | ||
if (!options) { | ||
console.error(`Please provide subscription details - more info: ${README_URL}`); | ||
return null; | ||
} | ||
if (options.retrieveToken) { | ||
// here | ||
return null; | ||
} | ||
if (!options.subscriptionKey || !options.token) { | ||
console.error(`Please define a 'subscriptionKey' or 'token' property - more info: ${README_URL}`); | ||
return null; | ||
} | ||
if (!options.region) { | ||
console.error(`Please define a 'region' property - more info: ${README_URL}`); | ||
return null; | ||
} | ||
// WORK - error handling for incorrect key | ||
if (options.subscriptionKey) { | ||
return sdkSpeechConfig.fromSubscription(options.subscriptionKey, options.region); | ||
} | ||
if (options.token) { | ||
return sdkSpeechConfig.fromAuthorizationToken(options.token, options.region); | ||
} | ||
return null; | ||
} | ||
|
||
private static process(sdkSpeechConfig: SpeechConfig, options: AzureOptions) { | ||
if (options.language) sdkSpeechConfig.speechRecognitionLanguage = options.language; | ||
} | ||
|
||
public static get(sdkConfigType: typeof SpeechConfig, options: AzureOptions) { | ||
const speechConfig = AzureSpeechConfig.getNewSpeechConfig(sdkConfigType, options); | ||
if (speechConfig) AzureSpeechConfig.process(speechConfig, options); | ||
return speechConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Translations} from '../../types/options'; | ||
import {Translate} from '../../utils/translate'; | ||
|
||
export class AzureTranscript { | ||
public static extract(text: string, finalTranscript: string, isFinal: boolean, translations?: Translations) { | ||
if (translations) text = Translate.translate(text, translations); | ||
if (isFinal) { | ||
return {interimTranscript: '', finalTranscript: `${finalTranscript + text} `}; | ||
} | ||
return {interimTranscript: text, finalTranscript}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters