MyNixOS website logo
Description

R Client for the Microsoft Cognitive Services 'Text-to-Speech' REST API.

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/services/cognitive-services/> in order to obtain a (free) API key. Without an API key, this package will not work properly.

R-CMD-check

mscstts Package:

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

Getting an API key

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.

  1. Create an Azure account
  2. Go to https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices. If that works, skip to step 5.
  3. Go to https://portal.azure.com/#home
  4. Click + Create a Resource
  5. Search “Speech”
  6. Hit + Create
  7. Should be able to create an F0 account (which is free - see below) if you hit the pricing tiers

Setting up your API key

You can set up your API key in a number of ways (where XXX is your API key):

  1. Edit ~/.Renviron and set MS_TTS_API_KEY = "XXXX"
  2. In R, use options(ms_tts_key = "XXXX").
  3. Set export MS_TTS_API_KEY=XXXX in .bash_profile/.bashrc if you’re using R in the terminal.
  4. Pass api_key = "XXXX" in arguments of functions such as ms_list_voices(api_key = "XXXX").

Installation

You can install mscstts from GitHub with:

# install.packages("remotes")
remotes::install_github("muschellij2/mscstts")

Example

library(mscstts)
if (ms_have_tts_key()) {
  res = ms_synthesize(
    script = "hey, how are you doing? I'm doing pretty good",
    output_format = "audio-16khz-128kbitrate-mono-mp3")
  tmp <- tempfile("example", fileext = ".mp3")
  writeBin(res$content, con = tmp)
  mp3 = tuneR::readMP3(tmp)
}
testthat::expect_true(file.size(tmp) > 50000)
if (interactive()) {
  player = tuneR::getWavPlayer()
  if (.Platform$OS.type == "windows" && is.null(player)) player = NULL
  if (.Platform$OS.type != "windows" && is.null(player)) player = "play"
  tuneR::play(mp3, player = player)
}
Metadata

Version

0.6.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows