Skip to contents

Builds the table of all recordings that "random_recordings" in select_clips(), export_occupancy_data() and run_app() take as recordings, by listing the audio files under audio_dir. Unlike the list that those functions build when recordings = NULL, it includes the recordings of folders without any prediction, which the multiple-method design and the occasions of the occupancy models need.

Usage

list_recordings(
  audio_dir,
  audio_pattern = "\\.(wav|flac|mp3)$",
  site = NULL,
  site_pattern = NULL,
  remap_from = NULL,
  remap_to = NULL,
  predictions = NULL,
  file = NULL
)

Arguments

audio_dir

Character scalar, path to the root folder of the audio files, searched recursively.

audio_pattern

Character scalar, regular expression for the audio file names (case insensitive).

site

NULL (the site is the first folder below audio_dir) or a character scalar, a single site name for every file.

site_pattern

NULL or character scalar, regular expression with one capture group that takes the site from the file name, for recordings of several sites in the same folder. For example, "^[^_]+_([^_]+)_" reads Campus01 from Campinas_Campus01_20261003_074339.flac. It replaces the folder rule and cannot be combined with site.

remap_from, remap_to

NULL or character scalars. Replace the prefix remap_from of the listed paths by remap_to, e.g. "/Volumes/NAS/" and "N:/", so that the paths match Begin Path. Backslashes are turned into forward slashes first.

predictions

NULL or a data frame of predictions (one row per prediction) from read_selection_tables(), to check that its audio files are in the list.

file

NULL or character scalar, path of a CSV file to write the table to (e.g. "recordings.csv").

Value

A tibble (class tbl_df) with site and source_audio, one row per recording, sorted by site and path (invisibly when file is given).

Details

The site of each recording is the first folder below audio_dir, so both audio_dir/<site>/<file> and audio_dir/<site>/<card or date>/<file> work. Files directly in audio_dir need site.

The paths must match those in the Begin Path column of the selection tables, because the recordings are matched to the predictions by path. When the audio was analysed on another computer (for instance, from a network drive mapped as N:), list the files where they are and rewrite the prefix with remap_from and remap_to, or pass the same remap_from and remap_to to select_clips() so that Begin Path is rewritten to the local prefix instead. With predictions, the function reports how many of the audio files of the predictions are in the list.

File names are expected to carry the date and time as YYYYMMDD_HHMMSS, as most recorders write them; the files whose names do not are reported.

Examples

audio <- file.path(tempdir(), "audio")
for (s in c("ARA", "BAI")) dir.create(file.path(audio, s), recursive = TRUE)
file.create(file.path(audio, "ARA", c("ARA01_20211001_190000.wav",
                                     "ARA01_20211001_200000.wav")))
#> [1] TRUE TRUE
file.create(file.path(audio, "BAI", "BAI01_20211001_190000.wav"))
#> [1] TRUE
list_recordings(audio)
#> 3 recordings listed at 2 site(s).
#> # A tibble: 3 × 2
#>   site  source_audio                                       
#>   <chr> <chr>                                              
#> 1 ARA   /tmp/RtmpnYqzB0/audio/ARA/ARA01_20211001_190000.wav
#> 2 ARA   /tmp/RtmpnYqzB0/audio/ARA/ARA01_20211001_200000.wav
#> 3 BAI   /tmp/RtmpnYqzB0/audio/BAI/BAI01_20211001_190000.wav