Skip to contents

This vignette provides a step-by-step demonstration of generating an API key to access the Microsoft Azure Cognitive Services Text to speech REST API. Furthermore, we explain how to set up the API key so that users of conrad can access the API and its text-to-speech functionalities.

Note that users can follow a similar process to obtain an API key for accessing various other services provided by Azure Cognitive Services, such as Speech to text, Speech translation, and more.

Getting an API key

  1. Sign into Microsoft Azure Cognitive Services by clicking on the ‘Sign in’ option located at the top right corner. If you don’t have an account yet, you can also create a new account.

  2. Click + Create a resource (below “Azure services” or click on the Hamburger button). In Azure, a resource is an entity managed by Azure. Virtual machines, virtual networks, and storage accounts are all examples of Azure resources.

  3. Search for “Speech” and Click Create -> Speech. This lets you gain access to Microsoft Azure’s Speech Service, which encompasses speech recognition, speech synthesis (text-to-speech), speech translation, and more.

  4. Create a Resource group, which associates multiple resources so you can manage them as a single thing. In our case, we only have one resource, Speech Service. Also, assign a name to your resource in the Name field.

  5. Select a Pricing tier (you can choose the free version with Free F0). Explore various pricing options here.

  6. Click Review + create, review the Terms, and click Create.

If the deployment was successful, you should see Your deployment is complete on the next page.

  1. Under Next steps, click Go to resource

  2. Look on the left sidebar and under Resource Management, click Keys and Endpoint

  3. Copy either KEY 1 or KEY 2 to clipboard. Only one key is necessary to make an API call.

Once you complete these steps, you have successfully retrieved your API keys to access the API.

WARNING: Remember your Location/Region, which you use to make calls to the API. Specifying a different region to conrad functions will lead to a HTTP 403 Forbidden response.

Setting your API key

You can set your API key in a number of ways:

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

You are now ready to access the API and utilize its text-to-speech functionalities.