Skip to content

Commit

Permalink
add video; close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolamz committed May 22, 2022
1 parent 4f7558d commit 8d4f29f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 15 deletions.
31 changes: 26 additions & 5 deletions R/gloss_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#' @param grammaticality character vector with the grammaticality value.
#' @param audio_path character string with the path to the sound in .wav format.
#' @param audio_label character string for the label to display.
#' @param video_path character string with the path to the video.
#' @param video_width width argument for the video in px.
#' @param video_height height argument for the video in px.
#' @param comment character vector of the length one for the comment line (under the free translation line).
#' @param line_length integer vector of the length one that denotes maximum number of characters per one line.
#' @param italic_transliteration logical variable that denotes, whether user wants to italicize your example.
Expand Down Expand Up @@ -46,6 +49,9 @@ gloss_example <- function(transliteration,
grammaticality = NULL,
audio_path = NULL,
audio_label = "\u266A",
video_path = NULL,
video_width = 320,
video_height = 240,
line_length = 70,
italic_transliteration = TRUE,
drop_transliteration = FALSE,
Expand Down Expand Up @@ -193,6 +199,7 @@ gloss_example <- function(transliteration,
drop_transliteration = drop_transliteration,
audio_path = if(i == max(splits_by_line)){audio_path} else {NULL},
audio_label = audio_label,
video_path = if(i == max(splits_by_line)){video_path} else {NULL},
intext = FALSE,
write_to_db = FALSE)
})
Expand Down Expand Up @@ -223,14 +230,30 @@ gloss_example <- function(transliteration,
position = "left",
full_width = FALSE)


# add video ---------------------------------------------------------------
if(!is.null(video_path) & knitr::is_html_output()){
if(length(video_path) > 1){
stop("video_path argument should be of the length 1")
}
result <- kableExtra::footnote(kable_input = result,
general = as.character(
add_video(video_path,
video_width,
video_height)),
general_title = "",
escape = FALSE)
}


# add comment --------------------------------------------------------------
if(nchar(comment) > 0){
result <- kableExtra::footnote(kable_input = result,
general = comment,
general_title = "")
}

# add free translation -----------------------------------------------------
# add audio ---------------------------------------------------------------
if(!is.null(audio_path) & knitr::is_html_output()){
if(length(audio_path) > 1){
stop("audio_path argument should be of the length 1")
Expand All @@ -241,13 +264,11 @@ gloss_example <- function(transliteration,
# if(!file.exists(audio_path)){
# stop(paste("It look like there is no file", audio_path))
# }
options("lingglosses.add_sound_script" = TRUE)
add_to_translation <- paste("'",
create_sound_play(audio_path, audio_label))
add_to_translation <- paste("'", add_sound(audio_path, audio_label))
} else {
add_to_translation <- "'"
}

# add free translation -----------------------------------------------------
if(nchar(free_translation) > 0){
result <- kableExtra::footnote(kable_input = result,
general = paste0("'",
Expand Down
21 changes: 19 additions & 2 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ color_annotate <- function(gloss){
}
}

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

create_sound_play <- function(snd_src, text = "\u266A") {
add_sound <- function(snd_src, text = "\u266A") {
htmltools::tagList(htmltools::a(
onmouseover = "lingglosses_resize(this, '150%')",
onmouseout = "lingglosses_resize(this, '100%')",
onclick = paste0("lingglosses_sound_play('", snd_src, "')"),
text),
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;}"))
}

#' Add video objects for html viewer
#'
#' @author George Moroz <[email protected]>
#'
#' @param vid_src string or vector of strings with a image(s) path(s).
#' @noRd
#' @importFrom htmltools tagList
#' @importFrom htmltools tags
#' @return a string or vector of strings

add_video <- function(vid_src, width, height) {
htmltools::tagList(htmltools::tags$video(src = vid_src,
controls = TRUE,
width=width,
height=height))
}
Binary file added docs/USL_piece.mp4
Binary file not shown.
15 changes: 13 additions & 2 deletions docs/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ gloss_example('za-s jaːluʁ **wo-b** **qa-b-ɨ**; turs-ubɨ qal-es-di ǯiqj-eː

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).

## Add audio
## Add audio and video

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.
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.

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

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.

Adding video is also possible:

(@) Ukrainian Sign Language (video from https://www.spreadthesign.com)
```{r}
gloss_example("PIECE",
"piece",
video_path = "USL_piece.mp4")
```

There are additional arguments `video_width` and `video_hight` for width and hight.

## In-text examples

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:
Expand Down
43 changes: 37 additions & 6 deletions docs/index.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions man/gloss_example.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d4f29f

Please sign in to comment.