diff --git a/src/vs/code/node/sharedProcess/contrib/voiceTranscriber.ts b/src/vs/code/node/sharedProcess/contrib/voiceTranscriber.ts index d9a9979dcb3..210570ef952 100644 --- a/src/vs/code/node/sharedProcess/contrib/voiceTranscriber.ts +++ b/src/vs/code/node/sharedProcess/contrib/voiceTranscriber.ts @@ -32,6 +32,8 @@ export class VoiceTranscriptionManager extends Disposable { class VoiceTranscriber extends Disposable { + private static MAX_DATA_LENGTH = 30 /* seconds */ * 16000 /* sampling rate */ * 16 /* bith depth */ * 1 /* channels */ / 8; + private readonly transcriptionSequentializer = new TaskSequentializer(); private requests = 0; @@ -81,7 +83,14 @@ class VoiceTranscriber extends Disposable { } } - this.data = this.joinFloat32Arrays(this.data ? [this.data, ...newData] : newData); + const dataCandidate = this.joinFloat32Arrays(this.data ? [this.data, ...newData] : newData); + + if (dataCandidate.length > VoiceTranscriber.MAX_DATA_LENGTH) { + this.logService.warn(`[voice] transcriber: refusing to accept more than 30s of audio data`); + return; + } + + this.data = dataCandidate; const data = this.data.slice(0); this.requests++; diff --git a/src/vs/platform/voiceRecognition/node/voiceRecognitionService.ts b/src/vs/platform/voiceRecognition/node/voiceRecognitionService.ts index ca569eae27e..a2a1d3218e9 100644 --- a/src/vs/platform/voiceRecognition/node/voiceRecognitionService.ts +++ b/src/vs/platform/voiceRecognition/node/voiceRecognitionService.ts @@ -44,11 +44,11 @@ export class VoiceRecognitionService implements IVoiceRecognitionService { const now = Date.now(); - const voiceModule: { transcribe: (audioBuffer: { channelCount: 1; sampleRate: 16000; sampleSize: 16; channelData: Float32Array }, options: { language: string | 'auto'; suppressNonSpeechTokens: boolean }) => Promise } = require.__$__nodeRequire(modulePath); + const voiceModule: { transcribe: (audioBuffer: { channelCount: 1; samplingRate: 16000; bitDepth: 16; channelData: Float32Array }, options: { language: string | 'auto'; suppressNonSpeechTokens: boolean }) => Promise } = require.__$__nodeRequire(modulePath); const text = await voiceModule.transcribe({ - sampleRate: 16000, - sampleSize: 16, + samplingRate: 16000, + bitDepth: 16, channelCount: 1, channelData }, { diff --git a/src/vs/workbench/services/voiceRecognition/electron-sandbox/workbenchVoiceRecognitionService.ts b/src/vs/workbench/services/voiceRecognition/electron-sandbox/workbenchVoiceRecognitionService.ts index 17260848ccf..e2e94971c3a 100644 --- a/src/vs/workbench/services/voiceRecognition/electron-sandbox/workbenchVoiceRecognitionService.ts +++ b/src/vs/workbench/services/voiceRecognition/electron-sandbox/workbenchVoiceRecognitionService.ts @@ -67,8 +67,8 @@ export class WorkbenchVoiceRecognitionService implements IWorkbenchVoiceRecognit declare readonly _serviceBrand: undefined; - private static readonly AUDIO_SAMPLE_RATE = 16000; - private static readonly AUDIO_SAMPLE_SIZE = 16; + private static readonly AUDIO_SAMPLING_RATE = 16000; + private static readonly AUDIO_BIT_DEPTH = 16; private static readonly AUDIO_CHANNELS = 1; constructor( @@ -96,8 +96,8 @@ export class WorkbenchVoiceRecognitionService implements IWorkbenchVoiceRecognit const microphoneDevice = await navigator.mediaDevices.getUserMedia({ audio: { - sampleRate: WorkbenchVoiceRecognitionService.AUDIO_SAMPLE_RATE, - sampleSize: WorkbenchVoiceRecognitionService.AUDIO_SAMPLE_SIZE, + sampleRate: WorkbenchVoiceRecognitionService.AUDIO_SAMPLING_RATE, + sampleSize: WorkbenchVoiceRecognitionService.AUDIO_BIT_DEPTH, channelCount: WorkbenchVoiceRecognitionService.AUDIO_CHANNELS, autoGainControl: true, noiseSuppression: true @@ -109,7 +109,7 @@ export class WorkbenchVoiceRecognitionService implements IWorkbenchVoiceRecognit } const audioContext = new AudioContext({ - sampleRate: WorkbenchVoiceRecognitionService.AUDIO_SAMPLE_RATE, + sampleRate: WorkbenchVoiceRecognitionService.AUDIO_SAMPLING_RATE, latencyHint: 'interactive' });