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)
which generates the html
<audio src="wavs/tempwav.wav" type="audio/wav" autoplay controls></audio>
to play a sound in a Shiny server.
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).
Using the code in an HTML file, eg
<HTML>
<audio src="wavs/tempwav.wav" type="audio/wav" autoplay controls></audio>
</HTML>
works just fine in any browser. I think the issue may have to do with how R Shiny deals with directories. Suggestions?
paste0(getwd(),"/wavs/tempwav.wav")
results in the error "this audio stopped playing suddenly" in Edge, still nothing elsewhere. Thinking it may be a result of the reactive nature of Shiny, I tried linking a static wav file without success as well. – Zediiiiishiny::tags$source(src = paste0("file", F, ".mp3"))
worked for me. – Rumpl