knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" )
The rlena package makes it easy to work with LENA .its
files in R.
The Language Environment ANalysis (LENA) system produces automatic annotations
for audio recordings. Its annotations can be exported as .its
files, that
contain an xml
structure. The rlena package helps with importing and preparing
.its
files for further anlysis in R.
The read_its_file()
fuction takes the path to an .its
file and returns an
XML object. All other functions work with this object to extract information.
They return tidy data frames that can easily be manipulated
with the usual tools from the tidyverse:
gather_recordings()
- Returns all <Recording>
nodes gather_blocks()
- Returns all <Conversation>
and <Pause>
nodes gather_conversations()
- Returns all <Conversation>
nodes gather_pauses()
- Returns all <Pause>
nodes gather_segments()
- Returns all <Segment>
nodes gather_ava_info()
- Returns AVA (Automatic Vocalization Assessment) infogather_child_info()
- Returns child info (e.g. birth data, age, gender) :warning: Warning: This package is early work in progress and subject to potentially code-breaking change.
# rlena is not (yet) available on CRAN, but you can install the developmental # version from GitHub (requires devtools): if(!require(devtools) install.packages("devtools") devtools::install_github("HomeBankCode/rlena", dependencies = TRUE)
.its
file. For this example we download a file from
HomeBankCode/lena-its-tools.library(rlena) library(dplyr, warn.conflicts = FALSE) # Download the example ITS file url <- "https://cdn.rawgit.com/HomeBankCode/lena-its-tools/master/Example/e20160420_165405_010572.its" tmp <- tempfile() download.file(url, tmp) its <- read_its_file(tmp)
gather_child_info(its) gather_ava_info(its)
# Each row corresponds to an uninterrupted recording. There is a long pause # inbetween the two recordings. This means, that the LENA recorder was paused. recordings <- gather_recordings(its) recordings
# Each row of the returned data frame corresponds to # one conversation node in the `.its` file. The columns contain the node's # attributes, such as the number of adult words and child vocalizations. conversations <- gather_conversations(its) conversations
library(tidyr) library(ggplot2) # Create long data-frame of word counts word_counts <- conversations %>% select(conversation_nr = blkTypeId, time = startClockTimeLocal, female = femaleAdultWordCnt, male = maleAdultWordCnt) %>% gather(key = speaker, value = count, female, male) %>% filter(count != 0) # Add acumulated word count word_counts <- word_counts %>% group_by(speaker) %>% arrange(conversation_nr) %>% mutate(count_acc = cumsum(count)) # Plot word counts per conversations word_counts %>% ggplot(aes(conversation_nr, count, color = speaker)) + geom_point() + labs(title = "Adult Word Count per Conversation", x = "Conversation Number", y = "Words") # Plot accumulating word count over time word_counts %>% ggplot(aes(time, y = count_acc, color = speaker)) + geom_rect(data = recordings, inherit.aes = FALSE, aes(xmin = startClockTimeLocal, xmax = endClockTimeLocal, ymin=0, ymax = max(word_counts$count_acc), group = recId, fill = "recorder on"), alpha=0.2) + scale_fill_manual(NULL, values = 'skyblue') + geom_line() + labs(title = "Accumulated Adult Word Count throughout Recording", x = "Time", y = "Words (Accumulated)")
library(lubridate) # extract segments segments <- gather_segments(its) %>% filter(startClockTimeLocal >= ymd_hms("2016-04-02 15:00:00"), startClockTimeLocal <= ymd_hms("2016-04-02 16:30:00")) segments
segments %>% mutate(duration = endTime - startTime, Label = forcats::fct_collapse( spkr, KeyChild = c("CHN", "CHF"), Speech = c("FAN", "MAN", "CXN", "FAF", "MAF", "CXF"), TV = c("TVN", "TVF"), Noise = c("NOF", "NON", "OLF", "OLN"), Silence = c("SIL"))) %>% group_by(Label) %>% summarize(duration = sum(duration)) %>% ggplot(aes(Label, duration / 60, fill = Label)) + geom_col(show.legend = FALSE) + labs(title = "The sound Environment between 3pm and 4.30pm", y = "Duration (minutes)", x = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.