feat(beta): wire voice in/out end-to-end with push-to-talk (v0.2.0-beta.1)
Reaches the Internal Beta milestone of DEC-001's release sequence the
same day as Alpha. Adds voice capture and playback through the full
Flutter UI → FRB → Rust core → tsclientlib → server path.
Promotions from PoC:
poc/audio-capture-playback-spike → crates/chanora_audio/
New product code:
crates/chanora_audio/src/engine.rs — cpal capture and playback,
audiopus Opus VoIP encoder (48 kHz mono 20 ms frames), tsclientlib
AudioHandler for decode + jitter buffer + mix on playback,
push-to-talk gate, graceful playback-only fallback when capture
is unavailable.
crates/chanora_protocol/src/adapter.rs — extended with
voice_out_tx (clonable mpsc::Sender<OutPacket>) and
take_voice_in() (one-shot mpsc::Receiver<InboundVoice>); main
loop now interleaves outbound voice drain, event pumping, and
control-request handling.
crates/chanora_protocol/src/lib.rs — re-exports the few
tsproto_packets types (OutAudio, OutPacket, InAudioBuf,
AudioData, CodecType, Direction) that chanora_audio
legitimately needs. Documented as the single deliberate
cross-crate type re-export per SAD-067, justified by the
performance cost of a parallel type hierarchy on the 20 ms
voice frame.
core/chanora_core/src/lib.rs — ChanoraSession::start_audio,
set_ptt, audio_stats; disconnect now stops the engine first.
crates/chanora_bridge/src/api.rs — startAudio, setPtt,
audioStats commands and BridgeAudioStats DTO.
apps/chanora_flutter/lib/main.dart — "Start audio" button +
hold-to-talk PTT button with pressed/released visual state +
live stats line (TX/RX/PTT). Stats polled every 500 ms.
ARB:
Both en and zh-Hans gain startAudioAction, pttHoldToTalk,
pttTransmitting, audioStatsLine. Banner updated to
"Beta build — voice in/out wired; not production ready."
FRB config:
flutter_rust_bridge.yaml gains local: true so codegen resolves
the workspace member's library stem to "chanora_bridge" instead
of falling back to "UNKNOWN".
Empirical verification (2026-05-14, against cn.teamspeak.app):
cargo check + cargo test --workspace: all green.
flutter analyze: 0 issues.
flutter test: 4/4 passing including:
- test/alpha_e2e_test.dart (regression: Alpha still works)
- test/beta_e2e_test.dart (Beta: connect → startAudio →
PTT cycle → disconnect against cn.teamspeak.app).
Live smoke (cargo test alpha_smoke -- --ignored): 49 channels,
37 clients retrieved.
Capture stream open against the host PipeWire auto_null source
refused (snd_pcm_hw_params); engine correctly logged the warning
and continued in playback-only mode. TX=0 frames, RX=0 frames
reflects the headless null-source environment; on a real mic
host the encoder produces ~50 frames/second while PTT is held.
Honest Beta scope (NOT in this release):
- AEC / AGC / NS / HPF DSP (DEC-007..010): AudioEffects exists
as a struct but the filters are no-ops. Beta+ work.
- Production-quality resampler: current code is linear
interpolation. Beta+ work.
- Identity persistence via chanora_storage: still ephemeral.
- Push-to-Dart event stream: UI polls instead.
- chanora_diagnostics tracing-layer wiring: still scaffold.
- Mobile (Android) cdylib + UI: PoC-proven, not yet in product.
- Reconnect / network-loss recovery for the voice path.
Docs updates:
- docs/governance/product-decision-register.md bumped to v0.9.7
(Beta-milestone change-history entry; no row changes).
- docs/governance/poc-results-summary.md bumped to v0.6.0
(RISK-PoC-005 updated with Beta progress).
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
// Chanora Flutter application entry point — Alpha build.
|
||||
// Chanora Flutter application — Beta build (v0.2.0-beta.1).
|
||||
//
|
||||
// Wires the Alpha UI: server-address + nickname form, connect button,
|
||||
// channel tree, disconnect. All names from server-side state are
|
||||
// preserved verbatim per ADR-008 / DEC-015.
|
||||
// Adds voice in/out via push-to-talk on top of the Alpha UI:
|
||||
// 1. Connect form + channel/client tree (Alpha)
|
||||
// 2. "Start audio" button after connect → opens the audio engine
|
||||
// 3. Push-to-talk button: hold to transmit, release to stop
|
||||
// 4. Live audio stats line (TX/RX frame counts)
|
||||
//
|
||||
// Audio rendering on the speaker is automatic once the engine
|
||||
// starts; nothing to wire on the Dart side beyond that.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -27,35 +34,36 @@ class ChanoraApp extends StatelessWidget {
|
||||
useMaterial3: true,
|
||||
colorSchemeSeed: const Color(0xFF3F51B5),
|
||||
),
|
||||
// DEC-015 (register v0.9.5): English + Chinese Simplified at MVP.
|
||||
localizationsDelegates: AppL10n.localizationsDelegates,
|
||||
supportedLocales: AppL10n.supportedLocales,
|
||||
home: const _AlphaHome(),
|
||||
home: const _BetaHome(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Three-state UI: idle / connecting / connected. Errors collapse
|
||||
/// back to idle with the message captured.
|
||||
class _AlphaHome extends StatefulWidget {
|
||||
const _AlphaHome();
|
||||
|
||||
@override
|
||||
State<_AlphaHome> createState() => _AlphaHomeState();
|
||||
}
|
||||
|
||||
enum _Phase { idle, connecting, connected }
|
||||
|
||||
class _AlphaHomeState extends State<_AlphaHome> {
|
||||
class _BetaHome extends StatefulWidget {
|
||||
const _BetaHome();
|
||||
|
||||
@override
|
||||
State<_BetaHome> createState() => _BetaHomeState();
|
||||
}
|
||||
|
||||
class _BetaHomeState extends State<_BetaHome> {
|
||||
final _hostCtl = TextEditingController(text: 'cn.teamspeak.app');
|
||||
final _nickCtl = TextEditingController(text: 'ChanoraAlpha');
|
||||
final _nickCtl = TextEditingController(text: 'ChanoraBeta');
|
||||
|
||||
_Phase _phase = _Phase.idle;
|
||||
rust.BridgeSnapshot? _snapshot;
|
||||
String? _error;
|
||||
bool _audioStarted = false;
|
||||
rust.BridgeAudioStats? _audioStats;
|
||||
Timer? _statsTimer;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_statsTimer?.cancel();
|
||||
_hostCtl.dispose();
|
||||
_nickCtl.dispose();
|
||||
super.dispose();
|
||||
@@ -86,6 +94,34 @@ class _AlphaHomeState extends State<_AlphaHome> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onStartAudio() async {
|
||||
try {
|
||||
await rust.startAudio();
|
||||
if (!mounted) return;
|
||||
setState(() => _audioStarted = true);
|
||||
_statsTimer?.cancel();
|
||||
_statsTimer = Timer.periodic(const Duration(milliseconds: 500), (_) async {
|
||||
try {
|
||||
final s = await rust.audioStats();
|
||||
if (!mounted) return;
|
||||
setState(() => _audioStats = s);
|
||||
} catch (_) {}
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _error = e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setPtt(bool active) async {
|
||||
try {
|
||||
await rust.setPtt(active: active);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _error = e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefresh() async {
|
||||
try {
|
||||
final snap = await rust.snapshot();
|
||||
@@ -98,15 +134,17 @@ class _AlphaHomeState extends State<_AlphaHome> {
|
||||
}
|
||||
|
||||
Future<void> _onDisconnect() async {
|
||||
_statsTimer?.cancel();
|
||||
_statsTimer = null;
|
||||
try {
|
||||
await rust.disconnect();
|
||||
} catch (_) {
|
||||
// Best-effort. Even if disconnect throws we drop back to idle.
|
||||
}
|
||||
} catch (_) {}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_phase = _Phase.idle;
|
||||
_snapshot = null;
|
||||
_audioStarted = false;
|
||||
_audioStats = null;
|
||||
_error = null;
|
||||
});
|
||||
}
|
||||
@@ -150,7 +188,6 @@ class _AlphaHomeState extends State<_AlphaHome> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Banner
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
@@ -163,7 +200,6 @@ class _AlphaHomeState extends State<_AlphaHome> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// Status
|
||||
Text(statusText(), style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 12),
|
||||
if (_phase == _Phase.idle) ...[
|
||||
@@ -173,11 +209,29 @@ class _AlphaHomeState extends State<_AlphaHome> {
|
||||
onConnect: _onConnect,
|
||||
),
|
||||
] else if (_phase == _Phase.connecting) ...[
|
||||
const Center(child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: CircularProgressIndicator(),
|
||||
)),
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
] else if (_phase == _Phase.connected && _snapshot != null) ...[
|
||||
// Audio row: start button or stats + PTT.
|
||||
if (!_audioStarted) ...[
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.mic_none),
|
||||
label: Text(l10n.startAudioAction),
|
||||
onPressed: _onStartAudio,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
] else ...[
|
||||
_AudioControls(
|
||||
stats: _audioStats,
|
||||
onPttDown: () => _setPtt(true),
|
||||
onPttUp: () => _setPtt(false),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
Expanded(child: _SnapshotView(snapshot: _snapshot!)),
|
||||
],
|
||||
],
|
||||
@@ -230,6 +284,91 @@ class _ConnectForm extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _AudioControls extends StatefulWidget {
|
||||
const _AudioControls({
|
||||
required this.stats,
|
||||
required this.onPttDown,
|
||||
required this.onPttUp,
|
||||
});
|
||||
|
||||
final rust.BridgeAudioStats? stats;
|
||||
final VoidCallback onPttDown;
|
||||
final VoidCallback onPttUp;
|
||||
|
||||
@override
|
||||
State<_AudioControls> createState() => _AudioControlsState();
|
||||
}
|
||||
|
||||
class _AudioControlsState extends State<_AudioControls> {
|
||||
bool _pressed = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppL10n.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final stats = widget.stats;
|
||||
final statsText = stats == null
|
||||
? '—'
|
||||
: l10n.audioStatsLine(
|
||||
stats.framesSent,
|
||||
stats.framesReceived,
|
||||
stats.pttActive ? 'on' : 'off',
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Listener(
|
||||
onPointerDown: (_) {
|
||||
setState(() => _pressed = true);
|
||||
widget.onPttDown();
|
||||
},
|
||||
onPointerUp: (_) {
|
||||
setState(() => _pressed = false);
|
||||
widget.onPttUp();
|
||||
},
|
||||
onPointerCancel: (_) {
|
||||
setState(() => _pressed = false);
|
||||
widget.onPttUp();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: _pressed
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
_pressed ? Icons.mic : Icons.mic_off,
|
||||
color: _pressed
|
||||
? theme.colorScheme.onPrimary
|
||||
: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_pressed ? l10n.pttTransmitting : l10n.pttHoldToTalk,
|
||||
style: TextStyle(
|
||||
color: _pressed
|
||||
? theme.colorScheme.onPrimary
|
||||
: theme.colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(statsText, style: theme.textTheme.bodySmall),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SnapshotView extends StatelessWidget {
|
||||
const _SnapshotView({required this.snapshot});
|
||||
|
||||
@@ -243,7 +382,6 @@ class _SnapshotView extends StatelessWidget {
|
||||
final channels = [...snapshot.channels]
|
||||
..sort((a, b) => a.order.compareTo(b.order));
|
||||
|
||||
// Index clients by channel id for the tree view.
|
||||
final byChannel = <BigInt, List<rust.BridgeClient>>{};
|
||||
for (final c in snapshot.clients) {
|
||||
byChannel.putIfAbsent(c.channel, () => []).add(c);
|
||||
@@ -252,7 +390,10 @@ class _SnapshotView extends StatelessWidget {
|
||||
return ListView(
|
||||
children: [
|
||||
Text(
|
||||
l10n.countChannelsAndClients(snapshot.channels.length, snapshot.clients.length),
|
||||
l10n.countChannelsAndClients(
|
||||
snapshot.channels.length,
|
||||
snapshot.clients.length,
|
||||
),
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
if (snapshot.welcomeMessage.isNotEmpty) ...[
|
||||
|
||||
Reference in New Issue
Block a user