Skip to main content

Azure Azure Speech

The AzureTTSService provides professional, natural-sounding speech using Azure Cognitive Services. It's the recommended TTS provider for enterprise-grade applications requiring massive scale and extensive voice support.

Installation

To use Azure TTS, install the required dependencies:

pip install "piopiy-ai[azure]"

Prerequisites

  • An Azure subscription and a Speech service resource (Get yours here).
  • Azure API key and region.
  • Set your credentials in your environment:
    export AZURE_SPEECH_API_KEY="your_api_key_here"
    export AZURE_SPEECH_REGION="your_region_here"

Configuration

AzureTTSService Parameters

ParameterTypeDefaultDescription
api_keystrRequiredYour Azure Speech API key.
regionstrRequiredAzure region (e.g., "eastus").
voicestr"en-US-SaraNeural"Azure voice identifier.
paramsInputParamsInputParams()Advanced prosody and style settings.

InputParams

ParameterTypeDefaultDescription
stylestrNoneSpeaking style (e.g., "cheerful").
pitchstrNoneVoice pitch adjustment.
ratestr"1.05"Speech rate multiplier.
volumestrNoneVolume level adjustment.

Usage

Basic Setup

import os
from piopiy.services.azure.tts import AzureTTSService

tts = AzureTTSService(
api_key=os.getenv("AZURE_SPEECH_API_KEY"),
region=os.getenv("AZURE_SPEECH_REGION"),
voice="en-US-EmmaNeural"
)

With Expressive Styles

from piopiy.services.azure.tts import AzureTTSService

tts = AzureTTSService(
api_key=os.getenv("AZURE_SPEECH_API_KEY"),
region="eastus",
params=AzureTTSService.InputParams(
style="cheerful",
rate="1.1"
)
)

Notes

  • Word Timestamps: AzureTTSService supports precise word-level timestamps, enabling synchronized visual feedback or animations.
  • SSML: The service automatically generates SSML to apply your configuration parameters efficiently.