Skip to content

Commit 52cb4e4

Browse files
authored
voice - add config for language (microsoft#205908)
* voice - add config for language * . * . * .
1 parent 0cae183 commit 52cb4e4

File tree

7 files changed

+115
-10
lines changed

7 files changed

+115
-10
lines changed

src/vs/workbench/api/browser/mainThreadSpeech.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class MainThreadSpeech implements MainThreadSpeechShape {
4141

4242
const registration = this.speechService.registerSpeechProvider(identifier, {
4343
metadata,
44-
createSpeechToTextSession: token => {
44+
createSpeechToTextSession: (token, options) => {
4545
if (token.isCancellationRequested) {
4646
return {
4747
onDidChange: Event.None
@@ -51,7 +51,7 @@ export class MainThreadSpeech implements MainThreadSpeechShape {
5151
const disposables = new DisposableStore();
5252
const session = Math.random();
5353

54-
this.proxy.$createSpeechToTextSession(handle, session);
54+
this.proxy.$createSpeechToTextSession(handle, session, options?.language);
5555

5656
const onDidChange = disposables.add(new Emitter<ISpeechToTextEvent>());
5757
this.speechToTextSessions.set(session, { onDidChange });

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ export interface MainThreadSpeechShape extends IDisposable {
11711171
}
11721172

11731173
export interface ExtHostSpeechShape {
1174-
$createSpeechToTextSession(handle: number, session: number): Promise<void>;
1174+
$createSpeechToTextSession(handle: number, session: number, language?: string): Promise<void>;
11751175
$cancelSpeechToTextSession(session: number): Promise<void>;
11761176

11771177
$createKeywordRecognitionSession(handle: number, session: number): Promise<void>;

src/vs/workbench/api/common/extHostSpeech.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ExtHostSpeech implements ExtHostSpeechShape {
2424
this.proxy = mainContext.getProxy(MainContext.MainThreadSpeech);
2525
}
2626

27-
async $createSpeechToTextSession(handle: number, session: number): Promise<void> {
27+
async $createSpeechToTextSession(handle: number, session: number, language?: string): Promise<void> {
2828
const provider = this.providers.get(handle);
2929
if (!provider) {
3030
return;
@@ -35,7 +35,7 @@ export class ExtHostSpeech implements ExtHostSpeechShape {
3535
const cts = new CancellationTokenSource();
3636
this.sessions.set(session, cts);
3737

38-
const speechToTextSession = disposables.add(provider.provideSpeechToTextSession(cts.token));
38+
const speechToTextSession = disposables.add(provider.provideSpeechToTextSession(cts.token, language ? { language } : undefined));
3939
disposables.add(speechToTextSession.onDidChange(e => {
4040
if (cts.token.isCancellationRequested) {
4141
return;

src/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration.ts

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,11 @@ export function registerAccessibilityConfiguration() {
660660
}
661661

662662
export const enum AccessibilityVoiceSettingId {
663-
SpeechTimeout = 'accessibility.voice.speechTimeout'
663+
SpeechTimeout = 'accessibility.voice.speechTimeout',
664+
SpeechLanguage = 'accessibility.voice.speechLanguage'
664665
}
665666
export const SpeechTimeoutDefault = 1200;
667+
const SpeechLanguageDefault = 'en-US';
666668

667669
export class DynamicSpeechAccessibilityConfiguration extends Disposable implements IWorkbenchContribution {
668670

@@ -681,6 +683,11 @@ export class DynamicSpeechAccessibilityConfiguration extends Disposable implemen
681683
return; // these settings require a speech provider
682684
}
683685

686+
const languages = this.getLanguages();
687+
const languagesSorted = Object.keys(languages).sort((langA, langB) => {
688+
return languages[langA].name.localeCompare(languages[langB].name);
689+
});
690+
684691
const registry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
685692
registry.registerConfiguration({
686693
...accessibilityConfigurationNodeBase,
@@ -691,11 +698,98 @@ export class DynamicSpeechAccessibilityConfiguration extends Disposable implemen
691698
'default': SpeechTimeoutDefault,
692699
'minimum': 0,
693700
'tags': ['accessibility']
701+
},
702+
[AccessibilityVoiceSettingId.SpeechLanguage]: {
703+
'markdownDescription': localize('voice.speechLanguage', "The language that voice speech recognition should recognize."),
704+
'type': 'string',
705+
'enum': languagesSorted,
706+
'default': SpeechLanguageDefault,
707+
'tags': ['accessibility'],
708+
'enumDescriptions': languagesSorted.map(key => languages[key].name),
709+
'enumItemLabels': languagesSorted.map(key => languages[key].name)
694710
}
695711
}
696712
});
697713
}
714+
715+
private getLanguages(): { [locale: string]: { name: string } } {
716+
return {
717+
['de-DE']: {
718+
name: localize('speechLanguage.de-DE', "German (Germany)")
719+
},
720+
['en-AU']: {
721+
name: localize('speechLanguage.en-AU', "English (Australia)")
722+
},
723+
['en-CA']: {
724+
name: localize('speechLanguage.en-CA', "English (Canada)")
725+
},
726+
['en-GB']: {
727+
name: localize('speechLanguage.en-GB', "English (United Kingdom)")
728+
},
729+
['en-IE']: {
730+
name: localize('speechLanguage.en-IE', "English (Ireland)")
731+
},
732+
['en-IN']: {
733+
name: localize('speechLanguage.en-IN', "English (India)")
734+
},
735+
['en-NZ']: {
736+
name: localize('speechLanguage.en-NZ', "English (New Zealand)")
737+
},
738+
[SpeechLanguageDefault]: {
739+
name: localize('speechLanguage.en-US', "English (United States)")
740+
},
741+
['es-ES']: {
742+
name: localize('speechLanguage.es-ES', "Spanish (Spain)")
743+
},
744+
['es-MX']: {
745+
name: localize('speechLanguage.es-MX', "Spanish (Mexico)")
746+
},
747+
['fr-CA']: {
748+
name: localize('speechLanguage.fr-CA', "French (Canada)")
749+
},
750+
['fr-FR']: {
751+
name: localize('speechLanguage.fr-FR', "French (France)")
752+
},
753+
['hi-IN']: {
754+
name: localize('speechLanguage.hi-IN', "Hindi (India)")
755+
},
756+
['it-IT']: {
757+
name: localize('speechLanguage.it-IT', "Italian (Italy)")
758+
},
759+
['ja-JP']: {
760+
name: localize('speechLanguage.ja-JP', "Japanese (Japan)")
761+
},
762+
['ko-KR']: {
763+
name: localize('speechLanguage.ko-KR', "Korean (South Korea)")
764+
},
765+
['nl-NL']: {
766+
name: localize('speechLanguage.nl-NL', "Dutch (Netherlands)")
767+
},
768+
['pt-BR']: {
769+
name: localize('speechLanguage.pt-BR', "Portuguese (Brazil)")
770+
},
771+
['ru-RU']: {
772+
name: localize('speechLanguage.ru-RU', "Russian (Russia)")
773+
},
774+
['sv-SE']: {
775+
name: localize('speechLanguage.sv-SE', "Swedish (Sweden)")
776+
},
777+
['tr-TR']: {
778+
name: localize('speechLanguage.tr-TR', "Turkish (Turkey)")
779+
},
780+
['zh-CN']: {
781+
name: localize('speechLanguage.zh-CN', "Chinese (Simplified, China)")
782+
},
783+
['zh-HK']: {
784+
name: localize('speechLanguage.zh-HK', "Chinese (Traditional, Hong Kong)")
785+
},
786+
['zh-TW']: {
787+
name: localize('speechLanguage.zh-TW', "Chinese (Traditional, Taiwan)")
788+
}
789+
};
790+
}
698791
}
792+
699793
Registry.as<IConfigurationMigrationRegistry>(WorkbenchExtensions.ConfigurationMigration)
700794
.registerConfigurationMigrations([{
701795
key: 'audioCues.volume',

src/vs/workbench/contrib/speech/browser/speechService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
1313
import { DeferredPromise } from 'vs/base/common/async';
1414
import { ISpeechService, ISpeechProvider, HasSpeechProvider, ISpeechToTextSession, SpeechToTextInProgress, IKeywordRecognitionSession, KeywordRecognitionStatus, SpeechToTextStatus } from 'vs/workbench/contrib/speech/common/speechService';
1515
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
16+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1617

1718
export class SpeechService extends Disposable implements ISpeechService {
1819

@@ -34,7 +35,8 @@ export class SpeechService extends Disposable implements ISpeechService {
3435
@ILogService private readonly logService: ILogService,
3536
@IContextKeyService private readonly contextKeyService: IContextKeyService,
3637
@IHostService private readonly hostService: IHostService,
37-
@ITelemetryService private readonly telemetryService: ITelemetryService
38+
@ITelemetryService private readonly telemetryService: ITelemetryService,
39+
@IConfigurationService private readonly configurationService: IConfigurationService
3840
) {
3941
super();
4042
}
@@ -78,7 +80,8 @@ export class SpeechService extends Disposable implements ISpeechService {
7880
this.logService.warn(`Multiple speech providers registered. Picking first one: ${provider.metadata.displayName}`);
7981
}
8082

81-
const session = this._activeSpeechToTextSession = provider.createSpeechToTextSession(token);
83+
const language = this.configurationService.getValue<string>('accessibility.voice.speechLanguage');
84+
const session = this._activeSpeechToTextSession = provider.createSpeechToTextSession(token, typeof language === 'string' ? { language } : undefined);
8285

8386
const sessionStart = Date.now();
8487
let sessionRecognized = false;

src/vs/workbench/contrib/speech/common/speechService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ export interface IKeywordRecognitionSession {
5252
readonly onDidChange: Event<IKeywordRecognitionEvent>;
5353
}
5454

55+
export interface ISpeechToTextSessionOptions {
56+
readonly language?: string;
57+
}
58+
5559
export interface ISpeechProvider {
5660
readonly metadata: ISpeechProviderMetadata;
5761

58-
createSpeechToTextSession(token: CancellationToken): ISpeechToTextSession;
62+
createSpeechToTextSession(token: CancellationToken, options?: ISpeechToTextSessionOptions): ISpeechToTextSession;
5963
createKeywordRecognitionSession(token: CancellationToken): IKeywordRecognitionSession;
6064
}
6165

src/vscode-dts/vscode.proposed.speech.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ declare module 'vscode' {
77

88
// todo@bpasero work in progress speech API
99

10+
export interface SpeechToTextOptions {
11+
readonly language?: string;
12+
}
13+
1014
export enum SpeechToTextStatus {
1115
Started = 1,
1216
Recognizing = 2,
@@ -38,7 +42,7 @@ declare module 'vscode' {
3842
}
3943

4044
export interface SpeechProvider {
41-
provideSpeechToTextSession(token: CancellationToken): SpeechToTextSession;
45+
provideSpeechToTextSession(token: CancellationToken, options?: SpeechToTextOptions): SpeechToTextSession;
4246
provideKeywordRecognitionSession(token: CancellationToken): KeywordRecognitionSession;
4347
}
4448

0 commit comments

Comments
 (0)