RPA.Cloud.Azure
Azure is a library for operating with Microsoft Azure API endpoints.
List of supported service names:
- computervision (Azure Computer Vision API)
- face (Azure Face API)
- speech (Azure Speech Services API)
- textanalytics (Azure Text Analytics API)
Azure authentication
Authentication for Azure is set with service subscription key which can be given to the library in two different ways.
- Method 1 as environment variables, either service specific environment variable
for example
AZURE_TEXTANALYTICS_KEY
or with common keyAZURE_SUBSCRIPTION_KEY
which will be used for all the services. - Method 2 as Robocorp Vault secret. The vault name needs to be given in library init or
with keyword
Set Robocorp Vault
. Secret keys are expected to match environment variable names.
Method 1. subscription key using environment variable
*** Settings ***
Library RPA.Cloud.Azure
*** Tasks ***
Init Azure services
# NO parameters for client, expecting to get subscription key
# with AZURE_TEXTANALYTICS_KEY or AZURE_SUBSCRIPTION_KEY environment variable
Init Text Analytics Service
Method 2. setting Robocorp Vault in the library init
*** Settings ***
Library RPA.Cloud.Azure robocorp_vault_name=azure
*** Tasks ***
Init Azure services
Init Text Analytics Service use_robocorp_vault=${TRUE}
Method 2. setting Robocorp Vault with keyword
*** Settings ***
Library RPA.Cloud.Azure
*** Tasks ***
Init Azure services
Set Robocorp Vault vault_name=googlecloud
Init Text Analytics Service use_robocorp_vault=${TRUE}
References
List of supported language locales - Azure locale list
List of supported region identifiers - Azure region list
Examples
Robot Framework
This is a section which describes how to use the library in your Robot Framework tasks.
*** Settings ***
Library RPA.Cloud.Azure
*** Variables ***
${IMAGE_URL} IMAGE_URL
${FEATURES} Faces,ImageType
*** Tasks ***
Visioning image information
Init Computer Vision Service
&{result} Vision Analyze image_url=${IMAGE_URL} visual_features=${FEATURES}
@{faces} Set Variable ${result}[faces]
FOR ${face} IN @{faces}
Log Age: ${face}[age], Gender: ${face}[gender], Rectangle: ${face}[faceRectangle]
END
Python
This is a section which describes how to use the library in your own Python modules.
library = Azure()
library.init_text_analytics_service()
library.init_face_service()
library.init_computer_vision_service()
library.init_speech_service("westeurope")
response = library.sentiment_analyze(
text="The rooms were wonderful and the staff was helpful."
)
response = library.detect_face(
image_file=PATH_TO_FILE,
face_attributes="age,gender,smile,hair,facialHair,emotion",
)
for item in response:
gender = item["faceAttributes"]["gender"]
age = item["faceAttributes"]["age"]
print(f"Detected a face, gender:{gender}, age: {age}")
response = library.vision_analyze(
image_url=URL_TO_IMAGE,
visual_features="Faces,ImageType",
)
meta = response['metadata']
print(
f"Image dimensions meta['width']}x{meta['height']} pixels"
)
for face in response["faces"]:
left = face["faceRectangle"]["left"]
top = face["faceRectangle"]["top"]
width = face["faceRectangle"]["width"]
height = face["faceRectangle"]["height"]
print(f"Detected a face, gender:{face['gender']}, age: {face['age']}")
print(f" Face rectangle: (left={left}, top={top})")
print(f" Face rectangle: (width={width}, height={height})")
library.text_to_speech(
text="Developer tools for open-source RPA leveraging the Robot Framework ecosystem",
neural_voice_style="cheerful",
target_file='output.mp3'
)