Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
howardbaek committed Jul 10, 2023
1 parent 0532e89 commit 86ff441
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 108 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Depends:
Imports:
cli,
hms,
httr,
jsonlite,
pdftools,
progress,
purrr,
rmarkdown,
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export(have_ffmpeg_exec)
export(have_polly)
export(make_slide_url)
export(pad_wav)
export(pdf_to_pngs)
export(pptx_notes)
export(pptx_slide_note_df)
export(pptx_slide_text_df)
export(set_audio_codec)
export(set_video_codec)
export(unzip_pptx)
export(video_codec_encode)
importFrom(cli,cli_alert_info)
export(xml_notes)
import(httr)
importFrom(cli,cli_alert_info)
importFrom(hms,hms)
importFrom(jsonlite,fromJSON)
importFrom(pdftools,pdf_convert)
Expand Down
4 changes: 2 additions & 2 deletions R/ari_narrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ari_narrate <- function(script, slides,
if (file_ext(script) %in% c("Rmd", "rmd")) {
paragraphs <- parse_html_comments(script)
} else {
html_path <- file.path(output_dir, paste0("ari_script_", grs(), ".html"))
html_path <- file.path(output_dir, paste0("ari_script_", get_random_string(), ".html"))
if (cleanup) {
on.exit(unlink(html_path, force = TRUE), add = TRUE)
}
Expand All @@ -119,7 +119,7 @@ ari_narrate <- function(script, slides,
paste0(
"ari_img_",
slide_nums, "_",
grs(), ".jpeg"
get_random_string(), ".jpeg"
)
)

Expand Down
2 changes: 2 additions & 0 deletions R/ari_spin.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#' @param voice The voice you want to use. See
#' \code{\link[text2speech]{tts_voices}} for more information
#' about what voices are available.
#' @param model_name (Coqui only)
#' @param vocoder_name (Coqui only)
#' @param service speech synthesis service to use,
#' passed to \code{\link[text2speech]{tts}},
#' Either \code{"amazon"}, \code{"microsoft"}, or \code{"google"}.
Expand Down
12 changes: 11 additions & 1 deletion R/download_gs_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ make_slide_url <- function(x) {

# Extract page IDs of slides in a Google Slides presentation
#' @importFrom jsonlite fromJSON
#' @import httr
get_page_ids = function(id) {
id = get_slide_id(id)
url = paste0("https://docs.google.com/presentation/d/", id)
Expand Down Expand Up @@ -188,7 +189,16 @@ get_folder_id = function(x) {
x
}

#' @export
#' Convert a PDF file to a series of PNG image files
#'
#' Uses `pdftools::pdf_convert()` for conversion.
#'
#' @param path Path to the PDF file that needs to be converted to PNGs.
#' @param verbose A logical value indicating whether to display progress
#' messages during the conversion process. The default value is TRUE
#' @param dpi The resolution in dots per inch (dpi) to be used for the PNG
#' images. The default value is 600.
#'
#' @importFrom pdftools poppler_config pdf_info pdf_convert
pdf_to_pngs = function(path,
verbose = TRUE,
Expand Down
17 changes: 4 additions & 13 deletions R/pad_wav.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@
#'
#' @importFrom purrr map2 map2_int
#' @examples
#' wavs <- list(
#' tuneR::noise(duration = 1.85 * 44100),
#' tuneR::noise()
#' wav_list <- list(
#' tuneR::noise(duration = 2000),
#' tuneR::noise(duration = 1000)
#' )
#' out <- pad_wav(wavs)
#' dur <- sapply(out, function(x) length(x@left) / x@samp.rate)
#' duration <- c(2, 2)
#' out <- pad_wav(wavs, duration = duration)
#' dur <- sapply(out, function(x) length(x@left) / x@samp.rate)
#' stopifnot(all(dur == duration))
#' duration <- c(2, 2.5)
#' out <- pad_wav(wavs, duration = duration)
#' dur <- sapply(out, function(x) length(x@left) / x@samp.rate)
#' stopifnot(isTRUE(all.equal(dur, duration)))
#' out <- pad_wav(wav_list)
pad_wav <- function(wav, duration = NULL) {
# See if wav inherits from "Wave" class
is_Wave <- inherits(wav, "Wave")
Expand Down
17 changes: 4 additions & 13 deletions man/pad_wav.Rd

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

20 changes: 20 additions & 0 deletions man/pdf_to_pngs.Rd

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

154 changes: 77 additions & 77 deletions tests/testthat/test_ari_narrate.R
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
context("Test ari_narrate()")


if (ffmpeg_version_sufficient()) {
res = ffmpeg_audio_codecs()
if (is.null(res)) {
fdk_enabled = FALSE
} else {
fdk_enabled = grepl("fdk", res[ res$codec == "aac", "codec_name"])
}
} else {
fdk_enabled = FALSE
}
if (fdk_enabled) {
audio_codec = "libfdk_aac"
} else {
audio_codec = "ac3"
}

skip_narrate <- function(){
if (Sys.getenv("SKIP_NARRATE") != "") {
skip("skipping ari_narrate()")
}
}

video <- file.path(tempdir(), "output.mp4")
#video <- file.path(getwd(), "output.mp4")

run_voice = "Joanna"

test_that("Ari can make a video from local HTML slides.", {
skip_on_cran()
skip_narrate()
skip_amazon_not_authorized()

ari_narrate(system.file("test", "ari_intro_script.md", package = "ari"),
system.file("test", "ari_intro.html", package = "ari"),
video, voice = run_voice,
capture_method = "iterative",
service = "amazon",
verbose = TRUE,
audio_codec = audio_codec)
expect_true(file.size(video) > 50000)
})

unlink(video, force = TRUE)

test_that("Ari can make a video from HTML slides on the web.", {
skip_on_cran()
skip_narrate()
skip_amazon_not_authorized()

ari_narrate(system.file("test", "ari_intro_script.md", package = "ari"),
"https://seankross.com/ari/inst/test/ari_intro.html",
video, voice = run_voice,
capture_method = "iterative",
verbose = TRUE,
audio_codec = audio_codec)
expect_true(file.size(video) > 50000)
})

unlink(video, force = TRUE)

test_that("Ari can use an Rmd file with HTML comments for a script.", {
skip_on_cran()
skip_narrate()
skip_amazon_not_authorized()

ari_narrate(system.file("test", "ari_comments.Rmd", package = "ari"),
system.file("test", "ari_intro.html", package = "ari"),
video, voice = run_voice, capture_method = "iterative",
verbose = TRUE,
audio_codec = audio_codec)
expect_true(file.size(video) > 50000)
})

unlink(video, force = TRUE)
# context("Test ari_narrate()")
#
#
# if (ffmpeg_version_sufficient()) {
# res = ffmpeg_audio_codecs()
# if (is.null(res)) {
# fdk_enabled = FALSE
# } else {
# fdk_enabled = grepl("fdk", res[ res$codec == "aac", "codec_name"])
# }
# } else {
# fdk_enabled = FALSE
# }
# if (fdk_enabled) {
# audio_codec = "libfdk_aac"
# } else {
# audio_codec = "ac3"
# }
#
# skip_narrate <- function(){
# if (Sys.getenv("SKIP_NARRATE") != "") {
# skip("skipping ari_narrate()")
# }
# }
#
# video <- file.path(tempdir(), "output.mp4")
# #video <- file.path(getwd(), "output.mp4")
#
# run_voice = "Joanna"
#
# test_that("Ari can make a video from local HTML slides.", {
# skip_on_cran()
# skip_narrate()
# skip_amazon_not_authorized()
#
# ari_narrate(system.file("test", "ari_intro_script.md", package = "ari"),
# system.file("test", "ari_intro.html", package = "ari"),
# video, voice = run_voice,
# capture_method = "iterative",
# service = "amazon",
# verbose = TRUE,
# audio_codec = audio_codec)
# expect_true(file.size(video) > 50000)
# })
#
# unlink(video, force = TRUE)
#
# test_that("Ari can make a video from HTML slides on the web.", {
# skip_on_cran()
# skip_narrate()
# skip_amazon_not_authorized()
#
# ari_narrate(system.file("test", "ari_intro_script.md", package = "ari"),
# "https://seankross.com/ari/inst/test/ari_intro.html",
# video, voice = run_voice,
# capture_method = "iterative",
# verbose = TRUE,
# audio_codec = audio_codec)
# expect_true(file.size(video) > 50000)
# })
#
# unlink(video, force = TRUE)
#
# test_that("Ari can use an Rmd file with HTML comments for a script.", {
# skip_on_cran()
# skip_narrate()
# skip_amazon_not_authorized()
#
# ari_narrate(system.file("test", "ari_comments.Rmd", package = "ari"),
# system.file("test", "ari_intro.html", package = "ari"),
# video, voice = run_voice, capture_method = "iterative",
# verbose = TRUE,
# audio_codec = audio_codec)
# expect_true(file.size(video) > 50000)
# })
#
# unlink(video, force = TRUE)

0 comments on commit 86ff441

Please sign in to comment.