Microsoft Cognitive Services Speech SDK Samples
repository·master·Indexed 25 days ago
https://github.com/azure-samples/cognitive-services-speech-sdkA collection of samples for the Microsoft Cognitive Services Speech SDK to help developers implement speech recognition, synthesis, and translation. Includes C++ quickstarts for Linux, macOS, and Windows, covering scenarios such as recognizing speech from a microphone or file and performing text-to-speech synthesis.
What's inside cognitive-services-speech-sdk
- The Ingestion Client is an automated, scalable transcription solution that monitors an Azure Storage container. When new audio files land in the dedicated container, the client automatically triggers transcription using the Azure Speech service batch pipeline. It can also be configured to perform additional text analytics, such as sentiment analysis, PII redaction, and mapping transcripts to a SQL database.
Overview of SpeechSDKRemoteServiceGRPC architecture
masterThe
SpeechSDKRemoteServiceGRPCproject implements a middle-tier service in a multi-tier architecture. It acts as a bridge between an edge client device and the Azure Speech Service using GRPC as the transport layer.Workflow:
- Edge Client Device: Sends audio data via GRPC.
- Middle Tier Service: Receives audio, processes it using the Azure Speech SDK.
- Azure Speech SDK/Service: Performs the actual speech recognition.
The architecture includes a robust protocol to handle link failures by allowing the client to resend unacknowledged audio data.
Overview of Embedded and Hybrid Speech in C++
masterThis sample project demonstrates two speech modes using the Speech SDK for C++:
- Embedded Speech: Enables offline (on-device) speech recognition, synthesis, and translation.
- Hybrid Speech: Uses cloud speech services by default and falls back to embedded speech if cloud connectivity is limited.
Audio Format Requirements for Embedded Speech
Embedded speech recognition and translation only support audio in the following format:
- Single channel
- 8000 or 16000 Hz sample rate
- 16-bit little-endian signed integer samples
Quickstart: Using Voice Assistants in C# Universal Windows Platform
masterThis sample demonstrates how to implement a Voice Assistant using C# and the Universal Windows Platform (UWP). It enables speech recognition and allows the application to receive and display activity responses from a bot.Overview of SpeechSDKRemoteClientCore
masterTheSpeechSDKRemoteClientCoreis a core component designed for building a middle-tier service that processes audio from an Edge Client device. It serves as a shared library for different client transport implementations (such as WebSockets or gRPC) to handle audio streaming and communication with a middle-tier service, which then interacts with the Azure Speech Service.Overview of Ingestion Client
masterThe Ingestion Client is a solution designed to accelerate transcription capabilities. It automatically transcribes audio files that are uploaded to an Azure Storage Container.Implement Multi-tier Speech SDK Architecture
masterThe Multi-tier Speech SDK Sample provides a pattern for implementing Azure Speech SDK functionality where audio capture and speech recognition results are processed on a middle-tier server instead of the client device. This is useful when:
- The Speech SDK cannot run directly on the client device.
- You need to apply additional business logic or processing on a middle tier.
- You need to maintain persistent Speech SDK connections across multiple client sessions.
- You require robust audio transport over unreliable networks.
Advanced Objective-C iOS Speech Techniques
masterThe Objective-C samples for iOS provide implementations for several advanced speech scenarios:
Connection Management
The
connection-sampledemonstrates how to establish a connection to the speech service independently of starting a recognition task. This technique is used to reduce latency for the initial recognition task (e.g., recognition from a microphone).Speech Recognition and Translation
The
speech-samplesapp demonstrates:- Using phrase hints to improve recognition accuracy.
- Implementing continuous recognition.
- Using push and pull audio streams.
Speech Synthesis (TTS)
The
synthesis-samplesapp demonstrates:- Using push and pull audio streams (or audio data streams) to fetch synthesized audio streamingly to minimize latency.
- Using event handlers to manage synthesis events.
Prerequisites and Authentication for Batch Synthesis
masterBefore using the Batch Synthesis API, ensure you meet the following requirements:
Requirements
- Python: Version 3.8 or higher.
- Subscription: Batch synthesis is only available for paid subscriptions; free subscriptions are not supported.
- Custom Voices (Optional): You need the relationship between custom voice names and deployment ID.
- Azure Blob Storage (Optional): The URI of a writable Azure blob container if you wish to store audio files in your own storage.
Authentication Options
- Passwordless (Recommended): Use the
azure-identitylibrary. Your Microsoft Entra user account must be assigned theCognitive Services UserorCognitive Services Speech Userrole. - API Key: Use the subscription key found in the "Keys and Endpoint" tab of your Azure AI Speech resource in the Azure Portal.
Access Shared Content for Language Learning Samples
masterThescenarios/csharp/sharedcontent/consoledirectory contains shared assets used by the Language Learning samples. This content is utilized by both the .NET Framework (Windows) and .NET Core (Windows or Linux) implementations. To use these samples, refer to their respective documentation for setup and execution instructions.TTS Text Stream functionality overview
masterThe TTS Text Stream sample demonstrates the following capabilities using the Speech SDK:
- Incremental Text Streaming: Uses
SpeechSynthesisRequestInputType.TextStreamto push text to Azure TTS in small chunks. - Audio Collection: Collects streamed PCM audio from an
AudioDataStreamand writes the result to a WAV file. - Endpoint Usage: Utilizes the websocket v2 endpoint required for text stream APIs.
- Incremental Text Streaming: Uses
Use Batch Avatar Synthesis via REST API
masterThe Batch avatar synthesis API (Preview) allows for asynchronous synthesis of talking avatars to generate video content from text input.
Important Implementation Note: These samples do NOT require the installation of the Cognitive Service Speech SDK. Instead, they interact with the Batch avatar synthesis functionality by calling the REST API directly.
For real-time avatar synthesis (as opposed to batch), refer to the real-time avatar synthesis documentation.