33
44import logging
55import time
6- import warnings
76from collections .abc import Awaitable , Callable
87from typing import TYPE_CHECKING , Any , Optional
98
1211
1312from pyrit .auth .azure_auth import get_speech_config , get_speech_config_async
1413from pyrit .common import default_values
14+ from pyrit .common .deprecation import print_deprecation_message
1515from pyrit .identifiers import ComponentIdentifier
1616from pyrit .models import PromptDataType , data_serializer_factory
1717from pyrit .prompt_converter .prompt_converter import ConverterResult , PromptConverter
@@ -66,8 +66,16 @@ def __init__(
6666 If omitted, Entra ID auth via ``DefaultAzureCredential`` is used automatically.
6767 azure_speech_resource_id (str, Optional): The resource ID for accessing the service when using
6868 Entra ID auth. Required when using a callable token provider or when no API key is available.
69- use_entra_auth (bool, Optional): **Deprecated.** Will be removed in v0.15.0.
70- Authentication is now auto-detected from the provided credentials.
69+ use_entra_auth (bool, Optional): **Deprecated.** Will be removed in 0.15.0.
70+ Authentication is now selected automatically based on what you pass to
71+ ``azure_speech_key`` (and ``AZURE_SPEECH_KEY`` env var):
72+
73+ - Pass a **string** API key (or set ``AZURE_SPEECH_KEY``) to use API-key auth.
74+ - Pass a **callable token provider** (sync or async returning a token string)
75+ to use Entra ID with a custom token; ``azure_speech_resource_id`` must also
76+ be set.
77+ - Omit ``azure_speech_key`` entirely to use Entra ID via
78+ ``DefaultAzureCredential``; ``azure_speech_resource_id`` must be set.
7179 recognition_language (str): Recognition voice language. Defaults to "en-US".
7280 For more on supported languages, see the following link:
7381 https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support
@@ -76,12 +84,13 @@ def __init__(
7684 ValueError: If the required environment variables or parameters are not set.
7785 """
7886 if use_entra_auth is not None :
79- warnings .warn (
80- "'use_entra_auth' is deprecated and will be removed in v0.15.0. "
81- "Authentication is now auto-detected: pass a key string for key auth, "
82- "a callable token provider for token auth, or omit for automatic Entra ID auth." ,
83- DeprecationWarning ,
84- stacklevel = 2 ,
87+ print_deprecation_message (
88+ old_item = "AzureSpeechAudioToTextConverter(use_entra_auth=...)" ,
89+ new_item = (
90+ "AzureSpeechAudioToTextConverter("
91+ "azure_speech_key=<api-key-string-or-callable-token-provider-or-omit>)"
92+ ),
93+ removed_in = "0.15.0" ,
8594 )
8695
8796 self ._azure_speech_region : str = default_values .get_required_value (
@@ -189,11 +198,10 @@ def recognize_audio(self, audio_bytes: bytes) -> str:
189198 ModuleNotFoundError: If the azure.cognitiveservices.speech module is not installed.
190199 """
191200 if self ._token_provider :
192- warnings .warn (
193- "recognize_audio() does not support callable token providers. "
194- "Use convert_async() instead, which correctly resolves token providers." ,
195- DeprecationWarning ,
196- stacklevel = 2 ,
201+ print_deprecation_message (
202+ old_item = "AzureSpeechAudioToTextConverter.recognize_audio" ,
203+ new_item = "AzureSpeechAudioToTextConverter.convert_async" ,
204+ removed_in = "0.15.0" ,
197205 )
198206 speech_config = get_speech_config (
199207 resource_id = self ._azure_speech_resource_id ,
0 commit comments