mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
* feat(voice): universal talk waveform driven by real audio levels One shared Siri-style talk animation across iOS, watchOS, macOS, and Android (TalkWaveformView + exact Compose port), replacing per-platform fakes: synthetic speaking pulses, constant speech-detected power, static Android bar rows, flat realtime listening. Listening/recording follow live mic levels on every route; agent speech follows the real playback envelope (AVAudioPlayer metering + playback-aligned PCM envelope + WebRTC stats); voice-note recording shows a live capture wave. * fix(android): order waveform imports and sync native i18n inventory * chore(i18n): resync native inventory after rebase
110 lines
3.6 KiB
Swift
110 lines
3.6 KiB
Swift
import SwiftUI
|
|
|
|
/// Host-provided voice-note recording state for the shared chat composer.
|
|
public struct OpenClawChatVoiceNoteControl {
|
|
public var recorder: OpenClawVoiceNoteRecorder
|
|
public var isTalkActive: Bool
|
|
|
|
public init(recorder: OpenClawVoiceNoteRecorder, isTalkActive: Bool) {
|
|
self.recorder = recorder
|
|
self.isTalkActive = isTalkActive
|
|
}
|
|
}
|
|
|
|
struct OpenClawVoiceNoteButton: View {
|
|
let control: OpenClawChatVoiceNoteControl
|
|
let compact: Bool
|
|
let isComposerEnabled: Bool
|
|
let isAttachmentInputEnabled: Bool
|
|
|
|
var isRecordingEnabled: Bool {
|
|
self.isComposerEnabled
|
|
&& self.isAttachmentInputEnabled
|
|
&& !self.control.isTalkActive
|
|
&& !self.control.recorder.isRequestingPermission
|
|
}
|
|
|
|
var body: some View {
|
|
Button {
|
|
Task { await self.control.recorder.start() }
|
|
} label: {
|
|
if self.control.recorder.isRequestingPermission {
|
|
ProgressView()
|
|
.controlSize(.mini)
|
|
} else {
|
|
Image(systemName: "mic")
|
|
.font(OpenClawChatTypography.display(size: 15, weight: .semibold, relativeTo: .subheadline))
|
|
}
|
|
}
|
|
.help("Record Voice Note")
|
|
.accessibilityLabel("Record voice note")
|
|
.accessibilityIdentifier("chat-voice-note-record")
|
|
.modifier(VoiceNoteButtonChrome(compact: self.compact))
|
|
.controlSize(.small)
|
|
.foregroundStyle(.secondary)
|
|
.contentShape(Rectangle())
|
|
.disabled(!self.isRecordingEnabled)
|
|
}
|
|
}
|
|
|
|
struct OpenClawVoiceNoteRecordingRow: View {
|
|
let recorder: OpenClawVoiceNoteRecorder
|
|
|
|
var body: some View {
|
|
HStack(spacing: 10) {
|
|
Circle()
|
|
.fill(OpenClawChatTheme.danger)
|
|
.frame(width: 9, height: 9)
|
|
|
|
// Live capture wave replaces a static "Recording" label; the level is
|
|
// real recorder metering, so silence reads flat and speech moves.
|
|
TalkWaveformView(phase: .listening(level: self.recorder.level, speechActive: false))
|
|
.frame(maxWidth: .infinity, minHeight: 26, maxHeight: 26)
|
|
.accessibilityLabel("Recording")
|
|
|
|
Text(openClawVoiceNoteDurationLabel(self.recorder.elapsedSeconds))
|
|
.font(OpenClawChatTypography.mono(size: 13, relativeTo: .footnote))
|
|
.foregroundStyle(.secondary)
|
|
|
|
Spacer(minLength: 8)
|
|
|
|
Button {
|
|
self.recorder.cancel()
|
|
} label: {
|
|
Image(systemName: "xmark")
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.controlSize(.small)
|
|
.accessibilityLabel("Cancel voice note")
|
|
|
|
Button {
|
|
self.recorder.finish()
|
|
} label: {
|
|
Image(systemName: "checkmark")
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.controlSize(.small)
|
|
.accessibilityLabel("Finish voice note")
|
|
}
|
|
.padding(.horizontal, 14)
|
|
.padding(.vertical, 10)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 14, style: .continuous)
|
|
.fill(OpenClawChatTheme.composerField)
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 14, style: .continuous)
|
|
.strokeBorder(OpenClawChatTheme.composerBorder)))
|
|
}
|
|
}
|
|
|
|
private struct VoiceNoteButtonChrome: ViewModifier {
|
|
let compact: Bool
|
|
|
|
func body(content: Content) -> some View {
|
|
if self.compact {
|
|
content.buttonStyle(.plain)
|
|
} else {
|
|
content.buttonStyle(.bordered)
|
|
}
|
|
}
|
|
}
|