bbc / audio-offset-finder

Find the offset of an audio file within another audio file
Apache License 2.0
171 stars 29 forks source link

Feature idea: locate multiple audio matches #61

Open mjbaldwin opened 4 months ago

mjbaldwin commented 4 months ago

Hi @stephenjolly -- you were so extremely helpful in fixing the bug I was encountering with audio-offset-finder!

I assume you don't have the bandwidth to add features to the tool, but I just wanted to document here that I am facing a situation where I'd actually like to locate multiple instances of an audio file within another.

If I run my desired command I get output and a plot that looks like this:

% audio-offset-finder --find-offset-of jingle.wav --within episode.mp3 --show-plot
Offset: 2221.072 (seconds)
Standard score: 21.03777246466176
image

As you can see, there are actually two matches -- the one in the middle, and one further to the right. (For my purposes, I'm actually looking for the rightmost/latest one.)

It would actually be very useful to me if I could pass an argument to set a mode where it would return not just the single largest peak, but rather an array of all peaks above some given score. E.g. --all-above 10 or --multiple-threshold 10.0 or something like that. And then the JSON output would return an array of objects, rather than the single object.

Again, I'm not expecting this to be implemented, as it's probably out of scope for the tool. But perhaps just to leave this as an open issue in case others are also interested and it might be prioritized someday, or as a pull request?

stephenjolly commented 4 months ago

A couple of initial thoughts:

  1. You could probably do this in a hacky way with the current tool by writing a script that used the output from one run to create temporary trimmed versions of the input files and then running the search again. Repeat this process until the standard score falls below a given threshold.
  2. The above suggestion would be a less hacky approach if the tool supported searching within a specific range of time offsets, which would be more straightforward to implement than outputting multiple results, and could potentially be a compromise option.
mjbaldwin commented 4 months ago

Ah thanks Stephen! And thanks for the reply. You're right, a kind of bisecting algorithm could work here if I wanted to use the tool as-is. A bit tedious, but achievable.

And actually, searching within a specific range of offsets would actually solve my very specific problem, since I know for example that what I'm looking for (in this case) is always the match in the last 15 minutes of the file. So you've given me the idea that I can actually just trim the last 15 minutes myself with ffmpeg and search within. (In the same way I'm currently using the --trim option to speed up processing when looking for matches I know will occur only in the first 20 minutes.) So while adding support for offsets might be a useful general idea, I can do it myself easily enough.

I still think the idea of returning all matches above a score could be useful for users in general (so hopefully this can just remain an open feature request?), but now I realize I can do what I need just by trimming the last 15 minutes myself to input. Thanks!