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

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-speech-service-override",
3
- "version": "3.2.3",
3
+ "version": "4.1.0",
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@3.2.3"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.0"
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/src/vs/workbench/contrib/speech/browser/speechService.js';
3
+ import { SpeechService } from 'vscode/vscode/vs/workbench/contrib/speech/browser/speechService';
4
4
 
5
5
  function getServiceOverride() {
6
6
  return {
@@ -1,11 +0,0 @@
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 };
@@ -1,197 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { firstOrDefault } from 'vscode/vscode/vs/base/common/arrays';
3
- import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
4
- import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
5
- import { Disposable, toDisposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
6
- import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
7
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
8
- import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host';
9
- import { DeferredPromise } from 'vscode/vscode/vs/base/common/async';
10
- import { HasSpeechProvider, SpeechToTextInProgress, SpeechToTextStatus, KeywordRecognitionStatus } from 'vscode/vscode/vs/workbench/contrib/speech/common/speechService';
11
- import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
12
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
13
-
14
- let SpeechService = class SpeechService extends Disposable {
15
- get hasSpeechProvider() { return this.providers.size > 0; }
16
- constructor(logService, contextKeyService, hostService, telemetryService, configurationService) {
17
- super();
18
- this.logService = logService;
19
- this.contextKeyService = contextKeyService;
20
- this.hostService = hostService;
21
- this.telemetryService = telemetryService;
22
- this.configurationService = configurationService;
23
- this._onDidRegisterSpeechProvider = this._register(( new Emitter()));
24
- this.onDidRegisterSpeechProvider = this._onDidRegisterSpeechProvider.event;
25
- this._onDidUnregisterSpeechProvider = this._register(( new Emitter()));
26
- this.onDidUnregisterSpeechProvider = this._onDidUnregisterSpeechProvider.event;
27
- this.providers = ( new Map());
28
- this.hasSpeechProviderContext = HasSpeechProvider.bindTo(this.contextKeyService);
29
- this._onDidStartSpeechToTextSession = this._register(( new Emitter()));
30
- this.onDidStartSpeechToTextSession = this._onDidStartSpeechToTextSession.event;
31
- this._onDidEndSpeechToTextSession = this._register(( new Emitter()));
32
- this.onDidEndSpeechToTextSession = this._onDidEndSpeechToTextSession.event;
33
- this._activeSpeechToTextSession = undefined;
34
- this.speechToTextInProgress = SpeechToTextInProgress.bindTo(this.contextKeyService);
35
- this._onDidStartKeywordRecognition = this._register(( new Emitter()));
36
- this.onDidStartKeywordRecognition = this._onDidStartKeywordRecognition.event;
37
- this._onDidEndKeywordRecognition = this._register(( new Emitter()));
38
- this.onDidEndKeywordRecognition = this._onDidEndKeywordRecognition.event;
39
- this._activeKeywordRecognitionSession = undefined;
40
- }
41
- registerSpeechProvider(identifier, provider) {
42
- if (( this.providers.has(identifier))) {
43
- throw new Error(`Speech provider with identifier ${identifier} is already registered.`);
44
- }
45
- this.providers.set(identifier, provider);
46
- this.hasSpeechProviderContext.set(true);
47
- this._onDidRegisterSpeechProvider.fire(provider);
48
- return toDisposable(() => {
49
- this.providers.delete(identifier);
50
- this._onDidUnregisterSpeechProvider.fire(provider);
51
- if (this.providers.size === 0) {
52
- this.hasSpeechProviderContext.set(false);
53
- }
54
- });
55
- }
56
- get hasActiveSpeechToTextSession() { return !!this._activeSpeechToTextSession; }
57
- createSpeechToTextSession(token, context = 'speech') {
58
- const provider = firstOrDefault(Array.from(( this.providers.values())));
59
- if (!provider) {
60
- throw new Error(`No Speech provider is registered.`);
61
- }
62
- else if (this.providers.size > 1) {
63
- this.logService.warn(`Multiple speech providers registered. Picking first one: ${provider.metadata.displayName}`);
64
- }
65
- const language = this.configurationService.getValue('accessibility.voice.speechLanguage');
66
- const session = this._activeSpeechToTextSession = provider.createSpeechToTextSession(token, typeof language === 'string' ? { language } : undefined);
67
- const sessionStart = Date.now();
68
- let sessionRecognized = false;
69
- const disposables = ( new DisposableStore());
70
- const onSessionStoppedOrCanceled = () => {
71
- if (session === this._activeSpeechToTextSession) {
72
- this._activeSpeechToTextSession = undefined;
73
- this.speechToTextInProgress.reset();
74
- this._onDidEndSpeechToTextSession.fire();
75
- this.telemetryService.publicLog2('speechToTextSession', {
76
- context,
77
- duration: Date.now() - sessionStart,
78
- recognized: sessionRecognized
79
- });
80
- }
81
- disposables.dispose();
82
- };
83
- disposables.add(token.onCancellationRequested(() => onSessionStoppedOrCanceled()));
84
- if (token.isCancellationRequested) {
85
- onSessionStoppedOrCanceled();
86
- }
87
- disposables.add(session.onDidChange(e => {
88
- switch (e.status) {
89
- case SpeechToTextStatus.Started:
90
- if (session === this._activeSpeechToTextSession) {
91
- this.speechToTextInProgress.set(true);
92
- this._onDidStartSpeechToTextSession.fire();
93
- }
94
- break;
95
- case SpeechToTextStatus.Recognizing:
96
- case SpeechToTextStatus.Recognized:
97
- sessionRecognized = true;
98
- break;
99
- case SpeechToTextStatus.Stopped:
100
- onSessionStoppedOrCanceled();
101
- break;
102
- }
103
- }));
104
- return session;
105
- }
106
- get hasActiveKeywordRecognition() { return !!this._activeKeywordRecognitionSession; }
107
- async recognizeKeyword(token) {
108
- const result = ( new DeferredPromise());
109
- const disposables = ( new DisposableStore());
110
- disposables.add(token.onCancellationRequested(() => {
111
- disposables.dispose();
112
- result.complete(KeywordRecognitionStatus.Canceled);
113
- }));
114
- const recognizeKeywordDisposables = disposables.add(( new DisposableStore()));
115
- let activeRecognizeKeywordSession = undefined;
116
- const recognizeKeyword = () => {
117
- recognizeKeywordDisposables.clear();
118
- const cts = ( new CancellationTokenSource(token));
119
- recognizeKeywordDisposables.add(toDisposable(() => cts.dispose(true)));
120
- const currentRecognizeKeywordSession = activeRecognizeKeywordSession = this.doRecognizeKeyword(cts.token).then(status => {
121
- if (currentRecognizeKeywordSession === activeRecognizeKeywordSession) {
122
- result.complete(status);
123
- }
124
- }, error => {
125
- if (currentRecognizeKeywordSession === activeRecognizeKeywordSession) {
126
- result.error(error);
127
- }
128
- });
129
- };
130
- disposables.add(this.hostService.onDidChangeFocus(focused => {
131
- if (!focused && activeRecognizeKeywordSession) {
132
- recognizeKeywordDisposables.clear();
133
- activeRecognizeKeywordSession = undefined;
134
- }
135
- else if (!activeRecognizeKeywordSession) {
136
- recognizeKeyword();
137
- }
138
- }));
139
- if (this.hostService.hasFocus) {
140
- recognizeKeyword();
141
- }
142
- let status;
143
- try {
144
- status = await result.p;
145
- }
146
- finally {
147
- disposables.dispose();
148
- }
149
- this.telemetryService.publicLog2('keywordRecognition', {
150
- recognized: status === KeywordRecognitionStatus.Recognized
151
- });
152
- return status;
153
- }
154
- async doRecognizeKeyword(token) {
155
- const provider = firstOrDefault(Array.from(( this.providers.values())));
156
- if (!provider) {
157
- throw new Error(`No Speech provider is registered.`);
158
- }
159
- else if (this.providers.size > 1) {
160
- this.logService.warn(`Multiple speech providers registered. Picking first one: ${provider.metadata.displayName}`);
161
- }
162
- const session = this._activeKeywordRecognitionSession = provider.createKeywordRecognitionSession(token);
163
- this._onDidStartKeywordRecognition.fire();
164
- const disposables = ( new DisposableStore());
165
- const onSessionStoppedOrCanceled = () => {
166
- if (session === this._activeKeywordRecognitionSession) {
167
- this._activeKeywordRecognitionSession = undefined;
168
- this._onDidEndKeywordRecognition.fire();
169
- }
170
- disposables.dispose();
171
- };
172
- disposables.add(token.onCancellationRequested(() => onSessionStoppedOrCanceled()));
173
- if (token.isCancellationRequested) {
174
- onSessionStoppedOrCanceled();
175
- }
176
- disposables.add(session.onDidChange(e => {
177
- if (e.status === KeywordRecognitionStatus.Stopped) {
178
- onSessionStoppedOrCanceled();
179
- }
180
- }));
181
- try {
182
- return (await Event.toPromise(session.onDidChange)).status;
183
- }
184
- finally {
185
- onSessionStoppedOrCanceled();
186
- }
187
- }
188
- };
189
- SpeechService = ( __decorate([
190
- ( __param(0, ILogService)),
191
- ( __param(1, IContextKeyService)),
192
- ( __param(2, IHostService)),
193
- ( __param(3, ITelemetryService)),
194
- ( __param(4, IConfigurationService))
195
- ], SpeechService));
196
-
197
- export { SpeechService };