Skip to main content

The real beauty of R Markdown is that it is becoming the plain text platform from which all kinds of data products can be generated: websites, blogs, books, web applications, slide presentations, and academic publications. Ari is an R package which adds video to this portfolio of data products. The following video was generated by Ari from a single R Markdown document:


Ari makes it easy to create technical lecture videos that you want to distribute online by latching into your regular data science workflows. To start using Ari there is a little bit of setup. First you’ll need to configure an Amazon Web Services account and link it to R so that Ari can use Amazon Polly in order to narrate your videos. I discussed how you can set this up in a previous blog post. Keep in mind that Amazon Web Services has a free tier, but once it is exhausted you will need to pay whenever you use Polly. After setting up your AWS account you’ll need to install FFmpeg, which Ari uses to create the video file.

Now that you’re all set up you can install Ari from CRAN:

install.packages("ari")

Let’s Make a Video

The main idea behind Ari is that you should be able to easily create a lecture video just from an R Markdown slide presentation and some written narration. Let’s load Ari so we can take a look at a sample R Markdown presentation:

library(ari)
file.show(ari_example("ari_comments.Rmd"))
---
title: "Ari Comments"
author: "Sean Kross"
---

<!--
Hello and welcome to this short presentation about Ari, the automated R
instructor.
-->

## What is Ari?

- Quickly create a lecture from plain text.
- Update your lecture easily.
- Your lecture is accessible.
- The materials can be translated into other spoken and written languages.

<!-- Ari is an R package which allows you to create lecture videos from plain
text. Your lectures are therefore easy to edit, translate, and they are
universally accessible. -->
...

As you can see the .Rmd file above is written in a standard format, with the exception that narration for each slide is written in an HTML comment, designated by the <!-- symbol which starts the comment and the --> symbol which ends the comment. This allows you to write narration under the corresponding R Markdown for a particular slide. Once you’ve written narration for each slide you should render() the HTML version of your presentation using the rmarkdown package. Now you’re ready to make a video! First make sure you have your Amazon credentials set up, then use ari_narrate() in order to produce the video. Let’s create a video from the built in example files:

# First set up your Amazon credentials
Sys.setenv("AWS_ACCESS_KEY_ID" = "EA6TDV7ASDE9TL2WI6RJ",
"AWS_SECRET_ACCESS_KEY" = "OSnwITbMzcAwvHfYDEmk10khb3g82j04Wj8Va4AA",
"AWS_DEFAULT_REGION" = "us-east-2")

# Use this Rmd file to create the slides
rmd_file <- ari_example("ari_comments.Rmd")

# Normally you would create this HTML file using rmarkdown::render()
html_file <- ari_example("ari_intro.html")

ari_narrate(rmd_file, html_file, voice = "Joey", capture_method = "iterative")

After several seconds a video file called output.mp4 should appear in your working directory, and you’ve made your first video! The voice argument above designates which voice Polly uses to narrate the video. You can see a list of available voices by running aws.polly::list_voices() (make sure you’ve set up AWS before running this command.) The capture_method argument attempts to minimize the time it takes to create the video. See ?ari_narrate for more details.

Why do this?

When I worked at the Johns Hopkins Data Science Lab we made new online courses at a rapid pace in order to popularize the latest, greatest data science technologies that we thought students should be using. As a result we wanted to create a ton of video content, which students often appreciate. Unfortunately videos are quite labor intensive to make, and in the case of technical videos APIs are always changing and new functions are being introduced. That meant that every time an API for one of our favorite packages changed we would need to re-shoot and re-edit a video, which took up lots of precious time. Ari has the potential to solve many of our video problems:

  1. Updating a video is as easy as changing a few lines of text.
  2. Since video source files are just plain text, videos can be version controlled with Git and GitHub.
  3. Our videos are more accessible to folks with disabilities since all of the narration is already typed out.
  4. Amazon Polly has voices for several languages, so theoretically we could run our lectures through the Google Translate API and make videos in 20+ different languages.

If you’re interested in using Ari please get in touch! As always I love to see what folks make.