feat(audio,bridge,flutter): v1 audio + PTT lifecycle implementation (SDD-094..097)
Implement the SDD-094 / SDD-095 / SDD-096 / SDD-097 detailed designs
committed in dfa84ee.
Rust side
- chanora_audio::TransmitMode enum (Ptt/Continuous/VoiceActivity) with
serde-friendly u8 repr (SDD-095).
- chanora_audio::TransmitModeSelector: lock-free Atomic-backed selector
that is the sole writer of transmit_active (per SAD-083), applying
hard_mute as a final clamp. VoiceActivity falls through to Continuous
for v1 (DEC-030 placeholder).
- chanora_audio::ReleaseTailTimer: tokio-task-owning struct driving the
selector's ptt_held input; default 200 ms tail, configurable 0–500 ms
with AtomicU32 hot read; pending JoinHandle held in a std::sync::Mutex
touched only on PTT edge transitions (SDD-096).
- chanora_storage: AudioMeta persisted as audio_meta.json next to
identity.dek; get/set_transmit_mode + get/set_release_tail_ms with
0..=500 clamp on write.
- chanora_core::ChanoraSession: voice_join(channel, password) and
voice_leave() are the new lifecycle entry points; ensure_audio_running
and shutdown_audio_if_idle are private helpers around the existing
Option<AudioEngine> field. SessionEvent::VoiceState carries the
in_channel / transmit_mode / mute / release_tail_ms tuple. Selector
state survives reconnect; supervisor rewires it to each fresh engine
gate.
- chanora_bridge: drop start_audio; add voice_join, voice_leave,
set/get_transmit_mode, set/get_release_tail_ms, set_hard_mute.
BridgeEvent::VoiceState mirrors the core event. AudioStarted/Stopped
kept for backwards compat but Flutter ignores them in the new UI.
Flutter side
- New apps/chanora_flutter/lib/widgets/voice_bar.dart replaces the
legacy _AudioControls widget. Renders channel pill, mode badge,
mute toggle, level meter, PttCapabilityBadge, leave button. No
manual Start affordance anywhere.
- New apps/chanora_flutter/lib/widgets/voice_settings.dart dialog with
TransmitMode radio group (VoiceActivity disabled with 'Coming soon'
trailing label per DEC-030), bind-key button, release-tail slider
0–500 ms step 25.
- main.dart: state fields _inChannel, _transmitMode, _hardMute,
_releaseTailMs driven by BridgeEvent_VoiceState. Channel-tap now
calls voiceJoin instead of moveToChannel. Removed _onStartAudio,
_audioStarted-gated branch, and the FilledButton.
- l10n: 11 new strings in app_en.arb + app_zh.arb.
Verification
- cargo check --workspace: clean.
- cargo test --workspace --lib: 72 passed / 0 failed / 1 ignored
(chanora_audio: +12 new tests for TransmitMode/Selector/ReleaseTail;
chanora_storage: +2 new tests for audio_meta round-trip).
- flutter analyze: 0 errors, 0 warnings; 6 infos are the Flutter 3.32
Radio.groupValue deprecation (pre-existing API usage).
- FRB Dart/Rust bindings regenerated via flutter_rust_bridge_codegen.
Follow-up (intentionally deferred)
- PttController and per-platform PTT backends still drive AudioTransmitGate
directly via the legacy set_ptt path; routing those key edges through
ChanoraSession::release_tail_timer().{key_down,key_up} so the tail
applies to native PTT input is a contained wiring change in a follow-up.
- Real audio-level RMS in BridgeAudioStats (current meter is binary).
- VoiceActivity backend (DEC-030).
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
// Voice bar widget (SDD-097). Replaces the legacy `_AudioControls`
|
||||
// block that used to live in `main.dart`. Driven by the
|
||||
// `BridgeEvent::VoiceState` stream the bridge publishes from the
|
||||
// core's transmit-mode selector + release-tail timer.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/generated/app_localizations.dart';
|
||||
import '../main.dart' show PttCapabilityBadge;
|
||||
import '../src/rust/api.dart' as rust;
|
||||
|
||||
/// Voice bar — surfaces the live voice state, mode badge, hard-mute
|
||||
/// toggle, level meter, and a leave-channel affordance.
|
||||
class VoiceBar extends StatelessWidget {
|
||||
/// Construct a voice bar.
|
||||
const VoiceBar({
|
||||
super.key,
|
||||
required this.inChannel,
|
||||
required this.transmitMode,
|
||||
required this.hardMute,
|
||||
required this.releaseTailMs,
|
||||
required this.channelName,
|
||||
required this.audioStats,
|
||||
required this.pttLevel,
|
||||
required this.pttBackendId,
|
||||
required this.pttBoundInputClass,
|
||||
required this.pttBoundKeyLabel,
|
||||
required this.onToggleMute,
|
||||
required this.onConfigure,
|
||||
required this.onLeave,
|
||||
});
|
||||
|
||||
/// True when the session is currently joined to a voice channel.
|
||||
final bool inChannel;
|
||||
|
||||
/// Active transmit mode.
|
||||
final rust.BridgeTransmitMode transmitMode;
|
||||
|
||||
/// Hard-mute clamp state.
|
||||
final bool hardMute;
|
||||
|
||||
/// Configured release-tail in milliseconds (0..=500). Surfaced as
|
||||
/// a hint underneath the mode badge.
|
||||
final int releaseTailMs;
|
||||
|
||||
/// Channel display name to show in the channel-name pill. Empty
|
||||
/// string suppresses the pill (typically when `!inChannel`).
|
||||
final String channelName;
|
||||
|
||||
/// Audio statistics (TX/RX frames + ptt_active) to drive the
|
||||
/// level meter. Pass `null` to render an idle meter.
|
||||
final rust.BridgeAudioStats? audioStats;
|
||||
|
||||
/// PTT capability badge inputs — passed through to
|
||||
/// [`PttCapabilityBadge`].
|
||||
final String pttLevel;
|
||||
|
||||
/// Backend id, e.g. `focused`, `windows-raw-input`.
|
||||
final String pttBackendId;
|
||||
|
||||
/// Coarse bound input class.
|
||||
final String pttBoundInputClass;
|
||||
|
||||
/// Platform-neutral key label captured by the binding dialog.
|
||||
final String pttBoundKeyLabel;
|
||||
|
||||
/// Toggle the hard-mute clamp.
|
||||
final VoidCallback onToggleMute;
|
||||
|
||||
/// Open the voice settings dialog.
|
||||
final VoidCallback onConfigure;
|
||||
|
||||
/// Leave the voice channel.
|
||||
final VoidCallback onLeave;
|
||||
|
||||
String _modeLabel(AppL10n l10n) {
|
||||
switch (transmitMode) {
|
||||
case rust.BridgeTransmitMode.ptt:
|
||||
final key = pttBoundKeyLabel.isEmpty ? '—' : pttBoundKeyLabel;
|
||||
return '${l10n.voiceModePtt}: $key';
|
||||
case rust.BridgeTransmitMode.continuous:
|
||||
return l10n.voiceModeContinuous;
|
||||
case rust.BridgeTransmitMode.voiceActivity:
|
||||
return '${l10n.voiceModeVoiceActivity} (${l10n.voiceModeComingSoon})';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppL10n.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final stats = audioStats;
|
||||
final levelActive = stats?.pttActive ?? false;
|
||||
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Row 1: channel pill + mute toggle
|
||||
Row(
|
||||
children: [
|
||||
if (inChannel && channelName.isNotEmpty) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.tag,
|
||||
size: 14,
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
channelName,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
tooltip: l10n.voiceHardMuteLabel,
|
||||
icon: Icon(hardMute ? Icons.mic_off : Icons.mic),
|
||||
isSelected: hardMute,
|
||||
selectedIcon: const Icon(Icons.mic_off),
|
||||
onPressed: onToggleMute,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// Row 2: mode badge
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
transmitMode == rust.BridgeTransmitMode.ptt
|
||||
? Icons.radio_button_checked
|
||||
: Icons.podcasts,
|
||||
size: 16,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_modeLabel(l10n),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.tune, size: 16),
|
||||
label: Text(l10n.voiceSettingsTitle),
|
||||
onPressed: onConfigure,
|
||||
),
|
||||
],
|
||||
),
|
||||
// Row 3: release tail hint (only meaningful for PTT mode)
|
||||
if (transmitMode == rust.BridgeTransmitMode.ptt)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 22, top: 2),
|
||||
child: Text(
|
||||
'${l10n.voiceReleaseTailLabel}: $releaseTailMs${l10n.voiceReleaseTailHint}',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// Row 4: level meter
|
||||
_LevelMeter(active: levelActive),
|
||||
const SizedBox(height: 4),
|
||||
if (stats != null)
|
||||
Text(
|
||||
l10n.audioStatsLine(
|
||||
stats.framesSent,
|
||||
stats.framesReceived,
|
||||
stats.pttActive ? 'on' : 'off',
|
||||
),
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// PTT capability badge
|
||||
PttCapabilityBadge(
|
||||
level: pttLevel,
|
||||
backendId: pttBackendId,
|
||||
boundInputClass: pttBoundInputClass,
|
||||
boundKeyLabel: pttBoundKeyLabel,
|
||||
onConfigure: onConfigure,
|
||||
),
|
||||
if (inChannel) ...[
|
||||
const SizedBox(height: 6),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: TextButton.icon(
|
||||
icon: const Icon(Icons.call_end),
|
||||
label: Text(l10n.voiceLeaveAction),
|
||||
onPressed: onLeave,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LevelMeter extends StatelessWidget {
|
||||
const _LevelMeter({required this.active});
|
||||
|
||||
final bool active;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: FractionallySizedBox(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
widthFactor: active ? 0.75 : 0.05,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: active
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.outlineVariant,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// Voice settings dialog (SDD-097). Surfaces a TransmitMode radio
|
||||
// group, a bind-key button, and a release-tail slider.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/generated/app_localizations.dart';
|
||||
import '../src/rust/api.dart' as rust;
|
||||
|
||||
/// Result returned by [`VoiceSettingsDialog`]. `null` indicates a
|
||||
/// cancelled dialog.
|
||||
class VoiceSettingsResult {
|
||||
/// Construct a result snapshot.
|
||||
const VoiceSettingsResult({
|
||||
required this.mode,
|
||||
required this.releaseTailMs,
|
||||
required this.bindKeyRequested,
|
||||
});
|
||||
|
||||
/// Selected transmit mode.
|
||||
final rust.BridgeTransmitMode mode;
|
||||
|
||||
/// Chosen release-tail in milliseconds (0..=500, step 25).
|
||||
final int releaseTailMs;
|
||||
|
||||
/// True when the user tapped the "bind key" button. The caller
|
||||
/// is expected to open the focus-scoped capture dialog
|
||||
/// afterwards.
|
||||
final bool bindKeyRequested;
|
||||
}
|
||||
|
||||
/// Voice settings dialog widget.
|
||||
class VoiceSettingsDialog extends StatefulWidget {
|
||||
/// Construct a dialog seeded with the current settings.
|
||||
const VoiceSettingsDialog({
|
||||
super.key,
|
||||
required this.initialMode,
|
||||
required this.initialReleaseTailMs,
|
||||
});
|
||||
|
||||
/// Currently active transmit mode.
|
||||
final rust.BridgeTransmitMode initialMode;
|
||||
|
||||
/// Currently configured release tail in milliseconds.
|
||||
final int initialReleaseTailMs;
|
||||
|
||||
@override
|
||||
State<VoiceSettingsDialog> createState() => _VoiceSettingsDialogState();
|
||||
}
|
||||
|
||||
class _VoiceSettingsDialogState extends State<VoiceSettingsDialog> {
|
||||
late rust.BridgeTransmitMode _mode;
|
||||
late double _releaseTail;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_mode = widget.initialMode;
|
||||
_releaseTail = widget.initialReleaseTailMs.clamp(0, 500).toDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppL10n.of(context);
|
||||
final theme = Theme.of(context);
|
||||
return AlertDialog(
|
||||
title: Text(l10n.voiceSettingsTitle),
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.voiceModeLabel,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
RadioListTile<rust.BridgeTransmitMode>(
|
||||
dense: true,
|
||||
value: rust.BridgeTransmitMode.ptt,
|
||||
groupValue: _mode,
|
||||
title: Text(l10n.voiceModePtt),
|
||||
onChanged: (v) => setState(() => _mode = v!),
|
||||
),
|
||||
RadioListTile<rust.BridgeTransmitMode>(
|
||||
dense: true,
|
||||
value: rust.BridgeTransmitMode.continuous,
|
||||
groupValue: _mode,
|
||||
title: Text(l10n.voiceModeContinuous),
|
||||
onChanged: (v) => setState(() => _mode = v!),
|
||||
),
|
||||
RadioListTile<rust.BridgeTransmitMode>(
|
||||
dense: true,
|
||||
value: rust.BridgeTransmitMode.voiceActivity,
|
||||
groupValue: _mode,
|
||||
title: Text(l10n.voiceModeVoiceActivity),
|
||||
secondary: Text(
|
||||
l10n.voiceModeComingSoon,
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
// VoiceActivity is reserved per DEC-030 — keep the
|
||||
// tile visible but disabled per SDD-095.
|
||||
onChanged: null,
|
||||
),
|
||||
const Divider(),
|
||||
OutlinedButton.icon(
|
||||
icon: const Icon(Icons.keyboard),
|
||||
label: Text(l10n.voiceBindKeyAction),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(
|
||||
VoiceSettingsResult(
|
||||
mode: _mode,
|
||||
releaseTailMs: _releaseTail.round(),
|
||||
bindKeyRequested: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.voiceReleaseTailLabel,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: _releaseTail,
|
||||
min: 0,
|
||||
max: 500,
|
||||
divisions: 20, // step 25 ms
|
||||
label: '${_releaseTail.round()}${l10n.voiceReleaseTailHint}',
|
||||
onChanged: (v) => setState(() => _releaseTail = v),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'${_releaseTail.round()}${l10n.voiceReleaseTailHint}',
|
||||
style: theme.textTheme.bodySmall,
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(l10n.closeAction),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(
|
||||
VoiceSettingsResult(
|
||||
mode: _mode,
|
||||
releaseTailMs: _releaseTail.round(),
|
||||
bindKeyRequested: false,
|
||||
),
|
||||
),
|
||||
child: Text(l10n.pttConfigureSaveAction),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user