Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Audio probe regression dependencies
run: sudo apt-get update -qq && sudo apt-get install -y -q ffmpeg
- name: unit tests (collector, thread, tier2, ui invariants)
run: bun test
- name: QML badge regression (synthetic data, no desktop needed)
Expand All @@ -22,6 +24,12 @@ jobs:
run: |
sudo apt-get install -y -q qml6-module-qtquick-controls qml6-module-qtquick-templates
python3 scripts/test-composer-emoji-ui.py
- name: Inline audio playback and captured play intent
run: |
sudo apt-get install -y -q ffmpeg qml6-module-qtmultimedia qml6-module-qtquick-controls qml6-module-qtquick-templates
python3 scripts/test-audio-ui.py
python3 scripts/test-audio-session-ui.py
python3 scripts/test-audio-loader.py
- name: OTP desktop adapter (no desktop needed)
run: |
python3 -m py_compile otp-desktop.py
Expand Down
151 changes: 151 additions & 0 deletions AudioMessage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import QtQuick
import QtQuick.Controls
import "AudioWaveform.mjs" as AudioWaveform

// One parent-owned playing intent selects the active voice message. Each
// item retains its paused position; a conversation reset stops it entirely.
Rectangle {
id: root
property var playback: null
readonly property var player: playback || idle
QtObject { id: idle; property real position: 0; property real duration: 0; property bool seekable: false; property bool ready: false; property bool decodeFailed: false; property bool actuallyPlaying: false; function seek(ms) {} }
property url source: ""
property var waveform: []
property real durationMs: 0
property bool playing: false
property bool loading: false
property bool failed: false
property int resetToken: 0
property bool muted: false
property bool mine: false
property color fillColor: mine ? "#0a84ff" : "#34343a"
property color textColor: "white"
property string fontFamily: "sans-serif"
property int fontSize: 12
readonly property var bars: AudioWaveform.fitWaveform(waveform, Math.max(1, width - 80))
readonly property real positionMs: player.position
readonly property real totalDurationMs: player.duration > 0 ? player.duration : durationMs
readonly property real progress: AudioWaveform.playbackFraction(positionMs, totalDurationMs)
readonly property bool actuallyPlaying: player.actuallyPlaying
readonly property bool ready: player.ready
readonly property bool seekable: player.seekable
readonly property bool decodeFailed: player.decodeFailed
readonly property bool controlsFocused: playButton.activeFocus || timeline.activeFocus
signal toggleRequested()
signal playbackEnded()
signal playbackFailed()
signal contextRequested()
signal escapeRequested()
Keys.onEscapePressed: root.escapeRequested()

implicitWidth: 268
implicitHeight: 68
radius: 18
color: fillColor
Item {
id: playButton
x: 10; y: (root.height - height) / 2
width: 38; height: 38
activeFocusOnTab: true
Accessible.role: Accessible.Button
Accessible.name: root.loading ? "Loading audio message" : root.failed || root.decodeFailed ? "Retry audio message" : root.playing ? "Pause audio message" : "Play audio message"
Accessible.description: AudioWaveform.durationLabel(root.totalDurationMs)
Accessible.onPressAction: root.toggleRequested()
Rectangle { anchors.fill: parent; radius: width / 2; color: root.textColor; opacity: playButton.activeFocus ? 0.22 : 0.13 }
// Draw playback symbols geometrically, independent of emoji/font glyphs.
Canvas {
id: playSymbol
anchors.centerIn: parent; width: 20; height: 22
visible: !root.playing
onPaint: {
var c = getContext("2d")
c.reset(); c.fillStyle = root.textColor
c.beginPath(); c.moveTo(5, 3); c.lineTo(18, 11); c.lineTo(5, 19); c.closePath(); c.fill()
}
Connections { target: root; function onTextColorChanged() { playSymbol.requestPaint() } }
}
Row {
anchors.centerIn: parent; spacing: 4; visible: root.playing
Rectangle { width: 4; height: 17; radius: 1; color: root.textColor }
Rectangle { width: 4; height: 17; radius: 1; color: root.textColor }
}
TapHandler { onTapped: root.toggleRequested() }
HoverHandler { cursorShape: Qt.PointingHandCursor }
Keys.onSpacePressed: root.toggleRequested()
Keys.onReturnPressed: root.toggleRequested()
Keys.onEnterPressed: root.toggleRequested()
}

Slider {
id: timeline
objectName: "audioTimeline"
x: 58; y: 10
width: Math.max(24, root.width - x - 14); height: 30
from: 0; to: Math.max(1, root.totalDurationMs)
value: root.positionMs
stepSize: 1000
enabled: root.seekable && !root.loading && !root.decodeFailed
activeFocusOnTab: enabled
Accessible.name: "Audio message position"
Accessible.description: (root.bars.length === 0 ? "Waveform unavailable. " : "")
+ AudioWaveform.durationLabel(root.positionMs) + " of " + AudioWaveform.durationLabel(root.totalDurationMs)
onMoved: player.seek(Math.round(value))
background: Item {
x: timeline.leftPadding; y: timeline.topPadding
width: timeline.availableWidth; height: timeline.availableHeight
Row {
anchors.fill: parent
spacing: root.bars.length > 1 ? 2 : 0
Repeater {
model: root.bars
delegate: Rectangle {
required property int index
required property real modelData
width: Math.max(1, (timeline.availableWidth - Math.max(0, root.bars.length - 1) * 2) / Math.max(1, root.bars.length))
height: Math.max(3, modelData * timeline.availableHeight)
y: (timeline.availableHeight - height) / 2
radius: 1.5
color: root.textColor
opacity: (index + 0.5) / root.bars.length <= root.progress ? 1 : 0.38
}
}
}
Rectangle {
visible: root.bars.length === 0
anchors.verticalCenter: parent.verticalCenter
width: parent.width; height: 3; radius: 1.5
color: root.textColor; opacity: 0.3
}
Rectangle {
visible: root.bars.length === 0
anchors.verticalCenter: parent.verticalCenter
width: parent.width * root.progress; height: 3; radius: 1.5
color: root.textColor
}
}
handle: Rectangle {
x: timeline.leftPadding + timeline.visualPosition * Math.max(0, timeline.availableWidth - width)
y: timeline.topPadding - 1
width: 2; height: timeline.availableHeight + 2; radius: 1
visible: timeline.pressed || timeline.activeFocus
color: root.textColor
}
Keys.onLeftPressed: player.seek(Math.max(0, player.position - 5000))
Keys.onRightPressed: player.seek(Math.min(root.totalDurationMs, player.position + 5000))
Keys.onSpacePressed: root.toggleRequested()
Keys.onReturnPressed: root.toggleRequested()
Keys.onEnterPressed: root.toggleRequested()
}
Text {
x: timeline.x + 4; y: 42
width: timeline.width - 8
text: root.loading ? "Loading…" : root.failed || root.decodeFailed ? "Audio unavailable · retry"
: root.totalDurationMs > 0 ? AudioWaveform.durationLabel(Math.max(0, root.totalDurationMs - root.positionMs)) : "Audio message"
textFormat: Text.PlainText
color: root.textColor
opacity: 0.88
font.family: root.fontFamily
font.pixelSize: root.fontSize
}
TapHandler { acceptedButtons: Qt.RightButton; onTapped: root.contextRequested() }
}
36 changes: 36 additions & 0 deletions AudioPlayback.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import QtQuick
import QtMultimedia
Item {
id: root
property url source: ""
property bool playing: false
property bool muted: false
property int resetToken: 0
readonly property real position: player.position
readonly property real duration: player.duration
readonly property bool seekable: player.seekable
readonly property bool actuallyPlaying: player.playbackState === MediaPlayer.PlayingState
readonly property bool ready: player.mediaStatus === MediaPlayer.LoadedMedia || player.mediaStatus === MediaPlayer.BufferedMedia || player.mediaStatus === MediaPlayer.EndOfMedia
readonly property bool decodeFailed: player.error !== MediaPlayer.NoError
signal playbackEnded()
signal playbackFailed()
function seek(ms) { player.position = ms }
onPlayingChanged: {
if (playing && String(source) !== "") {
if (player.mediaStatus === MediaPlayer.EndOfMedia) player.position = 0
player.play()
} else player.pause()
}
onResetTokenChanged: player.stop()
Component.onDestruction: player.stop()
MediaPlayer {
id: player
source: root.source
audioOutput: AudioOutput { muted: root.muted }
onMediaStatusChanged: {
if (mediaStatus === MediaPlayer.LoadedMedia && root.playing) play()
else if (mediaStatus === MediaPlayer.EndOfMedia) root.playbackEnded()
}
onErrorOccurred: root.playbackFailed()
}
}
72 changes: 72 additions & 0 deletions AudioWaveform.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// audio-waveform.ts
var AUDIO_WAVEFORM_BARS = 64;
var AUDIO_SAMPLE_RATE = 24000;
var AUDIO_ANALYSIS_SECONDS = 600;
function normalizeWaveform(value) {
if (!Array.isArray(value) || value.length > 96)
return [];
return value.map((v) => typeof v === "number" && Number.isFinite(v) ? Math.max(0, Math.min(1, v)) : 0);
}
function fitWaveform(value, width) {
const input = normalizeWaveform(value);
if (!input.length || !Number.isFinite(width) || width <= 0)
return [];
const count = Math.min(input.length, Math.max(1, Math.floor(width / 4)));
const output = [];
for (let i = 0;i < count; i++) {
let peak = 0;
for (let j = Math.floor(i * input.length / count);j < Math.floor((i + 1) * input.length / count); j++)
peak = Math.max(peak, input[j]);
output.push(peak);
}
return output;
}
function waveformFromPcm16(bytes, count = AUDIO_WAVEFORM_BARS) {
const samples = Math.floor(bytes.length / 2);
if (!samples || bytes.length > AUDIO_SAMPLE_RATE * AUDIO_ANALYSIS_SECONDS * 2 || !Number.isInteger(count) || count < 1 || count > 96)
return [];
count = Math.min(count, samples);
const bins = [];
let largest = 0;
for (let bin = 0;bin < count; bin++) {
const first = Math.floor(bin * samples / count), last = Math.floor((bin + 1) * samples / count);
let sum = 0;
for (let i = first;i < last; i++) {
const unsigned = bytes[2 * i] | bytes[2 * i + 1] << 8;
const sample = unsigned >= 32768 ? unsigned - 65536 : unsigned;
sum += sample * sample;
}
const rms = Math.sqrt(sum / (last - first));
bins.push(rms);
largest = Math.max(largest, rms);
}
return largest === 0 ? bins : bins.map((v) => Math.round(Math.sqrt(v / largest) * 1000) / 1000);
}
function durationLabel(milliseconds) {
if (!Number.isFinite(milliseconds) || milliseconds < 0)
return "0:00";
const seconds = Math.floor(Math.min(milliseconds, 86400000) / 1000);
const minutes = Math.floor(seconds / 60), remainder = seconds % 60;
return String(minutes) + ":" + (remainder < 10 ? "0" : "") + String(remainder);
}
function playbackFraction(positionMs, durationMs) {
if (!Number.isFinite(positionMs) || !Number.isFinite(durationMs) || durationMs <= 0)
return 0;
return Math.max(0, Math.min(1, positionMs / durationMs));
}
function seekPosition(fraction, durationMs) {
if (!Number.isFinite(fraction) || !Number.isFinite(durationMs) || durationMs <= 0)
return 0;
return Math.round(Math.max(0, Math.min(1, fraction)) * durationMs);
}
export {
AUDIO_ANALYSIS_SECONDS,
AUDIO_SAMPLE_RATE,
AUDIO_WAVEFORM_BARS,
durationLabel,
fitWaveform,
normalizeWaveform,
playbackFraction,
seekPosition,
waveformFromPcm16
};
Loading
Loading