voice
vignette - The R part# packs
library(voice)
library(tidyverse)
library(music)
library(gm)
<- c('vaDir', 'wavDir', 'mp3Dir', 'musicxmlDir')
dirs <- '~/Downloads/voiceAudios'
vaDir for(i in 1:length(dirs)){
if(i>1){ assign(dirs[i], paste0(get(dirs[1]), '/', dirs[i])) }
ifelse(!dir.exists(get(dirs[i])), dir.create(get(dirs[i])), 'Directory exists!')
}<- paste0('rm ', wavDir, '/*.*; ', 'rm ', mp3Dir, '/*.*')
cmd system(cmd)
<- 'https://github.com/filipezabala/voiceAudios/blob/main/mp3/doremi.mp3?raw=true'
url0 download.file(url0, paste0(mp3Dir, '/doremi.mp3'), mode = 'wb')
::embed_audio(url0) embedr
<- 'cd ~/Downloads/voiceAudios/mp3Dir;
cmd for i in *.[Mm][Pp]3; do ffmpeg -i "$i" -ac 1 "../wavDir/${i%.*}.wav"; done'
system(cmd)
<- voice::extract_features(wavDir, features = c('f0','gain'),
ef round.to = 6, windowShift = 5)
#> PROGRESS 100%
#> FILE 1 OF 1 | 0.006 SECONDS
#>
#> TOTAL TIME 0.418 SECONDS
ef#> # A tibble: 1,179 × 5
#> id_seq id_seq_file file_name_ext F0 GAIN
#> <int> <int> <chr> <dbl> <dbl>
#> 1 1 1 doremi.wav NA 16.8
#> 2 2 2 doremi.wav NA 18.5
#> 3 3 3 doremi.wav NA 18.4
#> 4 4 4 doremi.wav NA 17.5
#> 5 5 5 doremi.wav NA 17.2
#> 6 6 6 doremi.wav NA 17.1
#> 7 7 7 doremi.wav NA 16.7
#> 8 8 8 doremi.wav NA 16.3
#> 9 9 9 doremi.wav NA 16.2
#> 10 10 10 doremi.wav NA 16.3
#> # … with 1,169 more rows
<- seq(1,11,2)
odd <- vector('list', length(odd))
ef_sm names(ef_sm) <- paste0('k=', odd)
for(i in 1:length(ef_sm)){
<- voice::smooth_df(ef, id = 3, k = i)
ef_sm[[i]]
}sapply(ef_sm, dim)
#> k=1 k=3 k=5 k=7 k=9 k=11
#> [1,] 1179 1178 1177 1176 1175 1174
#> [2,] 5 5 5 5 5 5
par(mfrow = c(2,3))
for(i in 1:length(ef_sm)){
plot(ef_sm[[i]]$F0, main = paste0('k = ', odd[i]))
}
Assign notes in Scientific Pitch Notation to F0.
for(i in 1:length(ef_sm)){
$F0_spn <- voice::notes(ef_sm[[i]]$F0)
ef_sm[[i]] }
<- vector('list', length(ef_sm))
dur_spn names(dur_spn) <- paste0('k=', odd)
for(i in 1:length(ef_sm)){
<- voice::duration(ef_sm[[i]]$F0_spn)
dur_spn[[i]] }
# compress
<- voice::conv_df(ef, 0.01, id = 3)
ef_01
# assign notes
$F0_spn <- voice::notes(ef_01$F0, measure = 'spn')
ef_01
# duration
<- voice::duration(ef_01$F0_spn)
nd_01
# gm by Renfei Mao
<- gm::Music()
m01 <- m01 +
m01 ::Meter(4, 4) +
gm::Line(pitches = as.list(as.character(nd_01$note)),
gmdurations = as.list(nd_01$dur_line)) +
Tempo(170)
show(m01, to = c('score', 'audio'))