Skip to content

Commit

Permalink
speech recording stops after log pause in audio (fix #203189) (#203433)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 25, 2024
1 parent a908e9d commit b0d1f89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Expand Up @@ -12,9 +12,14 @@ import { IChatWidget, IChatWidgetService } from 'vs/workbench/contrib/chat/brows
import { CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_REQUEST_IN_PROGRESS } from 'vs/workbench/contrib/chat/common/chatContextKeys';
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';

export interface IVoiceChatExecuteActionContext {
readonly disableTimeout?: boolean;
}

export interface IChatExecuteActionContext {
widget?: IChatWidget;
inputValue?: string;
voice?: IVoiceChatExecuteActionContext;
}

export class SubmitAction extends Action2 {
Expand Down
Expand Up @@ -262,7 +262,7 @@ class VoiceChatSessions {
@IConfigurationService private readonly configurationService: IConfigurationService
) { }

async start(controller: IVoiceChatSessionController): Promise<void> {
async start(controller: IVoiceChatSessionController, context?: IChatExecuteActionContext): Promise<void> {
this.stop();

const sessionId = ++this.voiceChatSessionIds;
Expand Down Expand Up @@ -304,7 +304,7 @@ class VoiceChatSessions {
case SpeechToTextStatus.Recognizing:
if (text) {
session.controller.updateInput([inputValue, text].join(' '));
if (voiceChatTimeout > 0) {
if (voiceChatTimeout > 0 && context?.voice?.disableTimeout !== true) {
acceptTranscriptionScheduler.cancel();
}
}
Expand All @@ -313,7 +313,7 @@ class VoiceChatSessions {
if (text) {
inputValue = [inputValue, text].join(' ');
session.controller.updateInput(inputValue);
if (voiceChatTimeout > 0) {
if (voiceChatTimeout > 0 && context?.voice?.disableTimeout !== true) {
acceptTranscriptionScheduler.schedule();
}
}
Expand Down Expand Up @@ -408,12 +408,12 @@ export class VoiceChatInChatViewAction extends Action2 {
});
}

async run(accessor: ServicesAccessor): Promise<void> {
async run(accessor: ServicesAccessor, context?: IChatExecuteActionContext): Promise<void> {
const instantiationService = accessor.get(IInstantiationService);

const controller = await VoiceChatSessionControllerFactory.create(accessor, 'view');
if (controller) {
VoiceChatSessions.getInstance(instantiationService).start(controller);
VoiceChatSessions.getInstance(instantiationService).start(controller, context);
}
}
}
Expand All @@ -435,12 +435,12 @@ export class InlineVoiceChatAction extends Action2 {
});
}

async run(accessor: ServicesAccessor): Promise<void> {
async run(accessor: ServicesAccessor, context?: IChatExecuteActionContext): Promise<void> {
const instantiationService = accessor.get(IInstantiationService);

const controller = await VoiceChatSessionControllerFactory.create(accessor, 'inline');
if (controller) {
VoiceChatSessions.getInstance(instantiationService).start(controller);
VoiceChatSessions.getInstance(instantiationService).start(controller, context);
}
}
}
Expand All @@ -462,12 +462,12 @@ export class QuickVoiceChatAction extends Action2 {
});
}

async run(accessor: ServicesAccessor): Promise<void> {
async run(accessor: ServicesAccessor, context?: IChatExecuteActionContext): Promise<void> {
const instantiationService = accessor.get(IInstantiationService);

const controller = await VoiceChatSessionControllerFactory.create(accessor, 'quick');
if (controller) {
VoiceChatSessions.getInstance(instantiationService).start(controller);
VoiceChatSessions.getInstance(instantiationService).start(controller, context);
}
}
}
Expand Down Expand Up @@ -500,11 +500,11 @@ export class StartVoiceChatAction extends Action2 {
});
}

async run(accessor: ServicesAccessor, context: unknown): Promise<void> {
async run(accessor: ServicesAccessor, context?: IChatExecuteActionContext): Promise<void> {
const instantiationService = accessor.get(IInstantiationService);
const commandService = accessor.get(ICommandService);

const widget = (context as IChatExecuteActionContext)?.widget;
const widget = context?.widget;
if (widget) {
// if we already get a context when the action is executed
// from a toolbar within the chat widget, then make sure
Expand All @@ -518,10 +518,10 @@ export class StartVoiceChatAction extends Action2 {

const controller = await VoiceChatSessionControllerFactory.create(accessor, 'focused');
if (controller) {
VoiceChatSessions.getInstance(instantiationService).start(controller);
VoiceChatSessions.getInstance(instantiationService).start(controller, context);
} else {
// fallback to Quick Voice Chat command
commandService.executeCommand(QuickVoiceChatAction.ID);
commandService.executeCommand(QuickVoiceChatAction.ID, context);
}
}
}
Expand Down
Expand Up @@ -16,6 +16,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { StartVoiceChatAction, StopListeningAction } from 'vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions';
import { IChatExecuteActionContext } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
import { CTX_INLINE_CHAT_HAS_PROVIDER, CTX_INLINE_CHAT_VISIBLE, InlineChatConfigKeys } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { HasSpeechProvider, ISpeechService } from 'vs/workbench/contrib/speech/common/speechService';
Expand Down Expand Up @@ -95,7 +96,7 @@ function holdForSpeech(accessor: ServicesAccessor, ctrl: InlineChatController |
let listening = false;
const handle = disposableTimeout(() => {
// start VOICE input
commandService.executeCommand(StartVoiceChatAction.ID);
commandService.executeCommand(StartVoiceChatAction.ID, { voice: { disableTimeout: true } } satisfies IChatExecuteActionContext);
listening = true;
}, 250);

Expand Down

0 comments on commit b0d1f89

Please sign in to comment.