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
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.
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.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.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.
Select a
Pricing tier
(you can choose the free version withFree F0
). Explore various pricing options here.Click
Review + create
, review the Terms, and clickCreate
.
If the deployment was successful, you should see Your deployment is complete on the next page.
Under
Next steps
, clickGo to resource
Look on the left sidebar and under
Resource Management
, clickKeys and Endpoint
Copy either
KEY 1
orKEY 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:
- Edit
~/.Renviron
and setMS_TTS_API_KEY = "YOUR_API_KEY"
- In
R
, useoptions(ms_tts_key = "YOUR_API_KEY")
. - Set
export MS_TTS_API_KEY=YOUR_API_KEY
in.bash_profile
/.bashrc
if you’re usingR
in the terminal. - Pass
api_key = "YOUR_API_KEY"
in arguments of functions such asms_list_voices(api_key = "YOUR_API_KEY")
.
You are now ready to access the API and utilize its text-to-speech functionalities.