简体   繁体   中英

How can I load a wav file in R using a URL of the wav file?

I am developing a Shiny application, in which I currently load wav-files by using audio::load.wave(path to wav-file)

However, I have to publish the Shiny application online, and thus I have to be able to load the wav-files from a URL. In the past, I was able to read data by using dataTable <- read.table("URL")

For the audio file I already tried using load(url("URL to wav file")) or loadwave(url("URL")) . However, nothing works. Does anyone have an idea of how to load a wav-file using a URL in R? Thanks!

A possible workaround might be to temporary download the audio file on the server, load it in the shiny app, and then remove it at the end of the session.

Here is a sample code:

url <- "http://www.wavlist.com/humor/001/911d.wav"

# Define the temporary directory and download the data
dest_path <- "sound.wav"
download.file(url,destfile = dest_path)

# Load the audio file
audio::load.wave(dest_path)

# At the end of the session remove the downloaded data
file.remove(dest_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM