@startsimpli/integrations 0.2.225 → 0.2.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/__tests__/attention-orgs.test.ts +61 -0
- package/src/__tests__/attention-run.test.ts +3 -3
- package/src/__tests__/converse-meeting-interrupted.test.ts +74 -0
- package/src/__tests__/converse-meeting-vad.test.ts +25 -3
- package/src/__tests__/converse-meeting.test.ts +29 -0
- package/src/__tests__/converse-roci-transcript.test.ts +36 -0
- package/src/__tests__/converse-soak.test.ts +28 -0
- package/src/__tests__/converse-tts.test.ts +128 -0
- package/src/__tests__/converse.test.ts +38 -1
- package/src/__tests__/relay-items.test.ts +1 -1
- package/src/corpus/attention/importance.ts +1 -1
- package/src/corpus/attention/index.ts +1 -0
- package/src/corpus/attention/orgs.ts +41 -0
- package/src/corpus/attention/policy.ts +2 -0
- package/src/corpus/attention/push.ts +2 -1
- package/src/corpus/attention/queue.ts +3 -1
- package/src/corpus/attention/run-steps.ts +1 -1
- package/src/corpus/attention/run.ts +4 -3
- package/src/corpus/attention/types.ts +1 -1
- package/src/corpus/converse/handle.ts +12 -4
- package/src/corpus/converse/meeting-config.ts +8 -2
- package/src/corpus/converse/meeting.ts +24 -5
- package/src/corpus/converse/respond.ts +2 -2
- package/src/corpus/converse/speak-chunks.ts +33 -0
- package/src/corpus/converse/speak.ts +17 -4
- package/src/corpus/converse/types.ts +2 -0
- package/src/corpus/converse/vad.ts +16 -1
- package/src/corpus/notify/types.ts +2 -0
- package/src/native/app/FoundryApp.tsx +37 -2
- package/src/native/app/__tests__/briefingServices.test.ts +26 -0
- package/src/native/app/__tests__/haptics.test.tsx +55 -0
- package/src/native/app/__tests__/launch.test.ts +23 -1
- package/src/native/app/briefingServices.ts +9 -0
- package/src/native/app/converseServices.ts +17 -5
- package/src/native/app/device.ts +7 -0
- package/src/native/app/launch.ts +24 -0
- package/src/native/app/registry.tsx +6 -1
- package/src/native/app/services.ts +2 -2
- package/src/native/briefing/__tests__/playerPauseResume.test.ts +47 -0
- package/src/native/briefing/audioPlayer.ts +16 -1
- package/src/native/converse/ConverseScreen.tsx +45 -78
- package/src/native/converse/__tests__/bargeInIO.test.ts +49 -0
- package/src/native/converse/__tests__/liveScreen.test.tsx +59 -63
- package/src/native/converse/__tests__/meetingIO.test.ts +89 -23
- package/src/native/converse/__tests__/mock.test.ts +58 -0
- package/src/native/converse/__tests__/speedScreen.test.tsx +6 -2
- package/src/native/converse/index.ts +4 -1
- package/src/native/converse/io.ts +34 -20
- package/src/native/converse/mock.ts +136 -0
- package/src/native/converse/stateBanner.tsx +41 -0
- package/src/native/index.ts +1 -0
- package/src/native/push/NeedsYouCard.tsx +11 -7
- package/src/native/push/__tests__/decisionsApp.test.tsx +2 -3
- package/src/native/push/__tests__/needsYou.test.tsx +23 -9
- package/src/native/push/fake.ts +5 -5
- package/src/native/recording/recorder.ts +2 -1
- package/src/native/recording/recorderAudio.ts +14 -1
- package/src/native/talk/TalkTab.tsx +16 -13
- package/src/native/talk/__tests__/talk-tab.test.tsx +18 -0
- package/src/native/voice-session/__tests__/bargeIn.test.ts +93 -0
- package/src/native/voice-session/__tests__/bindings.test.ts +84 -0
- package/src/native/voice-session/__tests__/events.test.ts +72 -0
- package/src/native/voice-session/__tests__/inspector.test.ts +28 -0
- package/src/native/voice-session/__tests__/lifecycle.test.ts +197 -0
- package/src/native/voice-session/__tests__/music.test.ts +86 -0
- package/src/native/voice-session/__tests__/routes.test.ts +121 -0
- package/src/native/voice-session/__tests__/voiceSession.test.ts +177 -0
- package/src/native/voice-session/bindMeeting.ts +33 -0
- package/src/native/voice-session/fake.ts +21 -0
- package/src/native/voice-session/index.ts +142 -0
- package/src/native/voice-session/inspector.ts +14 -0
- package/src/native/voice-session/machine.ts +41 -0
- package/src/native/voice-session/nowPlaying.ts +35 -0
- package/src/native/voice-session/types.ts +45 -0
- package/src/native/voice-session/wire.ts +47 -0
- package/src/native/converse/DriveScreen.tsx +0 -47
- package/src/native/converse/__tests__/driveScreen.test.tsx +0 -54
|
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
vi.mock('react-native', async () => ({ ...(await import('../../../../../ui-native/test/rn-stub')) }));
|
|
4
4
|
|
|
5
|
-
import { act, hostById, maybeById, render } from '../../../../../ui-native/test/render';
|
|
5
|
+
import { act, allText, hostById, maybeById, render } from '../../../../../ui-native/test/render';
|
|
6
6
|
import type { MeetingController } from '../../../corpus/converse/meeting';
|
|
7
7
|
import { ConverseScreen } from '../ConverseScreen';
|
|
8
8
|
|
|
@@ -18,46 +18,67 @@ const make = (phase: string, micPreference = false) => {
|
|
|
18
18
|
return { controller, calls, mics };
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const word = (r: ReturnType<typeof render>) => String(hostById(r, 'converse-status').props.children);
|
|
22
|
+
const openMenu = async (r: ReturnType<typeof render>) => { await act(async () => { hostById(r, 'converse-settings').props.onPress(); }); };
|
|
23
|
+
|
|
24
|
+
describe('Talk is one flow: thread, one mic (it shows the state), text box, settings', () => {
|
|
25
|
+
it.each([['listening', 'Listening'], ['thinking', 'Thinking'], ['speaking', 'Speaking'], ['idle', 'Muted']])('%s: NO status bar; the mic itself carries the state (%s)', (phase, hint) => {
|
|
26
|
+
const { controller } = make(phase);
|
|
27
|
+
const r = render(<ConverseScreen controller={controller} />);
|
|
28
|
+
expect(maybeById(r, 'converse-banner')).toHaveLength(0);
|
|
29
|
+
expect(maybeById(r, 'state-banner')).toHaveLength(0);
|
|
30
|
+
expect(hostById(r, 'converse-mic').props.accessibilityHint).toBe(hint);
|
|
31
|
+
});
|
|
32
|
+
it('has no header title, no subtitle, no Start circle, no Voice/Text pills, no Drive button, no Done, no Stop', () => {
|
|
23
33
|
const { controller } = make('listening');
|
|
24
34
|
const r = render(<ConverseScreen controller={controller} />);
|
|
25
|
-
|
|
26
|
-
expect(hostById(r, 'converse-live')).toBeTruthy();
|
|
35
|
+
for (const gone of ['converse-header', 'converse-talk', 'converse-mode', 'converse-mode-voice', 'converse-mode-text', 'talk-drive', 'converse-end', 'converse-stop', 'converse-speed', 'converse-repeat']) expect(maybeById(r, gone)).toHaveLength(0);
|
|
27
36
|
expect(hostById(r, 'converse-line-1')).toBeTruthy();
|
|
28
|
-
expect(hostById(r, 'converse-
|
|
37
|
+
expect(hostById(r, 'converse-mic')).toBeTruthy();
|
|
38
|
+
expect(hostById(r, 'converse-input')).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
it('the ONE mic control: Talk when off, Mute while listening, Interrupt while it speaks or thinks', async () => {
|
|
41
|
+
const off = make('idle');
|
|
42
|
+
const r0 = render(<ConverseScreen controller={off.controller} />);
|
|
43
|
+
expect(hostById(r0, 'converse-mic').props.accessibilityLabel).toBe('Talk');
|
|
44
|
+
await act(async () => { hostById(r0, 'converse-mic').props.onPress(); });
|
|
45
|
+
expect(off.mics).toEqual([true]);
|
|
46
|
+
const live = make('listening');
|
|
47
|
+
const r1 = render(<ConverseScreen controller={live.controller} />);
|
|
48
|
+
expect(hostById(r1, 'converse-mic').props.accessibilityLabel).toBe('Mute');
|
|
49
|
+
await act(async () => { hostById(r1, 'converse-mic').props.onPress(); });
|
|
50
|
+
expect(live.mics).toEqual([false]);
|
|
51
|
+
for (const phase of ['speaking', 'thinking']) {
|
|
52
|
+
const t = make(phase);
|
|
53
|
+
const r = render(<ConverseScreen controller={t.controller} />);
|
|
54
|
+
expect(hostById(r, 'converse-mic').props.accessibilityLabel).toBe('Interrupt');
|
|
55
|
+
expect(hostById(r, 'converse-mic').props.disabled).toBeFalsy();
|
|
56
|
+
await act(async () => { hostById(r, 'converse-mic').props.onPress(); });
|
|
57
|
+
expect(t.calls.stop).toBe(1);
|
|
58
|
+
}
|
|
29
59
|
});
|
|
30
|
-
it('leaving the screen does not end the meeting; only
|
|
60
|
+
it('leaving the screen does not end the meeting; only Save conversation (in settings) does', async () => {
|
|
31
61
|
const { controller, calls } = make('speaking');
|
|
32
62
|
const r = render(<ConverseScreen controller={controller} />);
|
|
33
63
|
act(() => { r.unmount(); });
|
|
34
64
|
expect(calls.end).toBe(0);
|
|
35
65
|
const r2 = render(<ConverseScreen controller={controller} />);
|
|
66
|
+
await openMenu(r2);
|
|
36
67
|
await act(async () => { hostById(r2, 'converse-end').props.onPress(); });
|
|
37
68
|
expect(calls.end).toBe(1);
|
|
38
69
|
});
|
|
39
|
-
it('
|
|
40
|
-
const { controller
|
|
41
|
-
(controller.getState() as { lines: unknown[] }).lines = [];
|
|
42
|
-
const r = render(<ConverseScreen controller={controller} />);
|
|
43
|
-
expect(maybeById(r, 'converse-talk')).toHaveLength(0);
|
|
44
|
-
expect(maybeById(r, 'converse-live')).toHaveLength(0);
|
|
45
|
-
expect(hostById(r, 'converse-input')).toBeTruthy();
|
|
46
|
-
await act(async () => { hostById(r, 'converse-mic').props.onPress(); });
|
|
47
|
-
expect(mics).toEqual([true]);
|
|
48
|
-
});
|
|
49
|
-
it('the mic stops listening without ending the conversation', async () => {
|
|
50
|
-
const { controller, calls, mics } = make('listening');
|
|
70
|
+
it('after it is saved, Save conversation is not offered again', async () => {
|
|
71
|
+
const { controller } = make('ended');
|
|
51
72
|
const r = render(<ConverseScreen controller={controller} />);
|
|
52
|
-
await
|
|
53
|
-
expect(
|
|
54
|
-
expect(calls.end).toBe(0);
|
|
73
|
+
await openMenu(r);
|
|
74
|
+
expect(maybeById(r, 'converse-end')).toHaveLength(0);
|
|
55
75
|
});
|
|
56
|
-
it('
|
|
57
|
-
const { controller } = make('
|
|
76
|
+
it('a problem shows as a small alert, not in a banner', () => {
|
|
77
|
+
const { controller } = make('stopped');
|
|
78
|
+
(controller.getState() as { error: string | null }).error = 'No connection';
|
|
58
79
|
const r = render(<ConverseScreen controller={controller} />);
|
|
59
|
-
expect(hostById(r, 'converse-
|
|
60
|
-
expect(
|
|
80
|
+
expect(hostById(r, 'converse-error')).toBeTruthy();
|
|
81
|
+
expect(allText(r)).toContain('No connection');
|
|
61
82
|
});
|
|
62
83
|
it('a cited source opens through onOpenSource', async () => {
|
|
63
84
|
const { controller } = make('idle');
|
|
@@ -76,49 +97,24 @@ describe('Converse while a meeting runs', () => {
|
|
|
76
97
|
expect(calls.text).toEqual(['move the car service to Friday']);
|
|
77
98
|
expect(hostById(r, 'converse-input').props.value).toBe('');
|
|
78
99
|
});
|
|
79
|
-
it('after Done it says the meeting is saved and offers no Done again', () => {
|
|
80
|
-
const { controller } = make('ended');
|
|
81
|
-
const r = render(<ConverseScreen controller={controller} />);
|
|
82
|
-
expect(JSON.stringify(r.toJSON())).toContain('Meeting saved');
|
|
83
|
-
expect(maybeById(r, 'converse-end')).toHaveLength(0);
|
|
84
|
-
});
|
|
85
100
|
it('shows a quiet Filed marker after a note was filed', () => {
|
|
86
101
|
const { controller } = make('listening');
|
|
87
102
|
(controller.getState() as { lines: unknown[] }).lines = [{ role: 'user', text: 'note' }, { role: 'assistant', text: 'Got it.' }, { role: 'system', text: 'Filed: 2 to-dos' }];
|
|
88
103
|
const r = render(<ConverseScreen controller={controller} />);
|
|
89
104
|
expect(JSON.stringify(r.toJSON())).toContain('Filed: 2 to-dos');
|
|
90
105
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
await act(async () => { hostById(r, 'converse-stop').props.onPress(); });
|
|
99
|
-
expect(calls.stop).toBe(1);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
it('Stop is not shown when nothing is being said', () => {
|
|
103
|
-
const { controller } = make('listening');
|
|
104
|
-
const r = render(<ConverseScreen controller={controller} />);
|
|
105
|
-
expect(maybeById(r, 'converse-stop')).toHaveLength(0);
|
|
106
|
-
});
|
|
107
|
-
it('the mic stays on screen and tappable while it speaks', () => {
|
|
108
|
-
const { controller } = make('speaking');
|
|
109
|
-
const r = render(<ConverseScreen controller={controller} />);
|
|
110
|
-
expect(hostById(r, 'converse-mic').props.disabled).toBeFalsy();
|
|
111
|
-
});
|
|
112
|
-
it('Text turns the mic off and Voice turns it on', async () => {
|
|
106
|
+
it('holds the drive audio session only while a conversation runs', async () => {
|
|
107
|
+
const log: string[] = [];
|
|
108
|
+
const drive = { begin: async () => { log.push('begin'); }, end: async () => { log.push('end'); } };
|
|
109
|
+
const idle = make('idle');
|
|
110
|
+
render(<ConverseScreen controller={idle.controller} drive={drive} />);
|
|
111
|
+
await act(async () => { await Promise.resolve(); });
|
|
112
|
+
expect(log).toEqual(['end']);
|
|
113
113
|
const live = make('listening');
|
|
114
|
-
const r = render(<ConverseScreen controller={live.controller} />);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const r2 = render(<ConverseScreen controller={off.controller} />);
|
|
120
|
-
expect(hostById(r2, 'converse-mode-text').props.accessibilityState).toEqual({ selected: true });
|
|
121
|
-
await act(async () => { hostById(r2, 'converse-mode-voice').props.onPress(); });
|
|
122
|
-
expect(off.mics).toEqual([true]);
|
|
114
|
+
const r = render(<ConverseScreen controller={live.controller} drive={drive} />);
|
|
115
|
+
await act(async () => { await Promise.resolve(); });
|
|
116
|
+
expect(log.at(-1)).toBe('begin');
|
|
117
|
+
act(() => { r.unmount(); });
|
|
118
|
+
expect(log.at(-1)).toBe('end');
|
|
123
119
|
});
|
|
124
120
|
});
|
|
@@ -4,20 +4,24 @@ import { createMeetingController } from '../../../corpus/converse/meeting';
|
|
|
4
4
|
import { resolveMeetingConfig } from '../../../corpus/converse/meeting-config';
|
|
5
5
|
import { createNativeMeetingApi } from '../api';
|
|
6
6
|
import { createFakeMeeting } from '../fake';
|
|
7
|
-
import { createMeetingIO, dbToLevel
|
|
7
|
+
import { createMeetingIO, dbToLevel } from '../io';
|
|
8
8
|
import { statusLine } from '../format';
|
|
9
9
|
|
|
10
10
|
const LOUD = -10; // dBFS, well above the 0.02 speech level
|
|
11
11
|
const QUIET = -80;
|
|
12
12
|
|
|
13
|
-
function rig(over: { permission?: 'granted' | 'denied' } = {}) {
|
|
13
|
+
function rig(over: { permission?: 'granted' | 'denied'; bytes?: number; startFailures?: number } = {}) {
|
|
14
14
|
let clock = 0;
|
|
15
15
|
let onLevel: (db: number) => void = () => undefined;
|
|
16
16
|
const starts: number[] = [];
|
|
17
17
|
let take = 0;
|
|
18
|
+
let startFailures = over.startFailures ?? 0;
|
|
18
19
|
const audio = {
|
|
19
|
-
start: vi.fn(async (h: { onLevel: (db: number) => void }) => {
|
|
20
|
-
|
|
20
|
+
start: vi.fn(async (h: { onLevel: (db: number) => void }) => {
|
|
21
|
+
if (startFailures > 0) { startFailures -= 1; throw new Error('recorder did not start'); }
|
|
22
|
+
onLevel = h.onLevel; starts.push(clock);
|
|
23
|
+
}),
|
|
24
|
+
stop: vi.fn(async () => ({ uri: `file:///take${++take}.m4a`, durationMs: 2000, bytes: over.bytes ?? 9000 })),
|
|
21
25
|
};
|
|
22
26
|
let ps = { phase: 'idle' as string, positionMillis: 0, durationMillis: 0 };
|
|
23
27
|
const ls = new Set<(s: typeof ps) => void>();
|
|
@@ -32,10 +36,11 @@ function rig(over: { permission?: 'granted' | 'denied' } = {}) {
|
|
|
32
36
|
const removeFile = vi.fn(async () => undefined);
|
|
33
37
|
const api = { replySource: vi.fn(async () => ({ uri: 'http://x/a.mp3', headers: { authorization: 'Bearer t' } })), turn: vi.fn(), end: vi.fn() };
|
|
34
38
|
let broken: () => void = () => undefined;
|
|
35
|
-
const
|
|
39
|
+
const expiry = new Set<() => void>();
|
|
40
|
+
const io = createMeetingIO({ api: api as never, audio, speaker: speaker as never, removeFile, ensurePermission: async () => over.permission ?? 'granted', now: () => clock, onBroken: (h) => { broken = h; }, pauseExpired: (cb) => { expiry.add(cb); return () => { expiry.delete(cb); }; } });
|
|
36
41
|
/** Feed one level reading per 100 ms of fake time. */
|
|
37
42
|
const feed = (db: number, ms: number) => { for (let t = 0; t < ms; t += 100) { clock += 100; onLevel(db); } };
|
|
38
|
-
return { io, audio, speaker, removeFile, api, feed, finishPlayback, pausePlayback, starts, breakIt: () => broken(), config: resolveMeetingConfig() };
|
|
43
|
+
return { io, audio, speaker, expirePause: () => expiry.forEach((cb) => cb()), expiryListeners: () => expiry.size, removeFile, api, feed, finishPlayback, pausePlayback, starts, breakIt: () => broken(), config: resolveMeetingConfig() };
|
|
39
44
|
}
|
|
40
45
|
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
41
46
|
const settle = async () => { for (let i = 0; i < 6; i += 1) await tick(); };
|
|
@@ -121,35 +126,51 @@ describe('speak', () => {
|
|
|
121
126
|
expect(done).toBe(true);
|
|
122
127
|
});
|
|
123
128
|
|
|
124
|
-
it('a reply the
|
|
129
|
+
it('a reply the session gave up waiting on (VoiceSession pause-timeout) is played again, not waited on forever', async () => {
|
|
130
|
+
const r = rig();
|
|
131
|
+
const p = r.io.speak(reply, new AbortController().signal, r.config);
|
|
132
|
+
await tick();
|
|
133
|
+
r.pausePlayback();
|
|
134
|
+
r.expirePause();
|
|
135
|
+
await tick();
|
|
136
|
+
expect(r.speaker.play).toHaveBeenCalledTimes(2);
|
|
137
|
+
r.finishPlayback();
|
|
138
|
+
await p;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('the loop has no pause timer of its own: a paused reply is left alone until VoiceSession says so', async () => {
|
|
125
142
|
vi.useFakeTimers();
|
|
126
143
|
try {
|
|
127
144
|
const r = rig();
|
|
128
145
|
const p = r.io.speak(reply, new AbortController().signal, r.config);
|
|
129
146
|
await vi.advanceTimersByTimeAsync(1);
|
|
130
147
|
r.pausePlayback();
|
|
131
|
-
await vi.advanceTimersByTimeAsync(
|
|
148
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
132
149
|
expect(r.speaker.play).toHaveBeenCalledTimes(1);
|
|
133
|
-
await vi.advanceTimersByTimeAsync(2);
|
|
134
|
-
expect(r.speaker.play).toHaveBeenCalledTimes(2);
|
|
135
150
|
r.finishPlayback();
|
|
136
151
|
await p;
|
|
137
152
|
} finally { vi.useRealTimers(); }
|
|
138
153
|
});
|
|
139
154
|
|
|
140
|
-
it('a pause that
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
it('a pause timeout that arrives when the reply is not paused is ignored', async () => {
|
|
156
|
+
const r = rig();
|
|
157
|
+
const p = r.io.speak(reply, new AbortController().signal, r.config);
|
|
158
|
+
await tick();
|
|
159
|
+
r.expirePause();
|
|
160
|
+
await tick();
|
|
161
|
+
expect(r.speaker.play).toHaveBeenCalledTimes(1);
|
|
162
|
+
r.finishPlayback();
|
|
163
|
+
await p;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('stops listening for the pause timeout once the reply is over', async () => {
|
|
167
|
+
const r = rig();
|
|
168
|
+
const p = r.io.speak(reply, new AbortController().signal, r.config);
|
|
169
|
+
await tick();
|
|
170
|
+
expect(r.expiryListeners()).toBe(1);
|
|
171
|
+
r.finishPlayback();
|
|
172
|
+
await p;
|
|
173
|
+
expect(r.expiryListeners()).toBe(0);
|
|
153
174
|
});
|
|
154
175
|
|
|
155
176
|
it('abort cuts the reply off and resolves', async () => {
|
|
@@ -270,3 +291,48 @@ describe('duplex io (mic stays open while the reply plays)', () => {
|
|
|
270
291
|
await p;
|
|
271
292
|
});
|
|
272
293
|
});
|
|
294
|
+
|
|
295
|
+
describe('STT reliability (bd startsim-1x6kv.3)', () => {
|
|
296
|
+
it('a recording with no bytes in it (the empty-file race) is dropped, never sent as a turn, and listening carries on', async () => {
|
|
297
|
+
const r = rig({ bytes: 0 });
|
|
298
|
+
const ctl = new AbortController();
|
|
299
|
+
const p = r.io.listen(ctl.signal, r.config);
|
|
300
|
+
await tick();
|
|
301
|
+
r.feed(LOUD, 1000); r.feed(QUIET, 1300);
|
|
302
|
+
await settle();
|
|
303
|
+
expect(r.removeFile).toHaveBeenCalledWith('file:///take1.m4a');
|
|
304
|
+
expect(r.audio.start).toHaveBeenCalledTimes(2);
|
|
305
|
+
ctl.abort();
|
|
306
|
+
expect((await p).audio).toBeNull();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('the microphone permission is answered before the recorder is asked to start', async () => {
|
|
310
|
+
const order: string[] = [];
|
|
311
|
+
const r = rig();
|
|
312
|
+
const { createMeetingIO } = await import('../io');
|
|
313
|
+
const io = createMeetingIO({
|
|
314
|
+
api: r.api as never, audio: { start: vi.fn(async () => { order.push('start'); }), stop: vi.fn(async () => ({ uri: 'file:///x.m4a', durationMs: 1, bytes: 1 })) },
|
|
315
|
+
speaker: r.speaker as never, removeFile: r.removeFile, ensurePermission: async () => { order.push('permission'); return 'granted'; },
|
|
316
|
+
});
|
|
317
|
+
const ctl = new AbortController();
|
|
318
|
+
const p = io.listen(ctl.signal, r.config);
|
|
319
|
+
await tick();
|
|
320
|
+
ctl.abort();
|
|
321
|
+
await p;
|
|
322
|
+
expect(order).toEqual(['permission', 'start']);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('a first start that fails once (the first-tap !rec) is retried and the utterance still comes back', async () => {
|
|
326
|
+
const r = rig({ startFailures: 1 });
|
|
327
|
+
const p = r.io.listen(new AbortController().signal, r.config);
|
|
328
|
+
await new Promise((res) => setTimeout(res, 700));
|
|
329
|
+
r.feed(LOUD, 1000); r.feed(QUIET, 1300);
|
|
330
|
+
expect((await p).audio?.uri).toBe('file:///take1.m4a');
|
|
331
|
+
expect(r.audio.start).toHaveBeenCalledTimes(2);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('a start that keeps failing still surfaces the error (no endless retry)', async () => {
|
|
335
|
+
const r = rig({ startFailures: 99 });
|
|
336
|
+
await expect(r.io.listen(new AbortController().signal, r.config)).rejects.toThrow('recorder did not start');
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createMeetingIO } from '../io';
|
|
3
|
+
import { createMockVoice, MOCK_SCENARIOS, readMockScenario } from '../mock';
|
|
4
|
+
import { resolveMeetingConfig } from '../../../corpus/converse/meeting-config';
|
|
5
|
+
|
|
6
|
+
const config = resolveMeetingConfig();
|
|
7
|
+
const advance = async (ms: number) => { for (let t = 0; t < ms; t += 50) { vi.advanceTimersByTime(50); await Promise.resolve(); } };
|
|
8
|
+
|
|
9
|
+
function rig(scenario: string) {
|
|
10
|
+
const events: Array<{ event: string; at: number; fields?: Record<string, unknown> }> = [];
|
|
11
|
+
const diag = { log: (event: string, fields?: Record<string, unknown>) => { events.push({ event, at: Date.now(), fields }); } };
|
|
12
|
+
const mock = createMockVoice({ turns: MOCK_SCENARIOS[scenario], diag });
|
|
13
|
+
const io = createMeetingIO({ api: { replySource: async () => ({ uri: 'fake://silent' }) } as never, audio: mock.audio, speaker: mock.speaker, removeFile: async () => undefined, ensurePermission: async () => 'granted', diag, duplex: true });
|
|
14
|
+
return { io, events };
|
|
15
|
+
}
|
|
16
|
+
const named = (events: Array<{ event: string }>, n: string) => events.filter((e) => e.event === n);
|
|
17
|
+
|
|
18
|
+
beforeEach(() => vi.useFakeTimers());
|
|
19
|
+
afterEach(() => vi.useRealTimers());
|
|
20
|
+
|
|
21
|
+
describe('-tgVoiceMock scripted voice', () => {
|
|
22
|
+
it('knows its scenarios and rejects others', () => {
|
|
23
|
+
expect(readMockScenario('barge-in')).not.toBeNull();
|
|
24
|
+
expect(readMockScenario('nope')).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('barge-in: speech over a long reply cuts it off within 3 s, then the speech is heard', async () => {
|
|
28
|
+
const { io, events } = rig('barge-in');
|
|
29
|
+
const first = io.listen(new AbortController().signal, config, {});
|
|
30
|
+
await advance(5000);
|
|
31
|
+
await first;
|
|
32
|
+
const speakAbort = new AbortController();
|
|
33
|
+
const speaking = io.speak({} as never, speakAbort.signal);
|
|
34
|
+
const second = io.listen(new AbortController().signal, config, { onSpeechStart: () => speakAbort.abort() });
|
|
35
|
+
await advance(8000);
|
|
36
|
+
await speaking;
|
|
37
|
+
const start = named(events, 'mock.interject-start')[0];
|
|
38
|
+
const stop = named(events, 'mock.reply-stop')[0];
|
|
39
|
+
expect(stop.fields).toMatchObject({ why: 'stopped' });
|
|
40
|
+
expect(stop.at - start.at).toBeLessThanOrEqual(3000);
|
|
41
|
+
await advance(4000);
|
|
42
|
+
await expect(second).resolves.toMatchObject({ reason: 'speech-ended' });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('echo-only: a quiet steady level never cuts the reply off', async () => {
|
|
46
|
+
const { io, events } = rig('echo-only');
|
|
47
|
+
const first = io.listen(new AbortController().signal, config, {});
|
|
48
|
+
await advance(5000);
|
|
49
|
+
await first;
|
|
50
|
+
const onSpeechStart = vi.fn();
|
|
51
|
+
const speaking = io.speak({} as never, new AbortController().signal);
|
|
52
|
+
void io.listen(new AbortController().signal, config, { onSpeechStart });
|
|
53
|
+
await advance(8000);
|
|
54
|
+
await speaking;
|
|
55
|
+
expect(onSpeechStart).not.toHaveBeenCalled();
|
|
56
|
+
expect(named(events, 'mock.reply-stop')[0].fields).toMatchObject({ why: 'ended', playedMs: 6000 });
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -18,13 +18,17 @@ describe('Converse speed control', () => {
|
|
|
18
18
|
it('shows 1x 1.25x 1.5x 2x, marks the current one and changes it on tap', async () => {
|
|
19
19
|
const speed = createSpeedStore({ path: 'p', files: { exists: async () => false, read: async () => '', write: async () => undefined } });
|
|
20
20
|
const r = render(<ConverseScreen controller={controller} speed={speed} />);
|
|
21
|
+
expect(maybeById(r, 'converse-speed')).toHaveLength(0); // lives in the settings menu
|
|
22
|
+
await act(async () => { hostById(r, 'converse-settings').props.onPress(); });
|
|
21
23
|
expect(hostById(r, 'converse-speed-1.25').props.accessibilityState).toEqual({ selected: true });
|
|
22
24
|
await act(async () => { hostById(r, 'converse-speed-2').props.onPress(); });
|
|
23
25
|
expect(speed.get()).toBe(2);
|
|
24
26
|
expect(hostById(r, 'converse-speed-2').props.accessibilityState).toEqual({ selected: true });
|
|
25
27
|
expect(hostById(r, 'converse-speed-1.25').props.accessibilityState).toEqual({ selected: false });
|
|
26
28
|
});
|
|
27
|
-
it('has no control when there is no speed store', () => {
|
|
28
|
-
|
|
29
|
+
it('has no control when there is no speed store', async () => {
|
|
30
|
+
const r = render(<ConverseScreen controller={controller} />);
|
|
31
|
+
await act(async () => { hostById(r, 'converse-settings').props.onPress(); });
|
|
32
|
+
expect(maybeById(r, 'converse-speed')).toHaveLength(0);
|
|
29
33
|
});
|
|
30
34
|
});
|
|
@@ -8,4 +8,7 @@ export { SPEEDS, DEFAULT_SPEED, createSpeedStore } from './speed';
|
|
|
8
8
|
export type { SpeedStore } from './speed';
|
|
9
9
|
export { converseTab } from './tab';
|
|
10
10
|
export { statusLine } from './format';
|
|
11
|
-
export {
|
|
11
|
+
export { StateBanner, stateWord } from './stateBanner';
|
|
12
|
+
export type { DriveAudio } from './stateBanner';
|
|
13
|
+
export { createMockVoice, readMockScenario, MOCK_SCENARIOS } from './mock';
|
|
14
|
+
export type { MockTurn } from './mock';
|
|
@@ -30,8 +30,9 @@ export const dbToLevel = (db: number) => (db <= -100 ? 0 : 10 ** (Math.min(db, 0
|
|
|
30
30
|
/** While the reply plays, the idle recording is thrown away this often so little of the reply's echo precedes a barge-in. */
|
|
31
31
|
export const PLAYING_ROTATE_MS = 3000;
|
|
32
32
|
|
|
33
|
-
/** A
|
|
34
|
-
export const
|
|
33
|
+
/** A start that fails (the first tap after install, a session still settling) is tried again this many times before the error surfaces. */
|
|
34
|
+
export const START_RETRIES = 2;
|
|
35
|
+
export const START_RETRY_MS = 500;
|
|
35
36
|
|
|
36
37
|
export function createMeetingIO(deps: {
|
|
37
38
|
api: NativeMeetingApi;
|
|
@@ -45,6 +46,8 @@ export function createMeetingIO(deps: {
|
|
|
45
46
|
onBroken?: (handler: () => void) => void;
|
|
46
47
|
/** The recorder is echo-cancelled and the player shares its session: the mic stays open while the reply plays, and speech cuts the reply off. */
|
|
47
48
|
duplex?: boolean;
|
|
49
|
+
/** VoiceSession gave up waiting for a paused reply (no device came back): the loop plays it again on the route now active. */
|
|
50
|
+
pauseExpired?: (cb: () => void) => () => void;
|
|
48
51
|
}): MeetingIO<PhoneRecording> {
|
|
49
52
|
const log = (event: string, fields?: Record<string, unknown>) => deps.diag?.log(`meeting.${event}`, fields);
|
|
50
53
|
const now = deps.now ?? Date.now;
|
|
@@ -52,6 +55,18 @@ export function createMeetingIO(deps: {
|
|
|
52
55
|
let broken: (() => void) | null = null;
|
|
53
56
|
deps.onBroken?.(() => broken?.());
|
|
54
57
|
|
|
58
|
+
async function startWithRetry(handlers: Parameters<RecorderAudio['start']>[0]): ReturnType<RecorderAudio['start']> {
|
|
59
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
60
|
+
try {
|
|
61
|
+
return await deps.audio.start(handlers);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (attempt >= START_RETRIES) throw e;
|
|
64
|
+
log('start-retry', { attempt: attempt + 1, error: e instanceof Error ? e.message : String(e) });
|
|
65
|
+
await new Promise((r) => setTimeout(r, START_RETRY_MS));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
55
70
|
return {
|
|
56
71
|
duplex: deps.duplex === true,
|
|
57
72
|
async listen(signal, config, hooks) {
|
|
@@ -71,18 +86,21 @@ export function createMeetingIO(deps: {
|
|
|
71
86
|
let wake: (() => void) | null = null;
|
|
72
87
|
const finish = (why: NonNullable<typeof h.why>) => { if (!h.why) { h.why = why; wake?.(); } };
|
|
73
88
|
const t0 = now();
|
|
89
|
+
/** False when the recorder says voice processing did not turn on: the reply then leaks into the mic and must never count as speech. */
|
|
90
|
+
let echoCancelled = true;
|
|
74
91
|
broken = () => finish('broken');
|
|
75
92
|
// Aborted with reason 'finish' (the mic button): if he was speaking, that is the end of the utterance (it is sent); otherwise a plain stop.
|
|
76
93
|
const onAbort = () => finish(signal.reason === 'finish' && startedAt !== null ? 'end' : 'abort');
|
|
77
94
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
78
95
|
try {
|
|
79
|
-
await
|
|
96
|
+
const started = await startWithRetry({
|
|
80
97
|
onLevel: (db) => {
|
|
81
98
|
const t = now();
|
|
82
99
|
hooks?.onActivity?.();
|
|
83
100
|
// While the reply plays the voice must be louder (config.bargeInLevel): the speaker leaking into the mic is not a barge-in.
|
|
84
101
|
const playing = deps.duplex === true && deps.speaker.getState().phase === 'playing';
|
|
85
|
-
|
|
102
|
+
// Without echo cancellation the reply's own sound is the loudest thing the mic hears: only the tap can cut it off.
|
|
103
|
+
const level = playing && !echoCancelled ? 0 : dbToLevel(db) * (playing ? config.speechLevel / config.bargeInLevel : 1);
|
|
86
104
|
const ev = detector.feed(level, t);
|
|
87
105
|
if (ev?.type === 'start') { startedAt = t; hooks?.onSpeechStart?.(); }
|
|
88
106
|
else if (ev?.type === 'end') finish(ev.reason === 'max' ? 'max' : 'end');
|
|
@@ -90,6 +108,7 @@ export function createMeetingIO(deps: {
|
|
|
90
108
|
else if (startedAt === null && t - t0 >= (playing ? PLAYING_ROTATE_MS : config.idleRotateMs)) finish('rotate');
|
|
91
109
|
},
|
|
92
110
|
});
|
|
111
|
+
if (started && started.echoCancelled === false) { echoCancelled = false; log('barge-in-voice-off', { reason: 'no echo cancellation' }); }
|
|
93
112
|
} catch (e) {
|
|
94
113
|
signal.removeEventListener('abort', onAbort);
|
|
95
114
|
log('start-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
@@ -101,7 +120,9 @@ export function createMeetingIO(deps: {
|
|
|
101
120
|
let file: PhoneRecording | null = null;
|
|
102
121
|
try {
|
|
103
122
|
const stopped = await deps.audio.stop();
|
|
104
|
-
|
|
123
|
+
// No bytes = the empty-file race: nothing to send, record again.
|
|
124
|
+
if ((stopped.bytes ?? 1) > 0) file = { uri: stopped.uri, durationMs: stopped.durationMs };
|
|
125
|
+
else { log('empty-recording'); if (stopped.uri) await discard(stopped.uri); }
|
|
105
126
|
} catch (e) {
|
|
106
127
|
log('stop-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
107
128
|
}
|
|
@@ -123,20 +144,13 @@ export function createMeetingIO(deps: {
|
|
|
123
144
|
const source = await deps.api.replySource(reply);
|
|
124
145
|
let done: () => void = () => undefined;
|
|
125
146
|
const finished = new Promise<void>((resolve) => { done = resolve; });
|
|
126
|
-
// A meeting has no pause button: if iOS paused the reply (AirPods removed, a call) and
|
|
127
|
-
// again on whatever route is now active instead of waiting forever.
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
pausedTimer = setTimeout(() => {
|
|
134
|
-
pausedTimer = null;
|
|
135
|
-
if (signal.aborted || deps.speaker.getState().phase !== 'paused') return;
|
|
136
|
-
log('replay-after-pause');
|
|
137
|
-
void deps.speaker.play(source).catch(() => done());
|
|
138
|
-
}, PAUSED_REPLAY_MS);
|
|
139
|
-
} else if (p.phase !== 'paused') clearPaused();
|
|
147
|
+
// A meeting has no pause button: if iOS paused the reply (AirPods removed, a call) and VoiceSession gave up waiting for it
|
|
148
|
+
// (its pause-timeout), say it again on whatever route is now active instead of waiting forever. The timer is VoiceSession's.
|
|
149
|
+
const unsub = deps.speaker.subscribe((p) => { if (p.phase === 'ended' || p.phase === 'idle' || p.phase === 'failed') done(); });
|
|
150
|
+
const offExpired = deps.pauseExpired?.(() => {
|
|
151
|
+
if (signal.aborted || deps.speaker.getState().phase !== 'paused') return;
|
|
152
|
+
log('replay-after-pause');
|
|
153
|
+
void deps.speaker.play(source).catch(() => done());
|
|
140
154
|
});
|
|
141
155
|
const onAbort = () => { void deps.speaker.stop().catch(() => undefined); done(); };
|
|
142
156
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
@@ -145,7 +159,7 @@ export function createMeetingIO(deps: {
|
|
|
145
159
|
if (!signal.aborted) await finished;
|
|
146
160
|
} finally {
|
|
147
161
|
unsub();
|
|
148
|
-
|
|
162
|
+
offExpired?.();
|
|
149
163
|
signal.removeEventListener('abort', onAbort);
|
|
150
164
|
}
|
|
151
165
|
},
|