@codingame/monaco-vscode-speech-service-override 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ function __decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function __param(paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ }
10
+
11
+ export { __decorate, __param };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-speech-service-override",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,6 +18,6 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@4.1.0"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.2"
22
22
  }
23
23
  }
package/speech.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
2
2
  import { ISpeechService } from 'vscode/vscode/vs/workbench/contrib/speech/common/speechService';
3
- import { SpeechService } from 'vscode/vscode/vs/workbench/contrib/speech/browser/speechService';
3
+ import { SpeechService } from './vscode/src/vs/workbench/contrib/speech/browser/speechService.js';
4
4
 
5
5
  function getServiceOverride() {
6
6
  return {
@@ -0,0 +1,273 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
+ import { firstOrDefault } from 'vscode/vscode/vs/base/common/arrays';
4
+ import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
5
+ import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
6
+ import { Disposable, toDisposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
7
+ import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
8
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
9
+ import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host';
10
+ import { DeferredPromise } from 'vscode/vscode/vs/base/common/async';
11
+ import { HasSpeechProvider, SpeechToTextInProgress, speechLanguageConfigToLanguage, SPEECH_LANGUAGE_CONFIG, SpeechToTextStatus, KeywordRecognitionStatus } from 'vscode/vscode/vs/workbench/contrib/speech/common/speechService';
12
+ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
13
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
14
+ import { AccessibilitySignal, IAccessibilitySignalService } from 'vscode/vscode/vs/platform/accessibilitySignal/browser/accessibilitySignalService';
15
+ import { ExtensionsRegistry } from 'vscode/vscode/vs/workbench/services/extensions/common/extensionsRegistry';
16
+ import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
17
+
18
+ const speechProvidersExtensionPoint = ExtensionsRegistry.registerExtensionPoint({
19
+ extensionPoint: 'speechProviders',
20
+ jsonSchema: {
21
+ description: ( localizeWithPath(
22
+ 'vs/workbench/contrib/speech/browser/speechService',
23
+ 'vscode.extension.contributes.speechProvider',
24
+ 'Contributes a Speech Provider'
25
+ )),
26
+ type: 'array',
27
+ items: {
28
+ additionalProperties: false,
29
+ type: 'object',
30
+ defaultSnippets: [{ body: { name: '', description: '' } }],
31
+ required: ['name'],
32
+ properties: {
33
+ name: {
34
+ description: ( localizeWithPath(
35
+ 'vs/workbench/contrib/speech/browser/speechService',
36
+ 'speechProviderName',
37
+ "Unique name for this Speech Provider."
38
+ )),
39
+ type: 'string'
40
+ },
41
+ description: {
42
+ description: ( localizeWithPath(
43
+ 'vs/workbench/contrib/speech/browser/speechService',
44
+ 'speechProviderDescription',
45
+ "A description of this Speech Provider, shown in the UI."
46
+ )),
47
+ type: 'string'
48
+ }
49
+ }
50
+ }
51
+ }
52
+ });
53
+ let SpeechService = class SpeechService extends Disposable {
54
+ get hasSpeechProvider() { return this.providerDescriptors.size > 0 || this.providers.size > 0; }
55
+ constructor(logService, contextKeyService, hostService, telemetryService, configurationService, accessibilitySignalService, extensionService) {
56
+ super();
57
+ this.logService = logService;
58
+ this.contextKeyService = contextKeyService;
59
+ this.hostService = hostService;
60
+ this.telemetryService = telemetryService;
61
+ this.configurationService = configurationService;
62
+ this.accessibilitySignalService = accessibilitySignalService;
63
+ this.extensionService = extensionService;
64
+ this._onDidChangeHasSpeechProvider = this._register(( new Emitter()));
65
+ this.onDidChangeHasSpeechProvider = this._onDidChangeHasSpeechProvider.event;
66
+ this.providers = ( new Map());
67
+ this.providerDescriptors = ( new Map());
68
+ this.hasSpeechProviderContext = HasSpeechProvider.bindTo(this.contextKeyService);
69
+ this._onDidStartSpeechToTextSession = this._register(( new Emitter()));
70
+ this.onDidStartSpeechToTextSession = this._onDidStartSpeechToTextSession.event;
71
+ this._onDidEndSpeechToTextSession = this._register(( new Emitter()));
72
+ this.onDidEndSpeechToTextSession = this._onDidEndSpeechToTextSession.event;
73
+ this._activeSpeechToTextSession = undefined;
74
+ this.speechToTextInProgress = SpeechToTextInProgress.bindTo(this.contextKeyService);
75
+ this._onDidStartKeywordRecognition = this._register(( new Emitter()));
76
+ this.onDidStartKeywordRecognition = this._onDidStartKeywordRecognition.event;
77
+ this._onDidEndKeywordRecognition = this._register(( new Emitter()));
78
+ this.onDidEndKeywordRecognition = this._onDidEndKeywordRecognition.event;
79
+ this._activeKeywordRecognitionSession = undefined;
80
+ this.handleAndRegisterSpeechExtensions();
81
+ }
82
+ handleAndRegisterSpeechExtensions() {
83
+ speechProvidersExtensionPoint.setHandler((extensions, delta) => {
84
+ const oldHasSpeechProvider = this.hasSpeechProvider;
85
+ for (const extension of delta.removed) {
86
+ for (const descriptor of extension.value) {
87
+ this.providerDescriptors.delete(descriptor.name);
88
+ }
89
+ }
90
+ for (const extension of delta.added) {
91
+ for (const descriptor of extension.value) {
92
+ this.providerDescriptors.set(descriptor.name, descriptor);
93
+ }
94
+ }
95
+ if (oldHasSpeechProvider !== this.hasSpeechProvider) {
96
+ this.handleHasSpeechProviderChange();
97
+ }
98
+ });
99
+ }
100
+ registerSpeechProvider(identifier, provider) {
101
+ if (( this.providers.has(identifier))) {
102
+ throw new Error(`Speech provider with identifier ${identifier} is already registered.`);
103
+ }
104
+ const oldHasSpeechProvider = this.hasSpeechProvider;
105
+ this.providers.set(identifier, provider);
106
+ if (oldHasSpeechProvider !== this.hasSpeechProvider) {
107
+ this.handleHasSpeechProviderChange();
108
+ }
109
+ return toDisposable(() => {
110
+ const oldHasSpeechProvider = this.hasSpeechProvider;
111
+ this.providers.delete(identifier);
112
+ if (oldHasSpeechProvider !== this.hasSpeechProvider) {
113
+ this.handleHasSpeechProviderChange();
114
+ }
115
+ });
116
+ }
117
+ handleHasSpeechProviderChange() {
118
+ this.hasSpeechProviderContext.set(this.hasSpeechProvider);
119
+ this._onDidChangeHasSpeechProvider.fire();
120
+ }
121
+ get hasActiveSpeechToTextSession() { return !!this._activeSpeechToTextSession; }
122
+ async createSpeechToTextSession(token, context = 'speech') {
123
+ const provider = await this.getProvider();
124
+ const language = speechLanguageConfigToLanguage(this.configurationService.getValue(SPEECH_LANGUAGE_CONFIG));
125
+ const session = this._activeSpeechToTextSession = provider.createSpeechToTextSession(token, typeof language === 'string' ? { language } : undefined);
126
+ const sessionStart = Date.now();
127
+ let sessionRecognized = false;
128
+ let sessionContentLength = 0;
129
+ const disposables = ( new DisposableStore());
130
+ const onSessionStoppedOrCanceled = () => {
131
+ if (session === this._activeSpeechToTextSession) {
132
+ this._activeSpeechToTextSession = undefined;
133
+ this.speechToTextInProgress.reset();
134
+ this.accessibilitySignalService.playSignal(AccessibilitySignal.voiceRecordingStopped, { allowManyInParallel: true });
135
+ this._onDidEndSpeechToTextSession.fire();
136
+ this.telemetryService.publicLog2('speechToTextSession', {
137
+ context,
138
+ sessionDuration: Date.now() - sessionStart,
139
+ sessionRecognized,
140
+ sessionContentLength,
141
+ sessionLanguage: language
142
+ });
143
+ }
144
+ disposables.dispose();
145
+ };
146
+ disposables.add(token.onCancellationRequested(() => onSessionStoppedOrCanceled()));
147
+ if (token.isCancellationRequested) {
148
+ onSessionStoppedOrCanceled();
149
+ }
150
+ disposables.add(session.onDidChange(e => {
151
+ switch (e.status) {
152
+ case SpeechToTextStatus.Started:
153
+ if (session === this._activeSpeechToTextSession) {
154
+ this.speechToTextInProgress.set(true);
155
+ this._onDidStartSpeechToTextSession.fire();
156
+ this.accessibilitySignalService.playSignal(AccessibilitySignal.voiceRecordingStarted);
157
+ }
158
+ break;
159
+ case SpeechToTextStatus.Recognizing:
160
+ sessionRecognized = true;
161
+ break;
162
+ case SpeechToTextStatus.Recognized:
163
+ if (typeof e.text === 'string') {
164
+ sessionContentLength += e.text.length;
165
+ }
166
+ break;
167
+ case SpeechToTextStatus.Stopped:
168
+ onSessionStoppedOrCanceled();
169
+ break;
170
+ }
171
+ }));
172
+ return session;
173
+ }
174
+ async getProvider() {
175
+ await this.extensionService.activateByEvent('onSpeech');
176
+ const provider = firstOrDefault(Array.from(( this.providers.values())));
177
+ if (!provider) {
178
+ throw new Error(`No Speech provider is registered.`);
179
+ }
180
+ else if (this.providers.size > 1) {
181
+ this.logService.warn(`Multiple speech providers registered. Picking first one: ${provider.metadata.displayName}`);
182
+ }
183
+ return provider;
184
+ }
185
+ get hasActiveKeywordRecognition() { return !!this._activeKeywordRecognitionSession; }
186
+ async recognizeKeyword(token) {
187
+ const result = ( new DeferredPromise());
188
+ await this.extensionService.activateByEvent('onSpeech');
189
+ const disposables = ( new DisposableStore());
190
+ disposables.add(token.onCancellationRequested(() => {
191
+ disposables.dispose();
192
+ result.complete(KeywordRecognitionStatus.Canceled);
193
+ }));
194
+ const recognizeKeywordDisposables = disposables.add(( new DisposableStore()));
195
+ let activeRecognizeKeywordSession = undefined;
196
+ const recognizeKeyword = () => {
197
+ recognizeKeywordDisposables.clear();
198
+ const cts = ( new CancellationTokenSource(token));
199
+ recognizeKeywordDisposables.add(toDisposable(() => cts.dispose(true)));
200
+ const currentRecognizeKeywordSession = activeRecognizeKeywordSession = this.doRecognizeKeyword(cts.token).then(status => {
201
+ if (currentRecognizeKeywordSession === activeRecognizeKeywordSession) {
202
+ result.complete(status);
203
+ }
204
+ }, error => {
205
+ if (currentRecognizeKeywordSession === activeRecognizeKeywordSession) {
206
+ result.error(error);
207
+ }
208
+ });
209
+ };
210
+ disposables.add(this.hostService.onDidChangeFocus(focused => {
211
+ if (!focused && activeRecognizeKeywordSession) {
212
+ recognizeKeywordDisposables.clear();
213
+ activeRecognizeKeywordSession = undefined;
214
+ }
215
+ else if (!activeRecognizeKeywordSession) {
216
+ recognizeKeyword();
217
+ }
218
+ }));
219
+ if (this.hostService.hasFocus) {
220
+ recognizeKeyword();
221
+ }
222
+ let status;
223
+ try {
224
+ status = await result.p;
225
+ }
226
+ finally {
227
+ disposables.dispose();
228
+ }
229
+ this.telemetryService.publicLog2('keywordRecognition', {
230
+ keywordRecognized: status === KeywordRecognitionStatus.Recognized
231
+ });
232
+ return status;
233
+ }
234
+ async doRecognizeKeyword(token) {
235
+ const provider = await this.getProvider();
236
+ const session = this._activeKeywordRecognitionSession = provider.createKeywordRecognitionSession(token);
237
+ this._onDidStartKeywordRecognition.fire();
238
+ const disposables = ( new DisposableStore());
239
+ const onSessionStoppedOrCanceled = () => {
240
+ if (session === this._activeKeywordRecognitionSession) {
241
+ this._activeKeywordRecognitionSession = undefined;
242
+ this._onDidEndKeywordRecognition.fire();
243
+ }
244
+ disposables.dispose();
245
+ };
246
+ disposables.add(token.onCancellationRequested(() => onSessionStoppedOrCanceled()));
247
+ if (token.isCancellationRequested) {
248
+ onSessionStoppedOrCanceled();
249
+ }
250
+ disposables.add(session.onDidChange(e => {
251
+ if (e.status === KeywordRecognitionStatus.Stopped) {
252
+ onSessionStoppedOrCanceled();
253
+ }
254
+ }));
255
+ try {
256
+ return (await Event.toPromise(session.onDidChange)).status;
257
+ }
258
+ finally {
259
+ onSessionStoppedOrCanceled();
260
+ }
261
+ }
262
+ };
263
+ SpeechService = ( __decorate([
264
+ ( __param(0, ILogService)),
265
+ ( __param(1, IContextKeyService)),
266
+ ( __param(2, IHostService)),
267
+ ( __param(3, ITelemetryService)),
268
+ ( __param(4, IConfigurationService)),
269
+ ( __param(5, IAccessibilitySignalService)),
270
+ ( __param(6, IExtensionService))
271
+ ], SpeechService));
272
+
273
+ export { SpeechService };