Skip to content

Instantly share code, notes, and snippets.

@revodavid
Created August 16, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revodavid/d650bd6b31f5ec5b3ae633695aedb276 to your computer and use it in GitHub Desktop.
Save revodavid/d650bd6b31f5ec5b3ae633695aedb276 to your computer and use it in GitHub Desktop.
library(checkpoint)
checkpoint("2018-08-14")
library(fortunes)
library(mscstts)
set_ms_tts_key("8e61ae64924647d1a2833d68eeced78e")
out <- ms_synthesize("hello, world!", output_format = "audio-16khz-128kbitrate-mono-mp3")
f <- tempfile(fileext=".mp3")
writeBin(out$content, f)
shell(paste("start ", f))
say <- function(text, gender="Female", language="en-US", cmd="start") {
out <- ms_synthesize(gsub("[<>/]","",text),
gender=gender,
language=language,
output_format = "audio-16khz-128kbitrate-mono-mp3")
file <- tempfile(fileext=".mp3")
writeBin(out$content, file)
shell(paste(cmd, file))
}
say("Welcome to R, a free software environment for statistical computing and graphics.")
say("I'm sorry Dave, I can't do that.", gender="Male")
say("Crikey! That's a big crocodile.", language="en-AU")
say("Non, je ne regrette rien", gender="Female", language = "fr-FR")
fortune(275)
say(fortune(275)$quote)
@kburnham
Copy link

I'm on a Mac and needed to replace line 11 with:
system2('afplay', f)
The say() function would also require modification.

@davidfgeorge
Copy link

I am keen to experiment with TTS and signed up for an account as per your August 16, 2018 Revolutions 'Make R speak' post.
However the shell(paste("start ", f)) and shell(paste(cmd, file)) statements result in '... error in running command'.
What are the equivalent commands for a Linux-Ubuntu platform?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment