voice - allow pause between agent and slash command

This commit is contained in:
Benjamin Pasero 2024-02-13 12:27:34 +01:00 committed by Benjamin Pasero
parent f1b761fea5
commit f28c9e1cb6
2 changed files with 44 additions and 8 deletions

View file

@ -118,11 +118,7 @@ export class VoiceChatService extends Disposable implements IVoiceChatService {
return phrases;
}
private toText(value: IPhraseValue, type: PhraseTextType, options: IVoiceChatSessionOptions): string {
if (type === PhraseTextType.COMMAND && options.usesAgents) {
type = PhraseTextType.AGENT_AND_COMMAND; // rewrite `/fix` to `@workspace /foo` in this case
}
private toText(value: IPhraseValue, type: PhraseTextType): string {
switch (type) {
case PhraseTextType.AGENT:
return `${VoiceChatService.AGENT_PREFIX}${value.agent}`;
@ -158,7 +154,7 @@ export class VoiceChatService extends Disposable implements IVoiceChatService {
if (options.usesAgents && startsWithAgent && !detectedAgent && !detectedSlashCommand && originalWords.length >= 4) {
const phrase = this.phrases.get(originalWords.slice(0, 4).map(word => this.normalizeWord(word)).join(' '));
if (phrase) {
transformedWords = [this.toText(phrase, PhraseTextType.AGENT_AND_COMMAND, options), ...originalWords.slice(4)];
transformedWords = [this.toText(phrase, PhraseTextType.AGENT_AND_COMMAND), ...originalWords.slice(4)];
waitingForInput = originalWords.length === 4;
@ -173,7 +169,7 @@ export class VoiceChatService extends Disposable implements IVoiceChatService {
if (options.usesAgents && startsWithAgent && !detectedAgent && !transformedWords && originalWords.length >= 2) {
const phrase = this.phrases.get(originalWords.slice(0, 2).map(word => this.normalizeWord(word)).join(' '));
if (phrase) {
transformedWords = [this.toText(phrase, PhraseTextType.AGENT, options), ...originalWords.slice(2)];
transformedWords = [this.toText(phrase, PhraseTextType.AGENT), ...originalWords.slice(2)];
waitingForInput = originalWords.length === 2;
@ -187,7 +183,10 @@ export class VoiceChatService extends Disposable implements IVoiceChatService {
if (startsWithSlashCommand && !detectedSlashCommand && !transformedWords && originalWords.length >= 2) {
const phrase = this.phrases.get(originalWords.slice(0, 2).map(word => this.normalizeWord(word)).join(' '));
if (phrase) {
transformedWords = [this.toText(phrase, PhraseTextType.COMMAND, options), ...originalWords.slice(2)];
transformedWords = [this.toText(phrase, options.usesAgents && !detectedAgent ?
PhraseTextType.AGENT_AND_COMMAND : // rewrite `/fix` to `@workspace /foo` in this case
PhraseTextType.COMMAND // when we have not yet detected an agent before
), ...originalWords.slice(2)];
waitingForInput = originalWords.length === 2;

View file

@ -250,6 +250,43 @@ suite('VoiceChat', () => {
assert.strictEqual(event?.status, SpeechToTextStatus.Recognized);
assert.strictEqual(event?.text, options.usesAgents ? '@workspace for at workspace' : 'At workspace, for at workspace');
assert.strictEqual(event?.waitingForInput, false);
// Slash command detected after agent recognized
if (options.usesAgents) {
createSession(options);
emitter.fire({ status: SpeechToTextStatus.Recognized, text: 'At workspace' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognized);
assert.strictEqual(event?.text, '@workspace');
assert.strictEqual(event?.waitingForInput, true);
emitter.fire({ status: SpeechToTextStatus.Recognizing, text: 'slash' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognizing);
assert.strictEqual(event?.text, 'slash');
assert.strictEqual(event?.waitingForInput, false);
emitter.fire({ status: SpeechToTextStatus.Recognizing, text: 'slash fix' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognizing);
assert.strictEqual(event?.text, '/fix');
assert.strictEqual(event?.waitingForInput, true);
emitter.fire({ status: SpeechToTextStatus.Recognized, text: 'slash fix' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognized);
assert.strictEqual(event?.text, '/fix');
assert.strictEqual(event?.waitingForInput, true);
createSession(options);
emitter.fire({ status: SpeechToTextStatus.Recognized, text: 'At workspace' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognized);
assert.strictEqual(event?.text, '@workspace');
assert.strictEqual(event?.waitingForInput, true);
emitter.fire({ status: SpeechToTextStatus.Recognized, text: 'slash fix' });
assert.strictEqual(event?.status, SpeechToTextStatus.Recognized);
assert.strictEqual(event?.text, '/fix');
assert.strictEqual(event?.waitingForInput, true);
}
}
test('waiting for input', async () => {