R Shiny-音频播放 [英] R Shiny - Audio Playback

查看:146
本文介绍了R Shiny-音频播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个问题,我正在使用

For this question, I'm using

library("shiny")
library("tuneR")
library("markdown")

尽管我确定只有闪亮才有意义.

though I'm sure only shiny is relevant.

对于有光泽的标签词汇表,我应该可以使用

Per the Shiny tag glossary, I should be able to use

tags$audio(src = "wavs/tempwav.wav", type = "audio/wav", autoplay = NA, controls = NA)

生成html

<audio src="wavs/tempwav.wav" type="audio/wav" autoplay controls></audio> 

在Shiny服务器中播放声音.

to play a sound in a Shiny server.

我无法使用它来处理任何类型的mp3,wav或其他文件. Edge给出了不支持这种类型的音频文件"错误,而RStudio网页和Chrome仅显示空白的播放控件.我希望它可以与Shiny程序动态生成的* .wav文件一起使用. wav文件可以正确生成,并且可以在我尝试过的每个音乐播放器(例如VLC,WMP,MMgold,WinAmp等)中正确播放.

I can't get this to work with any kind of mp3, wav, or other file. Edge gives a, "this type of audio file is not supported" error, while the RStudio webpage and Chrome just show a blank playback control. I want it to work with *.wav files generated on the fly by the Shiny program. The wav files are generated correctly and play correctly in every music player I tried (eg, VLC, WMP, MMgold, WinAmp, etc).

使用HTML文件中的代码,例如

Using the code in an HTML file, eg

<HTML>
<audio src="wavs/tempwav.wav" type="audio/wav" autoplay controls></audio>
</HTML>

在任何浏览器中都可以正常工作.我认为问题可能与R Shiny如何处理目录有关.有建议吗?

works just fine in any browser. I think the issue may have to do with how R Shiny deals with directories. Suggestions?

推荐答案

解决方案

Solution here. Technically this was written in the Shiny tag glossary - though it was easy to miss. The www sub-directory must be in the present working directory for this to operate correctly.

要明确一点,如果您的密码是"c:\ dir",则目录"c:\ dir \ www"必须包含要播放的音频文件,并且标签将如词汇表中所示:

To be really clear, if your pwd is "c:\dir", then a directory "c:\dir\www" must contain the audio files to be played, and the tag would be written as shown in the glossary:

tags$audio(src = "sound.mp3", type = "audio/mp3", autoplay = NA, controls = NA)

它也适用于wav文件

tags$audio(src = "sound.wav", type = "audio/wav", autoplay = NA, controls = NA)

这篇关于R Shiny-音频播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆