SDKs overview
Microsoft Cognitive Services offers a suite of Software Development Kits (SDKs) designed to facilitate the integration of its artificial intelligence capabilities into various applications. These SDKs abstract the underlying RESTful API interactions, providing developers with language-specific interfaces for services such as Azure AI Vision, Azure AI Speech, and Azure AI Language. The availability of SDKs across multiple programming languages aims to support a broad developer base leveraging Microsoft's AI offerings within the Azure ecosystem Azure AI Services documentation.
The SDKs are developed and maintained by Microsoft, ensuring compatibility with the latest API versions and features. They typically handle common tasks such as authentication with Azure resources, serialization and deserialization of data, and error handling. This standardization helps reduce the boilerplate code required to interact with the services directly via HTTP requests. Developers can find comprehensive guides and API references on the official Microsoft Learn platform Azure AI Services API reference.
Official SDKs by language
Microsoft provides official SDKs for several popular programming languages. These SDKs are maintained to ensure compatibility with the various Azure AI services and typically follow the design patterns common to each specific language ecosystem. The primary languages supported include Python, C#, Java, JavaScript, and Go. Each SDK is generally distributed through standard package managers for its respective language.
| Language | Primary Package/Client | Maturity | Installation Command Example |
|---|---|---|---|
| Python | azure-cognitiveservices-* |
Generally Available | pip install azure-cognitiveservices-speech |
| C# | Microsoft.Azure.CognitiveServices.* |
Generally Available | dotnet add package Microsoft.Azure.CognitiveServices.Vision.Face |
| Java | com.azure.ai.* |
Generally Available | Maven: <dependency><groupId>com.azure</groupId><artifactId>azure-ai-textanalytics</artifactId></dependency> |
| JavaScript | @azure/cognitiveservices-* |
Generally Available | npm install @azure/cognitiveservices-speech |
| Go | github.com/Azure/azure-sdk-for-go/sdk/cognitiveservices/* |
Generally Available | go get github.com/Azure/azure-sdk-for-go/sdk/cognitiveservices/azurespeech |
Each service within Azure AI often has its own specific client library within these language SDKs. For instance, there are distinct client libraries for Speech, Vision, and Language services, allowing developers to install only the components relevant to their project Azure AI Services documentation overview.
Installation
Installation of Microsoft Cognitive Services SDKs typically follows the standard practices for each programming language's ecosystem. Below are general instructions for the primary supported languages:
Python
Python SDKs are distributed via PyPI. You can install specific service libraries using pip:
pip install azure-cognitiveservices-speech
pip install azure-cognitiveservices-vision-computervision
For more details on specific Python package names for Azure AI services, refer to the official Azure Cognitive Services Python SDK reference.
C# (.NET)
C# SDKs are available as NuGet packages. You can install them using the .NET CLI or NuGet Package Manager in Visual Studio:
dotnet add package Microsoft.Azure.CognitiveServices.Speech
dotnet add package Microsoft.Azure.CognitiveServices.Vision.ComputerVision
Consult the Azure Cognitive Services .NET SDK reference for detailed package information.
Java
Java SDKs are typically managed with Maven or Gradle. Add the dependencies to your pom.xml (Maven) or build.gradle (Gradle) file:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-textanalytics</artifactId>
<version>5.2.0</version> <!-- Check for the latest version -->
</dependency>
Find the exact dependency information on the Azure Cognitive Services Java SDK documentation.
JavaScript/TypeScript
JavaScript SDKs are available via npm. Install them in your project using npm or yarn:
npm install @azure/cognitiveservices-speech
yarn add @azure/cognitiveservices-computervision
For comprehensive details on JavaScript client libraries, refer to the Azure Cognitive Services JavaScript SDK reference.
Go
Go SDKs are installed using the go get command:
go get github.com/Azure/azure-sdk-for-go/sdk/cognitiveservices/azurespeech
go get github.com/Azure/azure-sdk-for-go/sdk/cognitiveservices/azuredocumentintelligence
The Azure Cognitive Services Go SDK documentation provides the latest package paths.
Quickstart example
This Python example demonstrates how to use the Azure AI Speech SDK to convert text to speech. Before running, ensure you have an Azure Speech resource created and its API key and endpoint readily available Azure Speech text-to-speech quickstart.
import os
import azure.cognitiveservices.speech as speechsdk
# This example requires the Speech SDK to be installed.
# pip install azure-cognitiveservices-speech
# Replace with your own subscription key and service region (e.g., "westus", "eastus")
SPEECH_KEY = os.environ.get('SPEECH_KEY')
SPEECH_REGION = os.environ.get('SPEECH_REGION')
def text_to_speech():
if not SPEECH_KEY or not SPEECH_REGION:
print("Please set the SPEECH_KEY and SPEECH_REGION environment variables.")
return
# Creates an instance of a speech config with specified subscription key and service region.
speech_config = speechsdk.SpeechConfig(subscription=SPEECH_KEY, region=SPEECH_REGION)
# Optional: Set the voice name, e.g., "en-US-JennyNeural"
speech_config.speech_synthesis_voice_name = "en-US-JennyNeural"
# Creates a speech synthesizer using the default speaker as audio output.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
# Receives a text from console input and synthesizes it to speaker.
print("Type some text that you want to speak...")
text = input()
if not text:
print("No text entered. Exiting.")
return
result = speech_synthesizer.speak_text_async(text).get()
# Checks result.
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
print("Speech synthesized for text [{}]".format(text))
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print("Speech synthesis canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
if cancellation_details.error_details:
print("Error details: {}".format(cancellation_details.error_details))
print("Did you set the speech resource key and region?")
if __name__ == "__main__":
text_to_speech()
This script initializes the speech configuration with your Azure Speech key and region, then synthesizes user-provided text into audio output. It demonstrates basic setup, text input, and error handling for the text-to-speech service.
Community libraries
While Microsoft provides official SDKs for its Cognitive Services, the broader developer community also contributes libraries and wrappers. These community-driven projects can sometimes offer alternative interfaces, specialized tooling, or integrations with frameworks not directly supported by official SDKs. However, it's important to note that community libraries may not always maintain the same level of support, API consistency, or security guarantees as the official Microsoft-provided SDKs. Developers should evaluate community offerings based on their specific project requirements, community activity, and maintenance status.
Examples of community contributions might include:
- Framework-specific integrations: Libraries that simplify integrating Cognitive Services with popular web frameworks like Django, Flask, or React.
- Simplified wrappers: Higher-level abstractions that aim to reduce the complexity of the official SDKs for specific use cases.
- Specialized tools: Command-line tools or desktop applications built on top of Cognitive Services APIs using various languages.
When considering community libraries, it is advisable to check their GitHub repositories or other distribution channels for recent updates, issue tracking, and contributor activity. Resources like GitHub and broader developer forums are the primary avenues for discovering and evaluating such community-contributed projects Google's guide to contributing to open source, which provides general advice applicable to evaluating open-source projects.
For critical production systems, the official SDKs are generally recommended due to their direct support from Microsoft and guaranteed compatibility with the underlying Azure AI services.