The goal of mscstts
is to provide an R Client for the
Microsoft Cognitive Services Text to Speech REST API, including voice
synthesis. A valid account MUST be registered at the Microsoft Cognitive
Services website https://azure.microsoft.com/en-us/free/cognitive-services/
in order to obtain a (free) API key. Without an API key, this package
will not work properly.
See the documentation here: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/overview
You can get a TTS API key here: https://azure.microsoft.com/en-us/free/cognitive-services/. The API you need to get one from is Cognitive Services, Speech.
+ Create a Resource
+ Create
You can set up your API key in a number of ways (where
XXX
is your API key):
~/.Renviron
and set
MS_TTS_API_KEY = "XXXX"
R
, use
options(ms_tts_key = "XXXX")
.export MS_TTS_API_KEY=XXXX
in
.bash_profile
/.bashrc
if you’re using
R
in the terminal.api_key = "XXXX"
in arguments of functions such as
ms_list_voices(api_key = "XXXX")
.You can install mscstts
from GitHub with:
# install.packages("remotes")
::install_github("muschellij2/mscstts") remotes
library(mscstts)
if (ms_have_tts_key()) {
= ms_synthesize(
res script = "hey, how are you doing? I'm doing pretty good",
output_format = "audio-16khz-128kbitrate-mono-mp3")
<- tempfile("example", fileext = ".mp3")
tmp writeBin(res$content, con = tmp)
= tuneR::readMP3(tmp)
mp3
}::expect_true(file.size(tmp) > 50000)
testthatif (interactive()) {
= tuneR::getWavPlayer()
player if (.Platform$OS.type == "windows" && is.null(player)) player = NULL
if (.Platform$OS.type != "windows" && is.null(player)) player = "play"
::play(mp3, player = player)
tuneR }