IPS-LMU / emuR

The main R package for the EMU Speech Database Management System (EMU-SDMS)
http://ips-lmu.github.io/EMU.html
23 stars 15 forks source link

The sample_end and sample_start types should be aligned with the expectations of wrassp functions #242

Closed FredrikKarlssonSpeech closed 3 years ago

FredrikKarlssonSpeech commented 3 years ago

I guess this issue could also be fixed in wrassp.

I just noticed that the sample_end and sample_start is defined as INTEGER, while wrassp functions (such as read.AsspDataObj) has other expectations REAL() can only be applied to a 'numeric', not a 'integer'

so you cannot just feed this data in from one function to another. Seems a bit awkward.

raphywink commented 3 years ago

Sorry but I think I need a bit more context. Are you using the output of a query() as an input to wrassp? If so how & why? :-)

FredrikKarlssonSpeech commented 3 years ago

I understand your confusion. I needed to make an extraction of pats of signals in a recoverable way, for processing in Matlab. So I used the output of a query to guide where to start and end the extraction. :-)

raphywink commented 3 years ago

Ah ok! Could you maybe put a min. example together 4 me using the ae demo emuDB? So I can easily reproduce the error? Then I can see where it would be best to type cast the cols.

FredrikKarlssonSpeech commented 3 years ago

Sure!

library(emuR)
library(wrassp)

extract_sounds <- function(dbHandle,sl,outputDir, signalFileSuffix=".wav"){
  sl$signalfiles <- normalizePath(
    file.path(dbHandle$basePath,paste0(sl$session,emuR:::session.suffix),paste0(sl$bundle,emuR:::bundle.dir.suffix),paste0(sl$bundle,signalFileSuffix))
    )
  sl$recoverable_filename <- paste0(paste(sl$session,sl$bundle,sl$db_uuid,sl$sample_start,sl$sample_end,sep="__"),signalFileSuffix)
  sl$recoverable_filename_path <- file.path(normalizePath(outputDir),sl$recoverable_filename)
  for(i in 1:nrow(sl)){
    curr <- wrassp::read.AsspDataObj(sl$signalfiles[[i]],begin=sl$sample_start[[i]],end=sl$sample_end[[i]],samples=TRUE)
    wrassp::write.AsspDataObj(curr,file=sl$recoverable_filename_path[[i]])
  }
  return(list(sucessful=sl$recoverable_filename[file.exists(sl$recoverable_filename_path)],
              failed=sl$recoverable_filename[!file.exists(sl$recoverable_filename_path)]))
}

create_emuRdemoData()
load_emuDB(file.path(tempdir(),"emuR_demoData","ae_emuDB")) -> ae
extract_sounds(ae,sl,"~/Desktop/out")

results in

Error in wrassp::read.AsspDataObj(sl$signalfiles[[i]], begin = sl$sample_start[[i]], : REAL() can only be applied to a 'numeric', not a 'integer'

However, redefining the function like this:

extract_sounds <- function(dbHandle,sl,outputDir, signalFileSuffix=".wav"){
  sl$signalfiles <- normalizePath(
    file.path(dbHandle$basePath,paste0(sl$session,emuR:::session.suffix),paste0(sl$bundle,emuR:::bundle.dir.suffix),paste0(sl$bundle,signalFileSuffix))
    )
  sl$recoverable_filename <- paste0(paste(sl$session,sl$bundle,sl$db_uuid,sl$sample_start,sl$sample_end,sep="__"),signalFileSuffix)
  sl$recoverable_filename_path <- file.path(normalizePath(outputDir),sl$recoverable_filename)
  for(i in 1:nrow(sl)){
    curr <- wrassp::read.AsspDataObj(sl$signalfiles[[i]],begin=as.numeric(sl$sample_start[[i]]),end=as.numeric(sl$sample_end[[i]]),samples=TRUE)
    wrassp::write.AsspDataObj(curr,file=sl$recoverable_filename_path[[i]])
  }
  return(list(sucessful=sl$recoverable_filename[file.exists(sl$recoverable_filename_path)],
              failed=sl$recoverable_filename[!file.exists(sl$recoverable_filename_path)]))
}

makes it all work like a charm.

raphywink commented 3 years ago

see https://github.com/IPS-LMU/wrassp/commit/cbbc6e9fe100f5f32f7b30510f3008c5a5553440