Skip to content

Instantly share code, notes, and snippets.

@revodavid revodavid/speakR.R
Created Aug 16, 2018

What would you like to do?
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),
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")

This comment has been minimized.

Copy link

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.


This comment has been minimized.

Copy link

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
You can’t perform that action at this time.