Skip to content

Instantly share code, notes, and snippets.

@tetlabo
Created April 4, 2021 14:04
Show Gist options
  • Save tetlabo/85ce0ec1f347b6399eeee637c916371b to your computer and use it in GitHub Desktop.
Save tetlabo/85ce0ec1f347b6399eeee637c916371b to your computer and use it in GitHub Desktop.
MP3データを読み込み、スペクトログラムを描画する
library(tuneR)
library(seewave)
mp3_files <- list.files(path = "mp3/", pattern = "*.mp3")
for (i in 1:length(mp3_files)) {
name <- gsub("mp3", "png", mp3_files[i])
voice <- readMP3(file.path(paste0("mp3/", mp3_files[i])))
# スペクトログラムの描画
png(filename = name, width = 3200, height = 1600, res = 240)
par(cex.lab = 1.3, cex.axis = 1.3)
spectro(voice, flim = c(0, 10), osc = TRUE)
dev.off()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment