Skip to content

Commit 9049ca9

Browse files
author
Vinothini Dharmaraj
committed
updating the play prompts
1 parent 36c02a3 commit 9049ca9

File tree

3 files changed

+76
-412
lines changed

3 files changed

+76
-412
lines changed

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_call_connection_client.py

Lines changed: 38 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Licensed under the MIT License. See License.txt in the project root for
55
# license information.
66
# --------------------------------------------------------------------------
7-
from typing import TYPE_CHECKING, Optional, List, Union, Dict, overload
7+
from typing import TYPE_CHECKING, Optional, List, Union, Dict
88
from urllib.parse import urlparse
99
import warnings
1010

@@ -411,10 +411,11 @@ def remove_participant(
411411

412412
return RemoveParticipantResult._from_generated(response) # pylint:disable=protected-access
413413

414-
@overload
414+
@distributed_trace
415415
def play_media(
416416
self,
417-
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
417+
play_source: Union[Union['FileSource', 'TextSource', 'SsmlSource'],
418+
List[Union['FileSource', 'TextSource', 'SsmlSource']]],
418419
play_to: Union[Literal["all"], List['CommunicationIdentifier']] = 'all',
419420
*,
420421
loop: bool = False,
@@ -427,39 +428,8 @@ def play_media(
427428
:param play_source: A PlaySource representing the source to play.
428429
:type play_source: ~azure.communication.callautomation.FileSource or
429430
~azure.communication.callautomation.TextSource or
430-
~azure.communication.callautomation.SsmlSource
431-
:param play_to: The targets to play media to. Default value is 'all', to play media
432-
to all participants in the call.
433-
:type play_to: list[~azure.communication.callautomation.CommunicationIdentifier]
434-
:keyword loop: Whether the media should be repeated until cancelled.
435-
:paramtype loop: bool
436-
:keyword operation_context: Value that can be used to track this call and its associated events.
437-
:paramtype operation_context: str or None
438-
:keyword operation_callback_url: Set a callback URL that overrides the default callback URL set
439-
by CreateCall/AnswerCall for this operation.
440-
This setup is per-action. If this is not set, the default callback URL set by
441-
CreateCall/AnswerCall will be used.
442-
:paramtype operation_callback_url: str or None
443-
:return: None
444-
:rtype: None
445-
:raises ~azure.core.exceptions.HttpResponseError:
446-
"""
447-
448-
@overload
449-
def play_media(
450-
self,
451-
play_sources: List[Union['FileSource', 'TextSource', 'SsmlSource']],
452-
play_to: Union[Literal["all"], List['CommunicationIdentifier']] = 'all',
453-
*,
454-
loop: bool = False,
455-
operation_context: Optional[str] = None,
456-
operation_callback_url: Optional[str] = None,
457-
**kwargs
458-
) -> None:
459-
"""Play media to specific participant(s) in this call.
460-
461-
:param play_sources: A PlaySource representing the source to play.
462-
:type play_sources: list[~azure.communication.callautomation.FileSource] or
431+
~azure.communication.callautomation.SsmlSource or
432+
list[~azure.communication.callautomation.FileSource] or
463433
list[~azure.communication.callautomation.TextSource] or
464434
list[~azure.communication.callautomation.SsmlSource]
465435
:param play_to: The targets to play media to. Default value is 'all', to play media
@@ -478,27 +448,19 @@ def play_media(
478448
:rtype: None
479449
:raises ~azure.core.exceptions.HttpResponseError:
480450
"""
481-
482-
@distributed_trace
483-
def play_media(
484-
self,
485-
**kwargs
486-
) -> None:
487-
488451
self._play_media(
489-
play_source=kwargs.pop("play_source", None),
490-
play_sources=kwargs.pop("play_sources", None),
491-
play_to=kwargs.pop("play_to", 'all'),
492-
loop=kwargs.pop("loop", False),
493-
operation_context=kwargs.pop("operation_context", None),
494-
operation_callback_url=kwargs.pop("operation_callback_url", None),
452+
play_source=play_source,
453+
play_to=play_to,
454+
loop=loop,
455+
operation_context=operation_context,
456+
operation_callback_url=operation_callback_url,
495457
**kwargs
496458
)
497459

498460
def _play_media(
499461
self,
500-
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
501-
play_sources: Optional[ List[Union['FileSource', 'TextSource', 'SsmlSource']]],
462+
play_source: Union[Union['FileSource', 'TextSource', 'SsmlSource'],
463+
List[Union['FileSource', 'TextSource', 'SsmlSource']]],
502464
play_to: Union[Literal["all"], List['CommunicationIdentifier']] = 'all',
503465
*,
504466
loop: bool = False,
@@ -512,9 +474,8 @@ def _play_media(
512474
:param play_source: A PlaySource representing the source to play.
513475
:type play_source: ~azure.communication.callautomation.FileSource or
514476
~azure.communication.callautomation.TextSource or
515-
~azure.communication.callautomation.SsmlSource
516-
:param play_sources: A PlaySource representing the source to play.
517-
:type play_sources: list[~azure.communication.callautomation.FileSource] or
477+
~azure.communication.callautomation.SsmlSource or
478+
list[~azure.communication.callautomation.FileSource] or
518479
list[~azure.communication.callautomation.TextSource] or
519480
list[~azure.communication.callautomation.SsmlSource]
520481
:param play_to: The targets to play media to. Default value is 'all', to play media
@@ -536,7 +497,9 @@ def _play_media(
536497
:rtype: None
537498
:raises ~azure.core.exceptions.HttpResponseError:
538499
"""
500+
539501
play_source_single: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None
502+
play_sources: Optional[List[Union['FileSource', 'TextSource', 'SsmlSource']]] = None
540503
if isinstance(play_source, list):
541504
if play_source: # Check if the list is not empty
542505
play_sources = play_source
@@ -556,10 +519,11 @@ def _play_media(
556519
)
557520
self._call_media_client.play(self._call_connection_id, play_request)
558521

559-
@overload
522+
@distributed_trace
560523
def play_media_to_all(
561524
self,
562-
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
525+
play_source: Union[Union['FileSource', 'TextSource', 'SsmlSource'],
526+
List[Union['FileSource', 'TextSource', 'SsmlSource']]],
563527
*,
564528
loop: bool = False,
565529
operation_context: Optional[str] = None,
@@ -572,43 +536,8 @@ def play_media_to_all(
572536
:param play_source: A PlaySource representing the source to play.
573537
:type play_source: ~azure.communication.callautomation.FileSource or
574538
~azure.communication.callautomation.TextSource or
575-
~azure.communication.callautomation.SsmlSource
576-
:keyword loop: Whether the media should be repeated until cancelled.
577-
:paramtype loop: bool
578-
:keyword operation_context: Value that can be used to track this call and its associated events.
579-
:paramtype operation_context: str or None
580-
:keyword operation_callback_url: Set a callback URL that overrides the default callback URL set
581-
by CreateCall/AnswerCall for this operation.
582-
This setup is per-action. If this is not set, the default callback URL set by
583-
CreateCall/AnswerCall will be used.
584-
:paramtype operation_callback_url: str or None
585-
:keyword interrupt_call_media_operation: If set play can barge into other existing
586-
queued-up/currently-processing requests.
587-
:paramtype interrupt_call_media_operation: bool
588-
:return: None
589-
:rtype: None
590-
:raises ~azure.core.exceptions.HttpResponseError:
591-
"""
592-
warnings.warn(
593-
"The method 'play_media_to_all' is deprecated. Please use 'play_media' instead.",
594-
DeprecationWarning
595-
)
596-
597-
@overload
598-
def play_media_to_all(
599-
self,
600-
play_sources: Optional[List[Union['FileSource', 'TextSource', 'SsmlSource']]],
601-
*,
602-
loop: bool = False,
603-
operation_context: Optional[str] = None,
604-
operation_callback_url: Optional[str] = None,
605-
interrupt_call_media_operation: bool = False,
606-
**kwargs
607-
) -> None:
608-
"""Play media to all participants in this call.
609-
610-
:param play_sources: A list of PlaySource representing the sources to play.
611-
:type play_sources: list[~azure.communication.callautomation.FileSource] or
539+
~azure.communication.callautomation.SsmlSource or
540+
list[~azure.communication.callautomation.FileSource] or
612541
list[~azure.communication.callautomation.TextSource] or
613542
list[~azure.communication.callautomation.SsmlSource]
614543
:keyword loop: Whether the media should be repeated until cancelled.
@@ -632,30 +561,24 @@ def play_media_to_all(
632561
DeprecationWarning
633562
)
634563

635-
@distributed_trace
636-
def play_media_to_all(
637-
self,
638-
**kwargs
639-
) -> None:
640-
641564
self._play_media(
642-
play_source=kwargs.pop("play_source", None),
643-
play_sources=kwargs.pop("play_sources", None),
644-
loop=kwargs.pop("loop", False),
645-
operation_context=kwargs.pop("operation_context", None),
646-
operation_callback_url=kwargs.pop("operation_callback_url", None),
647-
interrupt_call_media_operation=kwargs.pop("interrupt_call_media_operation", False),
565+
play_source=play_source,
566+
loop=loop,
567+
operation_context=operation_context,
568+
operation_callback_url=operation_callback_url,
569+
interrupt_call_media_operation=interrupt_call_media_operation,
648570
**kwargs
649571
)
650572

651-
@overload
573+
@distributed_trace
652574
def start_recognizing_media(
653575
self,
654576
input_type: Union[str, 'RecognizeInputType'],
655577
target_participant: 'CommunicationIdentifier',
656578
*,
657579
initial_silence_timeout: Optional[int] = None,
658-
play_prompt: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None,
580+
play_prompt: Optional[Union[Union['FileSource', 'TextSource', 'SsmlSource'],
581+
List[Union['FileSource', 'TextSource', 'SsmlSource']]]] = None,
659582
interrupt_call_media_operation: bool = False,
660583
operation_context: Optional[str] = None,
661584
interrupt_prompt: bool = False,
@@ -716,96 +639,14 @@ def start_recognizing_media(
716639
:raises ~azure.core.exceptions.HttpResponseError:
717640
"""
718641

719-
@overload
720-
def start_recognizing_media(
721-
self,
722-
input_type: Union[str, 'RecognizeInputType'],
723-
target_participant: 'CommunicationIdentifier',
724-
*,
725-
initial_silence_timeout: Optional[int] = None,
726-
play_prompts: Optional[List[Union['FileSource', 'TextSource', 'SsmlSource']]] = None,
727-
interrupt_call_media_operation: bool = False,
728-
operation_context: Optional[str] = None,
729-
interrupt_prompt: bool = False,
730-
dtmf_inter_tone_timeout: Optional[int] = None,
731-
dtmf_max_tones_to_collect: Optional[int] = None,
732-
dtmf_stop_tones: Optional[List[str or 'DtmfTone']] = None,
733-
speech_language: Optional[str] = None,
734-
choices: Optional[List['RecognitionChoice']] = None,
735-
end_silence_timeout: Optional[int] = None,
736-
speech_recognition_model_endpoint_id: Optional[str] = None,
737-
operation_callback_url: Optional[str] = None,
738-
**kwargs
739-
) -> None:
740-
"""Recognize inputs from specific participant in this call.
741-
742-
:param input_type: Determines the type of the recognition.
743-
:type input_type: str or ~azure.communication.callautomation.RecognizeInputType
744-
:param target_participant: Target participant of DTMF tone recognition.
745-
:type target_participant: ~azure.communication.callautomation.CommunicationIdentifier
746-
:keyword initial_silence_timeout: Time to wait for first input after prompt in seconds (if any).
747-
:paramtype initial_silence_timeout: int
748-
:keyword play_prompts: The source of the audio to be played for recognition.
749-
:paramtype play_prompts: ~azure.communication.callautomation.FileSource or
750-
~azure.communication.callautomation.TextSource or
751-
~azure.communication.callautomation.SsmlSource
752-
:keyword interrupt_call_media_operation:
753-
If set recognize can barge into other existing queued-up/currently-processing requests.
754-
:paramtype interrupt_call_media_operation: bool
755-
:keyword operation_context: Value that can be used to track this call and its associated events.
756-
:paramtype operation_context: str
757-
:keyword interrupt_prompt: Determines if we interrupt the prompt and start recognizing.
758-
:paramtype interrupt_prompt: bool
759-
:keyword dtmf_inter_tone_timeout: Time to wait between DTMF inputs to stop recognizing. Will be ignored
760-
unless input_type is 'dtmf' or 'speechOrDtmf'.
761-
:paramtype dtmf_inter_tone_timeout: int
762-
:keyword dtmf_max_tones_to_collect: Maximum number of DTMF tones to be collected. Will be ignored
763-
unless input_type is 'dtmf' or 'speechOrDtmf'.
764-
:paramtype dtmf_max_tones_to_collect: int
765-
:keyword dtmf_stop_tones: List of tones that will stop recognizing. Will be ignored
766-
unless input_type is 'dtmf' or 'speechOrDtmf'.
767-
:paramtype dtmf_stop_tones: list[str or ~azure.communication.callautomation.DtmfTone]
768-
:keyword speech_language: Speech language to be recognized, If not set default is en-US.
769-
:paramtype speech_language: str
770-
:keyword choices: Defines Ivr choices for recognize. Will be ignored unless input_type is 'choices'.
771-
:paramtype choices: list[~azure.communication.callautomation.RecognitionChoice]
772-
:keyword end_silence_timeout: The length of end silence when user stops speaking and cogservice
773-
send response. Will be ingored unless input_type is 'speech' or 'speechOrDtmf'.
774-
:paramtype end_silence_timeout: int
775-
:keyword speech_recognition_model_endpoint_id: Endpoint where the custom model was deployed.
776-
:paramtype speech_recognition_model_endpoint_id: str
777-
:keyword operation_callback_url: Set a callback URL that overrides the default callback URL set
778-
by CreateCall/AnswerCall for this operation.
779-
This setup is per-action. If this is not set, the default callback URL set by
780-
CreateCall/AnswerCall will be used.
781-
:paramtype operation_callback_url: str or None
782-
:return: None
783-
:rtype: None
784-
:raises ~azure.core.exceptions.HttpResponseError:
785-
"""
786-
787-
@distributed_trace
788-
def start_recognizing_media(
789-
self,
790-
**kwargs
791-
) -> None:
642+
play_prompt_single: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None
643+
play_prompts: Optional[List[Union['FileSource', 'TextSource', 'SsmlSource']]] = None
644+
if isinstance(play_prompt, list):
645+
if play_prompt: # Check if the list is not empty
646+
play_prompts = play_prompt
647+
else:
648+
play_prompt_single = play_prompt
792649

793-
play_prompt = kwargs.pop("play_prompt", None)
794-
input_type=kwargs.pop("input_type")
795-
target_participant=kwargs.pop("target_participant")
796-
initial_silence_timeout=kwargs.pop("initial_silence_timeout", None)
797-
speech_language=kwargs.pop("speech_language", None)
798-
speech_recognition_model_endpoint_id=kwargs.pop("speech_recognition_model_endpoint_id", None)
799-
play_prompts=kwargs.pop("play_prompts", None)
800-
interrupt_call_media_operation=kwargs.pop("interrupt_call_media_operation", False)
801-
operation_context=kwargs.pop("operation_context", None)
802-
interrupt_prompt=kwargs.pop("interrupt_prompt", False)
803-
dtmf_inter_tone_timeout=kwargs.pop("dtmf_inter_tone_timeout", None)
804-
dtmf_max_tones_to_collect=kwargs.pop("dtmf_max_tones_to_collect", None)
805-
dtmf_stop_tones=kwargs.pop("dtmf_stop_tones", None)
806-
choices=kwargs.pop("choices", None)
807-
end_silence_timeout=kwargs.pop("end_silence_timeout", None)
808-
operation_callback_url=kwargs.pop("operation_callback_url", None)
809650
options = RecognizeOptions(
810651
interrupt_prompt=interrupt_prompt,
811652
initial_silence_timeout_in_seconds=initial_silence_timeout,
@@ -814,13 +655,6 @@ def start_recognizing_media(
814655
speech_recognition_model_endpoint_id=speech_recognition_model_endpoint_id
815656
)
816657

817-
play_source_single: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None
818-
if isinstance(play_prompt, list):
819-
if play_prompt: # Check if the list is not empty
820-
play_source_single = play_prompt[0]
821-
else:
822-
play_source_single = play_prompt
823-
824658
if input_type == RecognizeInputType.DTMF:
825659
dtmf_options=DtmfOptions(
826660
inter_tone_timeout_in_seconds=dtmf_inter_tone_timeout,
@@ -849,7 +683,7 @@ def start_recognizing_media(
849683

850684
recognize_request = RecognizeRequest(
851685
recognize_input_type=input_type,
852-
play_prompt=play_source_single._to_generated() if play_source_single else None, # pylint:disable=protected-access
686+
play_prompt=play_prompt_single._to_generated() if play_prompt_single else None, # pylint:disable=protected-access
853687
play_prompts=[prompt._to_generated() for prompt in play_prompts] if play_prompts else None, # pylint:disable=protected-access
854688
interrupt_call_media_operation=interrupt_call_media_operation,
855689
operation_context=operation_context,

0 commit comments

Comments
 (0)