knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
ini0 <- Sys.time()

0. Installation

https://github.com/filipezabala/voice

# Install devtools package if necessary
if(!'devtools' %in% rownames(installed.packages())) install.packages('devtools')

# Install the stable development versions from GitHub
devtools::install_github('filipezabala/voice')
devtools::install_github('mccarthy-m-g/embedr')

1. Extract features

1.1 Load packages and audio files

# packs
library(voice)

# get path to audio file
wavDir <- list.files(system.file('extdata', package = 'wrassp'),
                     pattern = glob2rx('*.wav'), full.names = TRUE)

1.2 Examples

# minimal usage
M <- voice::extract_features(wavDir)
M

2. Tag

# creating Extended synthetic data
E <- dplyr::tibble(subject_id = c(1,1,1,2,2,2,3,3,3), wav_path = wavDir)
E

# minimal usage
voice::tag(E)

# canonical data
voice::tag(E, groupBy = 'subject_id')

3. Voice2Sheet (experimental)

3.1 Get audio

url0 <- 'https://github.com/filipezabala/voiceAudios/blob/main/mp3/doremi.mp3?raw=true'
download.file(url0, paste0(tempdir(), '/doremi.mp3'), mode = 'wb')
embedr::embed_audio(url0)

3.2 Convert mp3 to wav mono

cmd <- paste0('cd ', tempdir(), ';', 
' for i in *.[Mm][Pp]3; do ffmpeg -i "$i" -ac 1 "./${i%.*}.wav"; done')
system(cmd)

3.3 Media data

M <- voice::extract_features(tempdir())
summary(M)

3.4 Plot

voice::piano_plot(M, 0) # f0
voice::piano_plot(M, 0:1) # f0 + f1

3.5 Assign notes

(f0_spn <- voice::assign_notes(M, fmt = 0, min_points = 22, min_percentile = .85)) # f0
(f1_spn <- voice::assign_notes(M, fmt = 1, min_points = 22, min_percentile = .85)) # f1
(f2_spn <- voice::assign_notes(M, fmt = 2, min_points = 22, min_percentile = .85)) # f2

3.6 Sheet music

Must have MuseScore and gm.

3.6.1 Notes sequence of f0

library(gm)
line_0 <- gm::Line(as.character(f0_spn))
m0 <- gm::Music() +
  gm::Meter(4, 4) +
  line_0
gm::show(m0, to = c('score', 'audio'))

3.6.2 Notes sequences using f0 and f1

line_0 <- gm::Line(as.character(f0_spn))
line_1 <- gm::Line(as.character(f1_spn))
m1 <- gm::Music() + 
  gm::Meter(4, 4) + 
  line_0 + line_1
gm::show(m1, to = c('score', 'audio'))

3.6.3 Chords sequence using f0, f1 and f2

line_0 <- gm::Line(as.character(f0_spn))
line_1 <- gm::Line(as.character(f1_spn))
line_2 <- gm::Line(as.character(f2_spn))
m2 <- gm::Music() + 
  gm::Meter(4, 4) + 
  line_0 + line_1 + line_2
gm::show(m2, to = c('score', 'audio'))


filipezabala/voice documentation built on April 12, 2025, 12:39 p.m.