Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

kburnham commented Aug 17, 2018

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

@davidfgeorge

This comment has been minimized.

davidfgeorge commented Sep 7, 2018

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