如何使用 wav 文件的 URL 在 R 中加载 wav 文件?

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

我正在开发一个 Shiny 应用程序,我目前在其中使用 audio::load.wave(path to wav-file)

加载 wav 文件

但是,我必须在线发布 Shiny 应用程序,因此我必须能够从 URL 加载 wav 文件。 过去,我可以使用 dataTable <- read.table("URL")

读取数据

对于音频文件,我已经尝试使用 load(url("URL to wav file"))loadwave(url("URL"))。但是,没有任何效果。 有谁知道如何在 R 中使用 URL 加载 wav 文件?谢谢!

可能的解决方法是在服务器上临时下载音频文件,将其加载到闪亮的应用程序中,然后在会话结束时将其删除。

这是一个示例代码:

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)