Skip to content

Commit 8d4f29f

Browse files
committed
add video; close #3
1 parent 4f7558d commit 8d4f29f

File tree

6 files changed

+104
-15
lines changed

6 files changed

+104
-15
lines changed

R/gloss_example.R

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#' @param grammaticality character vector with the grammaticality value.
1212
#' @param audio_path character string with the path to the sound in .wav format.
1313
#' @param audio_label character string for the label to display.
14+
#' @param video_path character string with the path to the video.
15+
#' @param video_width width argument for the video in px.
16+
#' @param video_height height argument for the video in px.
1417
#' @param comment character vector of the length one for the comment line (under the free translation line).
1518
#' @param line_length integer vector of the length one that denotes maximum number of characters per one line.
1619
#' @param italic_transliteration logical variable that denotes, whether user wants to italicize your example.
@@ -46,6 +49,9 @@ gloss_example <- function(transliteration,
4649
grammaticality = NULL,
4750
audio_path = NULL,
4851
audio_label = "\u266A",
52+
video_path = NULL,
53+
video_width = 320,
54+
video_height = 240,
4955
line_length = 70,
5056
italic_transliteration = TRUE,
5157
drop_transliteration = FALSE,
@@ -193,6 +199,7 @@ gloss_example <- function(transliteration,
193199
drop_transliteration = drop_transliteration,
194200
audio_path = if(i == max(splits_by_line)){audio_path} else {NULL},
195201
audio_label = audio_label,
202+
video_path = if(i == max(splits_by_line)){video_path} else {NULL},
196203
intext = FALSE,
197204
write_to_db = FALSE)
198205
})
@@ -223,14 +230,30 @@ gloss_example <- function(transliteration,
223230
position = "left",
224231
full_width = FALSE)
225232

233+
234+
# add video ---------------------------------------------------------------
235+
if(!is.null(video_path) & knitr::is_html_output()){
236+
if(length(video_path) > 1){
237+
stop("video_path argument should be of the length 1")
238+
}
239+
result <- kableExtra::footnote(kable_input = result,
240+
general = as.character(
241+
add_video(video_path,
242+
video_width,
243+
video_height)),
244+
general_title = "",
245+
escape = FALSE)
246+
}
247+
248+
226249
# add comment --------------------------------------------------------------
227250
if(nchar(comment) > 0){
228251
result <- kableExtra::footnote(kable_input = result,
229252
general = comment,
230253
general_title = "")
231254
}
232255

233-
# add free translation -----------------------------------------------------
256+
# add audio ---------------------------------------------------------------
234257
if(!is.null(audio_path) & knitr::is_html_output()){
235258
if(length(audio_path) > 1){
236259
stop("audio_path argument should be of the length 1")
@@ -241,13 +264,11 @@ gloss_example <- function(transliteration,
241264
# if(!file.exists(audio_path)){
242265
# stop(paste("It look like there is no file", audio_path))
243266
# }
244-
options("lingglosses.add_sound_script" = TRUE)
245-
add_to_translation <- paste("'",
246-
create_sound_play(audio_path, audio_label))
267+
add_to_translation <- paste("'", add_sound(audio_path, audio_label))
247268
} else {
248269
add_to_translation <- "'"
249270
}
250-
271+
# add free translation -----------------------------------------------------
251272
if(nchar(free_translation) > 0){
252273
result <- kableExtra::footnote(kable_input = result,
253274
general = paste0("'",

R/zzz.r

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ color_annotate <- function(gloss){
7474
}
7575
}
7676

77-
#' Create audio play objects for html viewer
77+
#' Add audio objects for html viewer
7878
#'
7979
#' @author George Moroz <[email protected]>
8080
#'
@@ -86,11 +86,28 @@ color_annotate <- function(gloss){
8686
#' @importFrom htmltools tags
8787
#' @return a string or vector of strings
8888

89-
create_sound_play <- function(snd_src, text = "\u266A") {
89+
add_sound <- function(snd_src, text = "\u266A") {
9090
htmltools::tagList(htmltools::a(
9191
onmouseover = "lingglosses_resize(this, '150%')",
9292
onmouseout = "lingglosses_resize(this, '100%')",
9393
onclick = paste0("lingglosses_sound_play('", snd_src, "')"),
9494
text),
9595
htmltools::tags$script("function lingglosses_sound_play(x) {var audio = new Audio(); audio.src = x; audio.play();} function lingglosses_resize(elem, percent) {elem.style.fontSize = percent;}"))
9696
}
97+
98+
#' Add video objects for html viewer
99+
#'
100+
#' @author George Moroz <[email protected]>
101+
#'
102+
#' @param vid_src string or vector of strings with a image(s) path(s).
103+
#' @noRd
104+
#' @importFrom htmltools tagList
105+
#' @importFrom htmltools tags
106+
#' @return a string or vector of strings
107+
108+
add_video <- function(vid_src, width, height) {
109+
htmltools::tagList(htmltools::tags$video(src = vid_src,
110+
controls = TRUE,
111+
width=width,
112+
height=height))
113+
}

docs/USL_piece.mp4

89.7 KB
Binary file not shown.

docs/index.Rmd

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ gloss_example('za-s jaːluʁ **wo-b** **qa-b-ɨ**; turs-ubɨ qal-es-di ǯiqj-eː
205205

206206
If you are not satisfied with the result of the automatic split you can change the value of the `line_length` argument (the default value is `70`, that means 70 characters of the longest line).
207207

208-
## Add audio
208+
## Add audio and video
209209

210-
It is possible to add a sound to the example using an `audio_path` argument. It can be both: a path to the file or an URL.
210+
It is possible to add a soundtrack to the example using an `audio_path` argument. It can be both: a path to the file or an URL.
211211

212212
(@) Abaza, West Caucasian (my field recording)
213213
```{r}
@@ -219,6 +219,17 @@ gloss_example("á-ɕa",
219219

220220
You can hear the recording if you click on the note icon above. If you do not like the icon, you can change it to any text using an `audio_label` argument.
221221

222+
Adding video is also possible:
223+
224+
(@) Ukrainian Sign Language (video from https://www.spreadthesign.com)
225+
```{r}
226+
gloss_example("PIECE",
227+
"piece",
228+
video_path = "USL_piece.mp4")
229+
```
230+
231+
There are additional arguments `video_width` and `video_hight` for width and hight.
232+
222233
## In-text examples
223234

224235
When an example is small, the author may not want to put it in a separate paragraph, but prefer to display it as part of the running text. This is possible to achieve using the standard for `rmarkdown` [inline code](https://rmarkdown.rstudio.com/lesson-4.html). The result of the R code can be inserted into the rmarkdown document using the [backtick symbol](https://en.wikipedia.org/wiki/Grave_accent#Use_in_programming) and the small r, for example <code>&grave;r 2+2&grave;</code> will be rendered as `r 2+2`. Currently `lingglosses` can not automatically detect whether code was provided via code chunk or inline. So if you want to use an in-text glossed example and want the glosses to appear in list, it is possible to write them using the `gloss_example()` with the `intext = TRUE` argument. Here is a Turkish example from (@delancey97): `r gloss_example("Kemal gel-miş", "Kemal come-MIR", intext = TRUE)` that was produced with the following inline code:

docs/index.html

Lines changed: 37 additions & 6 deletions
Large diffs are not rendered by default.

man/gloss_example.Rd

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)