Audio files in R markdown

Thanks for the reply. But I've no idea at all about HTML. I've programmed only in R, and the only other language I have some knowledge about is python.

So basically, I just imitated (without much understanding) from the links you provided, and also those given here. This is what I've done:

---
title: "R Notebook"
output: html_document
---

some text

<html>
<audio controls>
  <source src="reprex.wav" type="audio/wav">
</audio></html>

some text

<html>
<audio controls>
  <source src="xerper.wav" type="audio/wav">
</audio></html>

some text

I used the following audio files: 1 and 2. What I obtained is this.

As far as I can tell, it seems to work perfectly, at least for this example. It may be the case that I need to modify it for different cases, though can't think of any right now.

Update

---
title: "Example"
output: html_document
---
  
```{r include = FALSE}
html_tag_audio <- function(file,
                           type = "wav")
{
  htmltools::tags$audio(controls = NA,
                        htmltools::tags$source(src = file,
                                               type = glue::glue("audio/{type}",
                                                                 type = type)))
}
```

some text 1

`r html_tag_audio("reprex.wav")`

some text 2

`r html_tag_audio("xerper.wav")`

some text 3

This yields the following:

https://ufile.io/zr8yx

Audio files used are 1 and 2, same as earlier.

1 Like