Azure Cognitive Services Intermediate

Azure Cognitive Services (now Azure AI Services) provides pre-built AI models accessible through simple REST APIs and SDKs. Add vision, speech, language, and decision-making capabilities to your applications without building ML models from scratch.

Vision Services

Computer Vision

Analyze images for content, objects, text (OCR), faces, and spatial analysis:

Python
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials

client = ComputerVisionClient(
    endpoint="https://my-vision.cognitiveservices.azure.com/",
    credentials=CognitiveServicesCredentials("YOUR_API_KEY")
)

# Analyze an image
analysis = client.analyze_image(
    url="https://example.com/photo.jpg",
    visual_features=["Categories", "Description", "Objects", "Tags"]
)

print(f"Description: {analysis.description.captions[0].text}")
for tag in analysis.tags:
    print(f"Tag: {tag.name} ({tag.confidence:.2f})")

Speech Services

Speech-to-Text

Python
import azure.cognitiveservices.speech as speechsdk

speech_config = speechsdk.SpeechConfig(
    subscription="YOUR_API_KEY",
    region="eastus"
)
speech_config.speech_recognition_language = "en-US"

# Recognize from microphone
recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
result = recognizer.recognize_once()

if result.reason == speechsdk.ResultReason.RecognizedSpeech:
    print(f"Recognized: {result.text}")

Text-to-Speech

Python
# Synthesize speech
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
result = synthesizer.speak_text_async("Hello from Azure AI Services!").get()

if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print("Speech synthesized successfully!")

Language Services

Text Analytics

Python
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

client = TextAnalyticsClient(
    endpoint="https://my-language.cognitiveservices.azure.com/",
    credential=AzureKeyCredential("YOUR_API_KEY")
)

documents = ["Azure AI is an amazing platform for building intelligent apps."]

# Sentiment analysis
response = client.analyze_sentiment(documents=documents)
for doc in response:
    print(f"Sentiment: {doc.sentiment}, Scores: {doc.confidence_scores}")

# Entity recognition
response = client.recognize_entities(documents=documents)
for doc in response:
    for entity in doc.entities:
        print(f"Entity: {entity.text} ({entity.category})")

Decision Services

Service Description Use Case
Anomaly Detector Detect anomalies in time series data Monitoring, fraud detection, IoT
Content Safety Detect harmful content in text and images Content moderation, user safety
Personalizer Deliver personalized experiences using reinforcement learning Content recommendations, UI optimization
Multi-Service Resource: Create a single Azure AI Services resource to access all cognitive services (Vision, Speech, Language, Decision) with one API key and endpoint. This simplifies management and billing.

AI Capabilities Added!

You can now integrate pre-built AI into any application. In the final lesson, explore best practices for enterprise Azure AI deployments.

Next: Best Practices →