Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(mobile): voice is tap to talk, tap to send

bubu-dudu57fb6614b7e2
diff --git a/mobile/lib/phone/voice_mic_action.dart b/mobile/lib/phone/voice_mic_action.dart
index 7d49adf9a..c26354b3d 100644
--- a/mobile/lib/phone/voice_mic_action.dart
+++ b/mobile/lib/phone/voice_mic_action.dart
@@ -27,12 +27,14 @@ VoiceMicAction voiceMicAction(
TerminalSession session,
) => micHoldsToTalk ? _holdAction(voice, session) : _tapAction(voice, session);
-/// Tap to talk, tap when done, tap to send — [VoiceMicMode.tapToToggle].
+/// Tap to talk, tap Send — [VoiceMicMode.tapToToggle].
///
-/// The second tap does NOT send. It writes what was heard into the terminal's
-/// prompt — [typeIntoPrompt] — so it can be read, and corrected with the
-/// keyboard, before it goes; the arrow that face turns into is the send. `×`
-/// in the pill beside the mic is the way out at every step.
+/// The second tap ends the take, types what was heard into the terminal's
+/// prompt — [typeIntoPrompt] — and presses Return, the same as Enter on the
+/// keyboard. `×` in the pill beside the mic is the way out while it listens.
+///
+/// The arrow face is only left for a Return that did not land: the words are in
+/// the prompt, and the next tap presses it again.
///
/// ⚠️ Tapping while the microphone is still OPENING calls it off rather than
/// writing: there is no take yet, and leaving the recording to start behind
@@ -56,9 +58,7 @@ VoiceMicAction _tapAction(VoiceInputController voice, TerminalSession session) {
),
VoiceInputStatus.listening => _face(
VoiceMicFace.listening,
- onPressed: () => unawaited(
- voice.stage(session, (text) => typeIntoPrompt(session, text)),
- ),
+ onPressed: () => unawaited(_writeAndSend(voice, session)),
),
// Words held from a write or send that did not land: sent as a composer
// turn, which is the one path that does not depend on the prompt.
@@ -79,6 +79,21 @@ VoiceMicAction _tapAction(VoiceInputController voice, TerminalSession session) {
};
}
+/// Ends the take, types its words into [session]'s prompt, and presses Return.
+///
+/// Two steps on the controller rather than one: [VoiceInputController.stage]
+/// is what leaves the words in the prompt, and a Return that does not land
+/// leaves them staged there — the arrow face — for the next tap to send.
+Future<void> _writeAndSend(
+ VoiceInputController voice,
+ TerminalSession session,
+) async {
+ await voice.stage(session, (text) => typeIntoPrompt(session, text));
+ if (voice.isStagedIn(session)) {
+ voice.sendStaged(() => pressEnter(session));
+ }
+}
+
/// Types [text] into the terminal's prompt, as the keyboard would, without
/// pressing Return. False when the terminal is not taking input.
///
@@ -245,7 +260,7 @@ String? voiceActivityLabel(
VoiceInputStatus.listening =>
micHoldsToTalk
? 'Listening… release to send, slide off to cancel'
- : 'Listening… tap ✓ when done',
+ : 'Listening… tap to send',
VoiceInputStatus.transcribing => 'Transcribing…',
VoiceInputStatus.idle || VoiceInputStatus.unavailable => null,
};
diff --git a/mobile/lib/phone/voice_mic_face.dart b/mobile/lib/phone/voice_mic_face.dart
index c48e2d814..0b6bf4e84 100644
--- a/mobile/lib/phone/voice_mic_face.dart
+++ b/mobile/lib/phone/voice_mic_face.dart
@@ -14,11 +14,12 @@ enum VoiceMicFace {
/// The microphone is opening: tap to call it off.
starting,
- /// Recording: tap when done, and what was said is written into the prompt.
- /// It breathes while it listens.
+ /// Recording: tap Send, and what was said is written into the prompt and
+ /// sent. It breathes while it listens.
listening,
- /// What was said is in the prompt, unsent: tap to send it.
+ /// What was said is in the prompt and its Return did not land: tap to send
+ /// it again.
send,
/// Transcribing or sending: nothing to tap until that is back.
@@ -40,6 +41,18 @@ enum VoiceMicFace {
cancelling,
}
+/// The mic's fill for [face].
+///
+/// Cancelling takes the warning colour: the button is about to throw away what
+/// was just said, and that is not something the accent — which everywhere else
+/// in the app means "go" — should be saying.
+///
+/// Listening is the accent's blue: the next tap sends.
+Color voiceMicTint(VoiceMicFace face) => switch (face) {
+ VoiceMicFace.cancelling => AppPalette.warn,
+ _ => AppPalette.accent,
+};
+
/// The round, filled part of the mic: its colour, its glow, and the glyph for
/// what a press will do.
class VoiceMicCore extends StatelessWidget {
@@ -51,11 +64,7 @@ class VoiceMicCore extends StatelessWidget {
final VoiceMicFace face;
final bool lit;
- /// The fill's hue. Cancelling takes the warning colour: the button is about
- /// to throw away what was just said, and that is not something the accent —
- /// which everywhere else in the app means "go" — should be saying.
- Color get _tint =>
- face == VoiceMicFace.cancelling ? AppPalette.warn : AppPalette.accent;
+ Color get _tint => voiceMicTint(face);
@override
Widget build(BuildContext context) => AnimatedContainer(
@@ -145,15 +154,9 @@ class _Glyph extends StatelessWidget {
// whole take and the thumb never leaves it, so there is no second press
// for an arrow to describe.
//
- // ⚠️ In hold-to-talk the arrow would be a lie: nothing is sent by
- // pressing this, it is sent by letting go. The mic stays up for the
- // whole take and the thumb never leaves it, so there is no second press
- // for an arrow to describe.
- //
- // Tap mode: a tick, "done talking" — the tap writes the words into the
- // prompt, it does not send them. The arrow is the NEXT tap's.
- VoiceMicFace.listening =>
- micHoldsToTalk ? LucideIcons.mic300 : LucideIcons.check300,
+ // The mic stays the glyph while it listens; the blue fill is what
+ // says the next tap sends — see [voiceMicTint].
+ VoiceMicFace.listening => LucideIcons.mic300,
VoiceMicFace.send || VoiceMicFace.retry => LucideIcons.arrowUp300,
VoiceMicFace.cancelling => LucideIcons.x300,
VoiceMicFace.off => LucideIcons.micOff300,
@@ -187,7 +190,9 @@ class VoiceMicRing extends StatelessWidget {
height: VoiceMicCore.diameter,
decoration: BoxDecoration(
shape: BoxShape.circle,
- color: AppPalette.accent.withValues(alpha: 0.35 * (1 - t)),
+ color: voiceMicTint(
+ VoiceMicFace.listening,
+ ).withValues(alpha: 0.35 * (1 - t)),
),
),
),
diff --git a/mobile/lib/phone/voice_mic_mode.dart b/mobile/lib/phone/voice_mic_mode.dart
index 68dd7ea88..119a4ce86 100644
--- a/mobile/lib/phone/voice_mic_mode.dart
+++ b/mobile/lib/phone/voice_mic_mode.dart
@@ -6,11 +6,10 @@
/// listens for, the faces it can show, and what a release does — and nothing
/// else in the app branches on it.
enum VoiceMicMode {
- /// Tap to start talking, tap again when done — the words are written into the
- /// terminal's prompt, unsent — and tap a third time to send them. `×` beside
- /// the mic calls the take off, or takes the words back out of the prompt.
- /// The button holds the recording open with nothing held down, so a long
- /// sentence costs no thumb, and nothing is sent before it has been read.
+ /// Tap to start talking, tap Send when done — the words are written into the
+ /// terminal's prompt and Return is pressed. `×` beside the mic calls the take
+ /// off. The button holds the recording open with nothing held down, so a
+ /// long sentence costs no thumb.
///
/// Long-press stays the language shortcut here, because nothing else wants it.
tapToToggle,
diff --git a/mobile/test/voice_mic_fab_test.dart b/mobile/test/voice_mic_fab_test.dart
index 3ea0a7eef..1ae0812fb 100644
--- a/mobile/test/voice_mic_fab_test.dart
+++ b/mobile/test/voice_mic_fab_test.dart
@@ -80,39 +80,21 @@ void main() {
if (type == 'message') payload['content'],
];
- testWidgets('tap, talk, tap: the words are typed into the prompt, unsent', (
+ testWidgets('tap, talk, tap Send: the words are typed and Return pressed', (
tester,
) async {
await pumpFab(tester);
- backend.replies.add('summarise the diff');
+ backend.replies.add('ship it');
await tester.tap(mic);
await tester.pump();
expect(voice.status, VoiceInputStatus.listening);
- await tester.tap(mic);
- await tester.pump();
- await tester.pump();
-
- expect(typed, ['summarise the diff']);
- expect(sentTurns(), isEmpty);
- expect(find.text('Tap ↑ to send'), findsOneWidget);
- await tester.pumpAndSettle();
- });
-
- testWidgets('a third tap sends them with Return', (tester) async {
- await pumpFab(tester);
- backend.replies.add('ship it');
-
- await tester.tap(mic);
- await tester.pump();
- await tester.tap(mic);
- await tester.pump();
- await tester.pump();
await tester.tap(mic);
await tester.pumpAndSettle();
expect(typed, ['ship it', '\r']);
+ expect(sentTurns(), isEmpty);
expect(voice.isIdle, isTrue);
expect(find.text('Tap ↑ to send'), findsNothing);
});
@@ -132,25 +114,6 @@ void main() {
expect(voice.isIdle, isTrue);
});
- testWidgets('× once the words are typed takes them back out', (tester) async {
- await pumpFab(tester);
- backend.replies.add('xin chào');
-
- await tester.tap(mic);
- await tester.pump();
- await tester.tap(mic);
- await tester.pump();
- await tester.pump();
- await tester.tap(cancel);
- await tester.pumpAndSettle();
-
- // One Backspace per character, counted in runes.
- expect(typed.first, 'xin chào');
- expect(typed.skip(1), List.filled('xin chào'.runes.length, '\x7f'));
- expect(frames, isEmpty);
- expect(voice.isIdle, isTrue);
- });
-
testWidgets('no talking while the terminal takes no input', (tester) async {
session.status = TerminalSessionStatus.takenOver;
await pumpFab(tester);