Matthew-DWM opened a new pull request, #9146:
URL: https://github.com/apache/texera/pull/9146

   ### What changes were proposed in this PR?
   
   Adds the **Audio Attribute Extractor** operator (Utilities), which turns 
audio files into time series that the rest of a workflow can filter, aggregate, 
join and chart. The user picks a binary column holding WAV, MP3 or FLAC files 
and one attribute to measure; each file becomes rows of `x` (time in seconds), 
`y` (the value) and `series` (the attribute's name).
   
   | Attribute | `y` | Typical use |
   |---|---|---|
   | `waveform` | the signal itself | see the shape of a recording |
   | `rms` | loudness of each frame | find loud and quiet passages |
   | `zcr` | zero-crossing rate of each frame | tell noise and hiss from tones |
   | `pitch_hz` | pitch, 60–1000 Hz; empty when unvoiced | follow a voice or a 
melody |
   | `onsets` | 1.0 at each new sound | count notes or sound events |
   | `beats` | 1.0 at each beat | measure tempo |
   
   Other settings: **Sample Rate**, **Frame Length** and **Hop Length** (shown 
only for rms, zcr and pitch_hz), **Max Points** and **Max Duration** per file, 
**Retain Input Columns** (carries the filename and other columns onto every 
row, so many files can be compared) and **Skip Unreadable Files**.
   
   #### How it works
   
   ```
    File Scan  (a binary or large binary column, one row per audio file)
        │
        ▼
    ┌─ Audio Attribute Extractor ──────────────────────────────────────────────┐
    │                                                                          │
    │  1. decode     WAV, MP3 or FLAC with miniaudio, streamed in blocks       │
    │  2. normalize  mix to mono, resample to Sample Rate (SciPy polyphase)    │
    │  3. measure    rms · zcr · pitch_hz   on Frame/Hop windows               │
    │                waveform               the loudest sample of each slice   │
    │                onsets · beats         on a fixed ~23 ms grid             │
    │  4. emit       one row per point, up to Max Points per file              │
    │                                                                          │
    └──────────────────────────────────────────────────────────────────────────┘
        │  x (seconds), y, series   + the input's other columns, if retained
        ▼
    Line Chart · Scatter Plot · Aggregate · Hash Join · …
   ```
   
   Like the other Python operators, the descriptor checks the settings when the 
workflow compiles and generates the Python that a worker runs, kept in 
`codegen/` objects as in the Hugging Face operator. Settings that would 
overwhelm a worker, such as too many decoded samples or a pitch window too 
short for 60 Hz, are rejected before anything runs, and the form shows each 
number's range.
   
   **Measuring.** Pitch comes from normalized autocorrelation, with checks 
against octave errors. Onsets combine a rise in energy with spectral flux, so a 
note that starts while others still ring is found too, and beats use librosa's 
dynamic-programming beat tracker, ported to NumPy so librosa itself is not a 
dependency.
   
   **Bad files.** An unreadable or unsupported file stops the run with an error 
naming the row, the file and the cause; with **Skip Unreadable Files** on, it 
is skipped and listed in the console. A cut-off WAV or FLAC file is analysed as 
far as it goes, with a warning.
   
   #### Design choices
   
   | Choice | Why |
   |---|---|
   | miniaudio instead of soundfile | soundfile bundles LGPL libsndfile, which 
Apache projects cannot ship |
   | Ogg is not supported | corrupted Ogg Vorbis crashes the worker process 
inside the decoder |
   | `x` in seconds for every attribute | events (onsets, beats) and curves 
(rms, pitch) share one time axis |
   | Combined onsets; librosa's beat tracker | energy thresholds alone missed 
overlapping notes and followed accents rather than the beat |
   
   #### File map
   
   | Area | File | Purpose |
   |---|---|---|
   | Operator | `operator/audio/AudioAttributeExtractorOpDesc.scala` | 
Settings, compile-time checks, output schema and the Python template (imports, 
dispatch, per-tuple operator) |
   | Operator | `operator/audio/codegen/` `DecodingCodegen`, `FeaturesCodegen`, 
`BeatTrackerCodegen` | The worker's Python by stage: decode and resample; 
measure; track beats |
   | Operator | `operator/audio/AudioAttribute.java` | The six attributes |
   | Registration | `LogicalOp.scala` | Registers the operator type |
   | Dependency | `amber/operator-requirements.txt`, 
`amber/LICENSE-binary-python`, `licenses/LICENSE-MIT-0.txt` | `miniaudio==1.71` 
and the licences of what it brings |
   | Licensing | `LICENSE`, `licenses-3rd-party-code/librosa.txt`, the 
services' `LICENSE-binary`, `project/AddMetaInfLicenseFiles.scala` | Records 
the librosa-derived beat tracker (ISC) in source and binary distributions |
   | Tests | `AudioAttributeExtractorOpDescSpec`, 
`AudioAttributeExtractorBehaviorSpec` with `audio_extractor_probe.py` and 
MP3/FLAC/Ogg fixtures, `AudioAttributeExtractorIntegrationSpec` | Descriptor, 
generated Python and engine tests |
   | Docs, UI | 
`docs/reference/operators/utilities/audio-attribute-extractor.md`, its index 
row, `AudioAttributeExtractor.png` | Reference page with a short usage guide; 
the icon |
   
   ### Any related issues, documentation, discussions?
   
   Closes #3762. New Python dependency: `miniaudio==1.71`.
   
   ### How was this PR tested?
   
   - **Descriptor** — `AudioAttributeExtractorOpDescSpec` (19): the form schema 
and ranges, the output schema and every compile-time limit.
   - **Generated Python** (`@IntegrationTest`, CI) — 
`AudioAttributeExtractorBehaviorSpec` (32): runs the operator's code on 
synthesised audio with known answers (tone pitch, click times, a 120 BPM 
track), every WAV sample format, MP3 and FLAC, and bad or cut-off files.
   - **Engine** (`@IntegrationTest`, CI) — 
`AudioAttributeExtractorIntegrationSpec` (17): File Scan → this operator 
through the real engine and a Python worker, for all six attributes over binary 
and large binary.
   - `WorkflowOperator/test` (2,806 tests), `scalafmtCheckAll` and `scalafixAll 
--check` pass, with the Python environment from AGENTS.md (the engine spec also 
needs the storage services, as in CI):
   
   ```bash
   export UDF_PYTHON_PATH="$(pwd)/../venv312/bin/python"
   sbt scalafmtCheckAll "scalafixAll --check"
   sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.audio.*"
   sbt "WorkflowExecutionService/testOnly 
org.apache.texera.amber.engine.e2e.AudioAttributeExtractorIntegrationSpec"
   sbt "WorkflowOperator/test"
   ```
   
   #### Manual workflows
   
   | Workflow | Topology | Result |
   |---|---|---|
   | Tempo and 
energy<br>[audio_tempo_energy_workflow.json](https://github.com/user-attachments/files/33949573/audio_tempo_energy_workflow.json)<br>[audio_demo.zip](https://github.com/user-attachments/files/33949577/audio_demo.zip)
 | `File Scan (ZIP) → Beats / Onsets / RMS → Aggregate → Python Lambda → Hash 
Join → Projection → Bar Chart, Scatter Plot` | click tracks at 90, 120 and 150 
BPM measure 90.1, 120.0 and 150.3 |
   | Melody pitch | `File Scan (MP3) → Audio Attribute Extractor (pitch_hz) → 
Line Chart` | the four notes, C4 E4 G4 C5 |
   | Unreadable file | `File Scan (M4A) → Audio Attribute Extractor` | an error 
naming the file; skipped when Skip Unreadable Files is on |
   
   Tempo and energy, across three click tracks and two public-domain 
recordings. The recording walks through the workflow, the form (Frame and Hop 
Length hide for beats and show for rms) and the results; to try it, import the 
workflow, upload the ZIP as a dataset and pick it in File Scan.
   
   
https://github.com/user-attachments/assets/ff0c7967-e30f-4ecf-996e-04f0a07b261a
   
   | File | BPM | Onsets per minute | Mean RMS |
   |---|---|---|---|
   | click_090_bpm.wav | 90.1 | 90.2 | 0.0087 |
   | click_120_bpm.wav | 120.0 | 117.3 | 0.0112 |
   | click_150_bpm.wav | 150.3 | 147.4 | 0.0142 |
   | casio_mt40_drum_pattern.mp3 | 99.3 | 295.0 | 0.0601 |
   | usaf_band_parade.mp3 | 117.1 | 158.3 | 0.0577 |
   
   Melody pitch, the operator's raw output as a Line Chart:
   <img width="900" height="500" alt="mp3_pitch_line" 
src="https://github.com/user-attachments/assets/169cc4a2-2882-4d77-8f20-6f0acc4ded02";
 />
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to