Skip to content

Commit 69f274d

Browse files
Merge pull request #223 from scribear/feat/whisper-gear-chip-An
showing the current language
2 parents 407c2d9 + 219191d commit 69f274d

3 files changed

Lines changed: 383 additions & 308 deletions

File tree

src/components/api/returnAPI.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ export const returnRecogAPI = (api : ApiStatus, control : ControlStatus, azure :
5656
*/
5757

5858

59+
60+
function toWhisperCode(bcp47: string): string {
61+
// Accept "en", "en-US", etc. Return "en" for "en-US".
62+
if (!bcp47) return "en";
63+
const base = bcp47.split('-')[0].toLowerCase();
64+
const supported = new Set([
65+
'en','es','fr','de','it','pt','nl','sv','da','nb','fi','pl','cs','sk','sl','hr','sr','bg','ro',
66+
'hu','el','tr','ru','uk','ar','he','fa','ur','hi','bn','ta','te','ml','mr','gu','kn','pa',
67+
'id','ms','vi','th','zh','ja','ko'
68+
]);
69+
return supported.has(base) ? base : 'en';
70+
}
71+
5972
const createRecognizer = (currentApi: number, control: ControlStatus, azure: AzureStatus, streamTextConfig: StreamTextStatus, scribearServerStatus: ScribearServerStatus, selectedModelOption: SelectedOption, playbackStatus: PlaybackStatus): Recognizer => {
6073
if (currentApi === API.SCRIBEAR_SERVER) {
6174
return new ScribearRecognizer(scribearServerStatus, selectedModelOption, control.speechLanguage.CountryCode);
@@ -74,7 +87,11 @@ const createRecognizer = (currentApi: number, control: ControlStatus, azure: Azu
7487
// Placeholder - this is just WebSpeech for now
7588
return new StreamTextRecognizer(streamTextConfig.streamTextEvent, 'en', streamTextConfig.startPosition);
7689
} else if (currentApi === API.WHISPER) {
77-
return new WhisperRecognizer(null, control.speechLanguage.CountryCode, 4);
90+
return new WhisperRecognizer(
91+
null,
92+
toWhisperCode(control.speechLanguage.CountryCode),
93+
4
94+
);
7895
} else {
7996
throw new Error(`Unexpcted API_CODE: ${currentApi}`);
8097
}

0 commit comments

Comments
 (0)