+ end
+
+ ############### Temp test functions — delete after testing ################
+
+ function get_one(audio_file::String, start_time::Float64, end_time::Float64)
+ signal, freq = load_audio_file(audio_file)
+ if freq != 8000
+ signal, freq = _resample_to_8000hz(signal, freq)
+ end
+ f = convert(Int, freq)
+ s = max(1, round(Int, start_time * f) + 1)
+ e = min(size(signal, 1), round(Int, end_time * f))
+ sample = signal[s:e, 1]
+ img = _get_image_from_sample(sample, f)
+ return img
+ end
+
+ function round_trip(img)
+ #! format: off
+ colorview(RGB, permutedims(img, (3, 1, 2))) |>
+ x -> Images.RGB.(x) |>
+ x -> collect(channelview(float32.(x))) |>
+ x -> permutedims(x, (3, 2, 1))
+ #! format: on
+ end
+
+ function compare(audio_file::String, start_time::Float64, end_time::Float64)
+ img = get_one(audio_file, start_time, end_time)
+ rt = round_trip(img)
+ @info "Sizes: raw=$(size(img)) roundtrip=$(size(rt))"
+ @info "Types: raw=$(eltype(img)) roundtrip=$(eltype(rt))"
+ @info "Equal: $(img == rt)"
+ @info "Max difference: $(maximum(abs.(img .- rt)))"
+ @info "Raw range: min=$(minimum(img)) max=$(maximum(img))"
+ @info "Roundtrip range: min=$(minimum(rt)) max=$(maximum(rt))"
+ @info "Values > 1.0 in raw: $(sum(img .> 1.0))"
+ @info "Values < 0.0 in raw: $(sum(img .< 0.0))"
+ # Check per-channel: does raw[:,:,1] match rt[:,:,1] or a different channel?
+ for i in 1:3
+ for j in 1:3
+ d = maximum(abs.(img[:,:,i] .- rt[:,:,j]))
+ @info "raw channel $i vs roundtrip channel $j: max diff = $d"
+ end
+ end