bioacoustica.collectionDownload: BioAcoustica collection download

Description Usage Arguments Author(s) Examples

Description

Downlaods the recordings from a BioAcoustica collection.

Usage

1

Arguments

collectionID

The BioAcoustica collection ID of the collection to download.

c

An authenticated CURL handle.

Author(s)

Ed Baker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(collectionID, c) {
  collection <- NULL;
  if (typeof(collectionID) != "list") {
    collection <- read.csv(text=DrupalR::drupalr.get("bio.acousti.ca/", paste0("collection/csv/",collectionID,"/", collectionID), c))
  } else {
    collection <- collectionID
  }
  bioacoustica.mkdir("bioacoustica_data")
  
  downloadData <- function(data, name) {
    url <- data["recording_url"]
    filename <- paste0(data["entity_id"],".wav")
    download.file(url, filename)
    
    if (data["entity_type"] == "annotation") {
      trimFile(filename, data["start"], data["end"])
    }
  }
  
  trimFile <- function(filename, start, end) {
    long <- readWave(filename)
    f <- long@samp.rate
    short <- seewave::cutw(long, f=f, from=as.numeric(start),to=as.numeric(end), method="Wave")
    file.remove(filename)
    seewave::savewav(short, f=f, file=filename)
  }
  
  urls <- as.character(collection[,"recording_url"])
  filenames <- as.character(collection[,"entity_id"])
  setwd("./bioacoustica_data")
  apply(collection, 1, downloadData)
  setwd("..")
  
}

BioAcoustica/bioacousticaR documentation built on May 5, 2019, 3:46 p.m.