Skip to content

Commit

Permalink
voice - offer to install speech from chat item (#212412)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed May 10, 2024
1 parent 7d220c8 commit 70e10d6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,35 @@ export class StartVoiceChatAction extends Action2 {

const InstallingSpeechProvider = new RawContextKey<boolean>('installingSpeechProvider', false, true);

export class InstallVoiceChatAction extends Action2 {

static readonly ID = 'workbench.action.chat.installVoiceChat';
abstract class BaseInstallSpeechProviderAction extends Action2 {

private static readonly SPEECH_EXTENSION_ID = 'ms-vscode.vscode-speech';

async run(accessor: ServicesAccessor): Promise<void> {
const contextKeyService = accessor.get(IContextKeyService);
const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService);
try {
InstallingSpeechProvider.bindTo(contextKeyService).set(true);
await extensionsWorkbenchService.install(BaseInstallSpeechProviderAction.SPEECH_EXTENSION_ID, {
justification: this.getJustification(),
enable: true
}, ProgressLocation.Notification);
} finally {
InstallingSpeechProvider.bindTo(contextKeyService).set(false);
}
}

protected abstract getJustification(): string;
}

export class InstallSpeechProviderForVoiceChatAction extends BaseInstallSpeechProviderAction {

static readonly ID = 'workbench.action.chat.installProviderForVoiceChat';

constructor() {
super({
id: InstallVoiceChatAction.ID,
title: localize2('workbench.action.chat.startVoiceChat.label', "Start Voice Chat"),
category: CHAT_CATEGORY,
id: InstallSpeechProviderForVoiceChatAction.ID,
title: localize2('workbench.action.chat.installProviderForVoiceChat.label', "Start Voice Chat"),
icon: Codicon.mic,
precondition: InstallingSpeechProvider.negate(),
menu: [{
Expand All @@ -702,18 +720,8 @@ export class InstallVoiceChatAction extends Action2 {
});
}

async run(accessor: ServicesAccessor): Promise<void> {
const contextKeyService = accessor.get(IContextKeyService);
const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService);
try {
InstallingSpeechProvider.bindTo(contextKeyService).set(true);
await extensionsWorkbenchService.install(InstallVoiceChatAction.SPEECH_EXTENSION_ID, {
justification: localize('confirmInstallDetail', "Microphone support requires this extension."),
enable: true
}, ProgressLocation.Notification);
} finally {
InstallingSpeechProvider.bindTo(contextKeyService).set(false);
}
protected getJustification(): string {
return localize('installProviderForVoiceChat.justification', "Microphone support requires this extension.");
}
}

Expand Down Expand Up @@ -857,13 +865,35 @@ class ChatSynthesizerSessions {
}
}

export class InstallSpeechProviderForSynthesizeChatAction extends BaseInstallSpeechProviderAction {

static readonly ID = 'workbench.action.chat.installProviderForSynthesis';

constructor() {
super({
id: InstallSpeechProviderForSynthesizeChatAction.ID,
title: localize2('workbench.action.chat.installProviderForSynthesis.label', "Read Aloud"),
icon: Codicon.unmute,
precondition: InstallingSpeechProvider.negate(),
menu: [{
id: MenuId.ChatMessageTitle,
when: HasSpeechProvider.negate(),
group: 'navigation'
}]
});
}

protected getJustification(): string {
return localize('installProviderForSynthesis.justification', "Speaker support requires this extension.");
}
}

export class ReadChatItemAloud extends Action2 {
constructor() {
super({
id: 'workbench.action.chat.readChatItemAloud',
title: localize2('workbench.action.chat.readChatItemAloud', "Read Aloud"),
f1: false,
category: CHAT_CATEGORY,
icon: Codicon.unmute,
precondition: CanVoiceChat,
menu: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { InlineVoiceChatAction, QuickVoiceChatAction, StartVoiceChatAction, StopListeningInQuickChatAction, StopListeningInChatEditorAction, StopListeningInChatViewAction, VoiceChatInChatViewAction, StopListeningAction, StopListeningAndSubmitAction, KeywordActivationContribution, InstallVoiceChatAction, StopListeningInTerminalChatAction, HoldToVoiceChatInChatViewAction, ReadChatItemAloud, StopReadAloud, StopReadChatItemAloud } from 'vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions';
import { InlineVoiceChatAction, QuickVoiceChatAction, StartVoiceChatAction, StopListeningInQuickChatAction, StopListeningInChatEditorAction, StopListeningInChatViewAction, VoiceChatInChatViewAction, StopListeningAction, StopListeningAndSubmitAction, KeywordActivationContribution, InstallSpeechProviderForSynthesizeChatAction, InstallSpeechProviderForVoiceChatAction, StopListeningInTerminalChatAction, HoldToVoiceChatInChatViewAction, ReadChatItemAloud, StopReadAloud, StopReadChatItemAloud } from 'vs/workbench/contrib/chat/electron-sandbox/actions/voiceChatActions';
import { registerAction2 } from 'vs/platform/actions/common/actions';
import { WorkbenchPhase, registerWorkbenchContribution2 } from 'vs/workbench/common/contributions';

registerAction2(StartVoiceChatAction);
registerAction2(InstallVoiceChatAction);
registerAction2(InstallSpeechProviderForVoiceChatAction);

registerAction2(VoiceChatInChatViewAction);
registerAction2(HoldToVoiceChatInChatViewAction);
Expand All @@ -26,5 +26,6 @@ registerAction2(StopListeningInTerminalChatAction);
registerAction2(ReadChatItemAloud);
registerAction2(StopReadChatItemAloud);
registerAction2(StopReadAloud);
registerAction2(InstallSpeechProviderForSynthesizeChatAction);

registerWorkbenchContribution2(KeywordActivationContribution.ID, KeywordActivationContribution, WorkbenchPhase.AfterRestored);

0 comments on commit 70e10d6

Please sign in to comment.