R/ms_list_voices.R

Defines functions ms_list_voices

Documented in ms_list_voices

#' List Voices
#'
#' @param api_key Microsoft Cognitive Services API key, if token is not
#' provided.
#' @param token An authentication token, base-64 encoded usually from
#' \code{\link{ms_get_tts_token}}.  If not provided, will be created from
#' \code{\link{ms_get_tts_token}}
#' @param region Subscription region for your key.
#' See \url{https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/overview}
#' @param ... Additional arguments to send to \code{\link{GET}}
#'
#' @return A \code{data.frame} of the names and their long names.
#' @examples \dontrun{
#' if (ms_have_tts_key()) {
#' res = ms_list_voices()
#' }
#'
#' }
#'
#' \dontrun{
#' res = ms_list_voices(region = "eastus")
#' }
#' @export
ms_list_voices = function(
  token = NULL,
  api_key = NULL,
  region = NULL,
  ...
){

  region = ms_region(region)
  synth_url = paste0("https://", region,
               ".tts.speech.microsoft.com/",
               "cognitiveservices/voices/list")
  if (is.null(token)) {
    token = ms_get_tts_token(api_key = api_key,
                             region = region)$token
  }

  auth_hdr = httr::add_headers(
    "Authorization" = token)
  res = httr::GET(
    synth_url,
    auth_hdr,
    ...)

  httr::stop_for_status(res)
  out = httr::content(res, as = "text")
  out = jsonlite::fromJSON(out, flatten = TRUE)

  return(out)
}

Try the mscstts package in your browser

Any scripts or data that you put into this service are public.

mscstts documentation built on June 10, 2022, 5:11 p.m.