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:
EdisonJwa
2026-05-15 23:05:37 +08:00
parent dfa84ee7bb
commit ba444d94bd
25 changed files with 2519 additions and 178 deletions
@@ -474,6 +474,72 @@ abstract class AppL10n {
/// In en, this message translates to:
/// **'{channels} channels • {clients} online'**
String countChannelsAndClients(int channels, int clients);
/// No description provided for @voiceModePtt.
///
/// In en, this message translates to:
/// **'PTT'**
String get voiceModePtt;
/// No description provided for @voiceModeContinuous.
///
/// In en, this message translates to:
/// **'Continuous'**
String get voiceModeContinuous;
/// No description provided for @voiceModeVoiceActivity.
///
/// In en, this message translates to:
/// **'Voice activity'**
String get voiceModeVoiceActivity;
/// No description provided for @voiceModeComingSoon.
///
/// In en, this message translates to:
/// **'Coming soon'**
String get voiceModeComingSoon;
/// No description provided for @voiceModeLabel.
///
/// In en, this message translates to:
/// **'Transmit mode'**
String get voiceModeLabel;
/// No description provided for @voiceReleaseTailLabel.
///
/// In en, this message translates to:
/// **'Release tail'**
String get voiceReleaseTailLabel;
/// No description provided for @voiceReleaseTailHint.
///
/// In en, this message translates to:
/// **'ms'**
String get voiceReleaseTailHint;
/// No description provided for @voiceLeaveAction.
///
/// In en, this message translates to:
/// **'Leave voice'**
String get voiceLeaveAction;
/// No description provided for @voiceHardMuteLabel.
///
/// In en, this message translates to:
/// **'Mute'**
String get voiceHardMuteLabel;
/// No description provided for @voiceSettingsTitle.
///
/// In en, this message translates to:
/// **'Voice settings'**
String get voiceSettingsTitle;
/// No description provided for @voiceBindKeyAction.
///
/// In en, this message translates to:
/// **'Bind PTT key'**
String get voiceBindKeyAction;
}
class _AppL10nDelegate extends LocalizationsDelegate<AppL10n> {
@@ -229,4 +229,37 @@ class AppL10nEn extends AppL10n {
String countChannelsAndClients(int channels, int clients) {
return '$channels channels • $clients online';
}
@override
String get voiceModePtt => 'PTT';
@override
String get voiceModeContinuous => 'Continuous';
@override
String get voiceModeVoiceActivity => 'Voice activity';
@override
String get voiceModeComingSoon => 'Coming soon';
@override
String get voiceModeLabel => 'Transmit mode';
@override
String get voiceReleaseTailLabel => 'Release tail';
@override
String get voiceReleaseTailHint => 'ms';
@override
String get voiceLeaveAction => 'Leave voice';
@override
String get voiceHardMuteLabel => 'Mute';
@override
String get voiceSettingsTitle => 'Voice settings';
@override
String get voiceBindKeyAction => 'Bind PTT key';
}
@@ -223,4 +223,37 @@ class AppL10nZh extends AppL10n {
String countChannelsAndClients(int channels, int clients) {
return '$channels 个频道 • $clients 在线';
}
@override
String get voiceModePtt => '按键说话';
@override
String get voiceModeContinuous => '持续发送';
@override
String get voiceModeVoiceActivity => '语音激活';
@override
String get voiceModeComingSoon => '即将推出';
@override
String get voiceModeLabel => '发送模式';
@override
String get voiceReleaseTailLabel => '释放延迟';
@override
String get voiceReleaseTailHint => '毫秒';
@override
String get voiceLeaveAction => '离开语音';
@override
String get voiceHardMuteLabel => '静音';
@override
String get voiceSettingsTitle => '语音设置';
@override
String get voiceBindKeyAction => '绑定 PTT 按键';
}