Created
March 25, 2021 16:24
-
-
Save tetlabo/e398b6c23c1ec9e95c42ebfb530ba2fa to your computer and use it in GitHub Desktop.
音声データ (MP3) をRでプロットする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tuneR) | |
library(ggplot2) | |
voice_orig <- readMP3(file.path("voice.mp3")) | |
# 音声の切り出し | |
start <- 0.6 * [email protected] | |
end <- 1.1 * [email protected] | |
voice <- voice_orig[start:end] | |
# データフレームへの変換 | |
sample <- seq(1:length(voice@left)) | |
time <- sample/[email protected] | |
sample.left <- as.vector(cbind(voice@left)) | |
voice_df <- data.frame(sample, time, sample.left) | |
# ノイズの付与 | |
voice_df[["noise_sample.left"]] <- sample.left + runif(n = length(sample.left), min = min(sample.left) / 2, max = max(sample.left) / 2) | |
# プロット | |
ggplot(voice_df, aes(x = time, y = sample.left)) + geom_line() + theme_void() | |
ggsave("voice_clear.png", width = 10, height = 4, units = "cm") | |
ggplot(voice_df, aes(x = time, y = noise_sample.left)) + geom_line() + theme_void() | |
ggsave("voice_noise.png", width = 10, height = 4, units = "cm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment