voice - some cleanup and 💄

This commit is contained in:
Benjamin Pasero
2023-08-17 12:13:14 +02:00
parent b96621b58c
commit e36739b66d
9 changed files with 30 additions and 31 deletions
+1 -2
View File
@@ -20,6 +20,5 @@ export const enum MarshalledId {
NotebookCellActionContext,
NotebookActionContext,
TestItemContext,
Date,
Float32Array
Date
}
+2 -2
View File
@@ -43,7 +43,7 @@ export interface IClientConnectionFilter {
* @returns `true` if the event was handled
* and should not be processed by the server.
*/
handled(e: MessageEvent): boolean;
handledClientConnection(e: MessageEvent): boolean;
}
/**
@@ -58,7 +58,7 @@ export class Server extends IPCServer {
const onCreateMessageChannel = new Emitter<MessagePortMain>();
process.parentPort.on('message', (e: MessageEvent) => {
if (filter?.handled(e)) {
if (filter?.handledClientConnection(e)) {
return;
}
@@ -35,6 +35,7 @@ export class VoiceTranscriber extends Disposable {
this._register(toDisposable(() => port.off('message', portHandler)));
port.start();
this._register(toDisposable(() => port.close()));
}));
}
}
@@ -117,7 +117,7 @@ import { NativeEnvironmentService } from 'vs/platform/environment/node/environme
import { IVoiceRecognitionService } from 'vs/platform/voiceRecognition/common/voiceRecognitionService';
import { VoiceRecognitionService } from 'vs/platform/voiceRecognition/node/voiceRecognitionService';
import { VoiceTranscriber } from 'vs/code/node/sharedProcess/contrib/voiceTranscriber';
import { RawSharedProcessConnection, SharedProcessLifecycle } from 'vs/platform/sharedProcess/common/sharedProcess';
import { SharedProcessRawConnection, SharedProcessLifecycle } from 'vs/platform/sharedProcess/common/sharedProcess';
class SharedProcessMain extends Disposable implements IClientConnectionFilter {
@@ -439,14 +439,14 @@ class SharedProcessMain extends Disposable implements IClientConnectionFilter {
});
}
handled(e: MessageEvent): boolean {
handledClientConnection(e: MessageEvent): boolean {
// This filter on message port messages will look for
// attempts of a window to connect raw to the shared
// process to handle these connections separate from
// our IPC based protocol.
if (e.data !== RawSharedProcessConnection.response) {
if (e.data !== SharedProcessRawConnection.response) {
return false;
}
@@ -9,12 +9,12 @@ export const SharedProcessLifecycle = {
initDone: 'vscode:shared-process->electron-main=init-done'
};
export const ChannelSharedProcessConnection = {
request: 'vscode:createChannelSharedProcessConnection',
response: 'vscode:createChannelSharedProcessConnectionResult'
export const SharedProcessChannelConnection = {
request: 'vscode:createSharedProcessChannelConnection',
response: 'vscode:createSharedProcessChannelConnectionResult'
};
export const RawSharedProcessConnection = {
request: 'vscode:createRawSharedProcessConnection',
response: 'vscode:createRawSharedProcessConnectionResult'
export const SharedProcessRawConnection = {
request: 'vscode:createSharedProcessRawConnection',
response: 'vscode:createSharedProcessRawConnectionResult'
};
@@ -18,7 +18,7 @@ import { UtilityProcess } from 'vs/platform/utilityProcess/electron-main/utility
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { parseSharedProcessDebugPort } from 'vs/platform/environment/node/environmentService';
import { assertIsDefined } from 'vs/base/common/types';
import { ChannelSharedProcessConnection, RawSharedProcessConnection, SharedProcessLifecycle } from 'vs/platform/sharedProcess/common/sharedProcess';
import { SharedProcessChannelConnection, SharedProcessRawConnection, SharedProcessLifecycle } from 'vs/platform/sharedProcess/common/sharedProcess';
export class SharedProcess extends Disposable {
@@ -43,10 +43,10 @@ export class SharedProcess extends Disposable {
private registerListeners(): void {
// Shared process channel connections from workbench windows
validatedIpcMain.on(ChannelSharedProcessConnection.request, (e, nonce: string) => this.onWindowConnection(e, nonce, ChannelSharedProcessConnection.response));
validatedIpcMain.on(SharedProcessChannelConnection.request, (e, nonce: string) => this.onWindowConnection(e, nonce, SharedProcessChannelConnection.response));
// Shared process raw connections from workbench windows
validatedIpcMain.on(RawSharedProcessConnection.request, (e, nonce: string) => this.onWindowConnection(e, nonce, RawSharedProcessConnection.response));
validatedIpcMain.on(SharedProcessRawConnection.request, (e, nonce: string) => this.onWindowConnection(e, nonce, SharedProcessRawConnection.response));
// Lifecycle
this._register(this.lifecycleMainService.onWillShutdown(() => this.onWillShutdown()));
@@ -8,7 +8,7 @@ import { IChannel, IServerChannel, getDelayedChannel } from 'vs/base/parts/ipc/c
import { ILogService } from 'vs/platform/log/common/log';
import { Disposable } from 'vs/base/common/lifecycle';
import { ISharedProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { ChannelSharedProcessConnection, RawSharedProcessConnection } from 'vs/platform/sharedProcess/common/sharedProcess';
import { SharedProcessChannelConnection, SharedProcessRawConnection } from 'vs/platform/sharedProcess/common/sharedProcess';
import { mark } from 'vs/base/common/performance';
import { Barrier, timeout } from 'vs/base/common/async';
import { acquirePort } from 'vs/base/parts/ipc/electron-sandbox/ipc.mp';
@@ -45,7 +45,7 @@ export class SharedProcessService extends Disposable implements ISharedProcessSe
// Acquire a message port connected to the shared process
mark('code/willConnectSharedProcess');
this.logService.trace('Renderer->SharedProcess#connect: before acquirePort');
const port = await acquirePort(ChannelSharedProcessConnection.request, ChannelSharedProcessConnection.response);
const port = await acquirePort(SharedProcessChannelConnection.request, SharedProcessChannelConnection.response);
mark('code/didConnectSharedProcess');
this.logService.trace('Renderer->SharedProcess#connect: connection established');
@@ -69,11 +69,11 @@ export class SharedProcessService extends Disposable implements ISharedProcessSe
async createRawConnection(): Promise<MessagePort> {
// Await initialization of the shared process
await this.connect();
await this.withSharedProcessConnection;
// Create a new port to the shared process
this.logService.trace('Renderer->SharedProcess#createRawConnection: before acquirePort');
const port = await acquirePort(RawSharedProcessConnection.request, RawSharedProcessConnection.response);
const port = await acquirePort(SharedProcessRawConnection.request, SharedProcessRawConnection.response);
this.logService.trace('Renderer->SharedProcess#createRawConnection: connection established');
return port;
@@ -13,7 +13,7 @@ class BufferedVoiceTranscriber extends AudioWorkletProcessor {
super();
this.channelCount = 1;
this.bufferTimespan = 4000;
this.bufferTimespan = 2000;
this.startTime = undefined;
this.allInputFloat32Array = undefined;
@@ -27,16 +27,16 @@ class BufferedVoiceTranscriber extends AudioWorkletProcessor {
// @ts-ignore
const port = this.port;
port.onmessage = event => {
if (event.data === 'vscode:transferPortToAudioWorklet') {
this.sharedProcessPort = event.ports[0];
if (event.data === 'vscode:transferSharedProcessConnection') {
this.sharedProcessConnection = event.ports[0];
this.sharedProcessPort.onmessage = event => {
this.sharedProcessConnection.onmessage = event => {
if (typeof event.data === 'string') {
port.postMessage(event.data);
}
};
this.sharedProcessPort.start();
this.sharedProcessConnection.start();
}
};
}
@@ -56,14 +56,13 @@ class BufferedVoiceTranscriber extends AudioWorkletProcessor {
this.currentInputFloat32Arrays.push(inputChannelData.slice(0));
if (Date.now() - this.startTime > this.bufferTimespan && this.sharedProcessPort) {
if (Date.now() - this.startTime > this.bufferTimespan && this.sharedProcessConnection) {
const currentInputFloat32Arrays = this.currentInputFloat32Arrays;
this.currentInputFloat32Arrays = [];
this.allInputFloat32Array = this.joinFloat32Arrays(this.allInputFloat32Array ? [this.allInputFloat32Array, ...currentInputFloat32Arrays] : currentInputFloat32Arrays);
// @ts-ignore
this.sharedProcessPort.postMessage(this.allInputFloat32Array);
this.sharedProcessConnection.postMessage(this.allInputFloat32Array);
this.startTime = Date.now();
}
@@ -50,10 +50,10 @@ class BufferedVoiceTranscriber extends AudioWorkletNode {
}
async start(token: CancellationToken): Promise<void> {
const rawSharedProcessConnection = await this.sharedProcessService.createRawConnection();
token.onCancellationRequested(() => rawSharedProcessConnection.close());
const sharedProcessConnection = await this.sharedProcessService.createRawConnection();
token.onCancellationRequested(() => sharedProcessConnection.close());
this.port.postMessage('vscode:transferPortToAudioWorklet', [rawSharedProcessConnection]);
this.port.postMessage('vscode:transferSharedProcessConnection', [sharedProcessConnection]);
}
}