Skip to content

Instantly share code, notes, and snippets.

View ymattu's full-sized avatar

Yuya MATSUMURA ymattu

View GitHub Profile
createProject <- function(dir) {
path <- file.path(dir, paste0(basename(dir), ".Rproj"))
template_path <- system.file("templates/template.Rproj",
package = "devtools")
x <- c("Version: 1.0", "", "RestoreWorkspace: Default", "SaveWorkspace: Default",
"AlwaysSaveHistory: Default", "", "EnableCodeIndexing: Yes",
"UseSpacesForTab: Yes", "NumSpacesForTab: 4", "Encoding: UTF-8",
"", "RnwWeave: knitr", "LaTeX: pdfLaTeX")
cat(paste(x, collapse="\n"), file=template_path)
#'
#' @importFrom magrittr %>%
#' @importFrom stringr str_which str_subset str_replace
#' @importFrom rstudioapi isAvailable getActiveDocumentContext getSourceEditorContext
library(stringr)
library(purrr)
library(rstudioapi)
suppressMessages(library(here))
whoAmI <- function() {
# http://stackoverflow.com/a/32016824/2292993
get_os <- function() {
if (.Platform$OS.type == "windows") {
"win"
} else if (Sys.info()["sysname"] == "Darwin") {
"mac"
} else if (.Platform$OS.type == "unix") {
"unix"
} else {
stop("Unknown OS")
}
@ymattu
ymattu / inverse_map.R
Created November 18, 2018 14:44
apply multiple functions to one object
inverse_map <- function(x, ...){
mthd <- list(...)
lapply(mthd, function(m) do.call(m,list(x)))
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AllowClipboardAccess</key>
<false/>
<key>AppleAntiAliasingThreshold</key>
<integer>1</integer>
<key>AppleScrollAnimationEnabled</key>
<integer>0</integer>
@ymattu
ymattu / server.R
Last active July 18, 2018 09:25
jumanpp::server
##' Start JUMAN++ server.
##'
##' @param host.name host name if necessary
##' @param port port number if necessary. By default, 12000
##' @export
jum_start_server <- function(host.name = NULL, port = NULL) {
rubypath <- Sys.which("ruby")
if(identical(rubypath, "")){
stop("PATH to Ruby not found. Please check Ruby is installed.")
}
@ymattu
ymattu / jum_version.R
Last active July 18, 2018 08:09
jumanpp::jum_version()
jum_version <- function(){
p <- system("jumanpp -v", intern = TRUE)
if (str_detect(p, "command not found")) {
res <- "JUMAN++ is not be installed or we cannot find the path to JUMAN++"
}
res <- p %>% str_trim()
return(res)
}
@ymattu
ymattu / .xonshrc
Last active December 25, 2017 01:26
import os
from collections import Counter
from prompt_toolkit.keys import Keys
os.environ['EDITOR'] = "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
os.environ['VISUAL'] = "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
$DIR_HIST_PATH = "/Users/yuya/.dirhist"
$PATH.append("/usr/local/bin")
%let hoge = newdata;
title1 "Contents of Data Set &hoge";
title2 'Contents of Data Set &hoge';

それでは、R で音声を入れる方法を解説します

まずはセットアップです。パッケージを読み込み、取得した API キーを環境変数として設定します。また、このほかにも依存しているプログラムをインストールする必要がありますが、詳しくはブログをご覧ください。

それができたら、あとは関数を実行するだけです。このときに、原稿のファイル、スライドのファイル、声の種類、出力するビデオファイルの名前を指定します。