Skip to content

Commit 36c02a3

Browse files
authored
adding the playprompt list support for play media, play media to all and recognize media (#35692)
* updating changes for play prompts * adding the support for play prompt list * adding test for multipe prompts
1 parent b162511 commit 36c02a3

File tree

3 files changed

+509
-38
lines changed

3 files changed

+509
-38
lines changed

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

Lines changed: 202 additions & 19 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
7+
from typing import TYPE_CHECKING, Optional, List, Union, Dict, overload
88
from urllib.parse import urlparse
99
import warnings
1010

@@ -411,7 +411,7 @@ def remove_participant(
411411

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

414-
@distributed_trace
414+
@overload
415415
def play_media(
416416
self,
417417
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
@@ -444,19 +444,61 @@ def play_media(
444444
:rtype: None
445445
:raises ~azure.core.exceptions.HttpResponseError:
446446
"""
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
463+
list[~azure.communication.callautomation.TextSource] or
464+
list[~azure.communication.callautomation.SsmlSource]
465+
:param play_to: The targets to play media to. Default value is 'all', to play media
466+
to all participants in the call.
467+
:type play_to: list[~azure.communication.callautomation.CommunicationIdentifier]
468+
:keyword loop: Whether the media should be repeated until cancelled.
469+
:paramtype loop: bool
470+
:keyword operation_context: Value that can be used to track this call and its associated events.
471+
:paramtype operation_context: str or None
472+
:keyword operation_callback_url: Set a callback URL that overrides the default callback URL set
473+
by CreateCall/AnswerCall for this operation.
474+
This setup is per-action. If this is not set, the default callback URL set by
475+
CreateCall/AnswerCall will be used.
476+
:paramtype operation_callback_url: str or None
477+
:return: None
478+
:rtype: None
479+
:raises ~azure.core.exceptions.HttpResponseError:
480+
"""
481+
482+
@distributed_trace
483+
def play_media(
484+
self,
485+
**kwargs
486+
) -> None:
487+
447488
self._play_media(
448-
play_source=play_source,
449-
play_to=play_to,
450-
loop=loop,
451-
operation_context=operation_context,
452-
operation_callback_url=operation_callback_url,
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),
453495
**kwargs
454496
)
455497

456-
@distributed_trace
457498
def _play_media(
458499
self,
459500
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
501+
play_sources: Optional[ List[Union['FileSource', 'TextSource', 'SsmlSource']]],
460502
play_to: Union[Literal["all"], List['CommunicationIdentifier']] = 'all',
461503
*,
462504
loop: bool = False,
@@ -471,6 +513,10 @@ def _play_media(
471513
:type play_source: ~azure.communication.callautomation.FileSource or
472514
~azure.communication.callautomation.TextSource or
473515
~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
518+
list[~azure.communication.callautomation.TextSource] or
519+
list[~azure.communication.callautomation.SsmlSource]
474520
:param play_to: The targets to play media to. Default value is 'all', to play media
475521
to all participants in the call.
476522
:type play_to: list[~azure.communication.callautomation.CommunicationIdentifier]
@@ -492,15 +538,15 @@ def _play_media(
492538
"""
493539
play_source_single: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None
494540
if isinstance(play_source, list):
495-
warnings.warn("Currently only single play source per request is supported.")
496541
if play_source: # Check if the list is not empty
497-
play_source_single = play_source[0]
542+
play_sources = play_source
498543
else:
499544
play_source_single = play_source
500545

501546
audience = [] if play_to == "all" else [serialize_identifier(i) for i in play_to]
502547
play_request = PlayRequest(
503-
play_sources=[play_source_single._to_generated()], # pylint:disable=protected-access
548+
play_sources=[play_source_single._to_generated()] if play_source_single else # pylint:disable=protected-access
549+
[source._to_generated() for source in play_sources] if play_sources else None, # pylint:disable=protected-access
504550
play_to=audience,
505551
play_options=PlayOptions(loop=loop),
506552
interrupt_call_media_operation=interrupt_call_media_operation,
@@ -510,7 +556,7 @@ def _play_media(
510556
)
511557
self._call_media_client.play(self._call_connection_id, play_request)
512558

513-
@distributed_trace
559+
@overload
514560
def play_media_to_all(
515561
self,
516562
play_source: Union['FileSource', 'TextSource', 'SsmlSource'],
@@ -547,16 +593,62 @@ def play_media_to_all(
547593
"The method 'play_media_to_all' is deprecated. Please use 'play_media' instead.",
548594
DeprecationWarning
549595
)
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
612+
list[~azure.communication.callautomation.TextSource] or
613+
list[~azure.communication.callautomation.SsmlSource]
614+
:keyword loop: Whether the media should be repeated until cancelled.
615+
:paramtype loop: bool
616+
:keyword operation_context: Value that can be used to track this call and its associated events.
617+
:paramtype operation_context: str or None
618+
:keyword operation_callback_url: Set a callback URL that overrides the default callback URL set
619+
by CreateCall/AnswerCall for this operation.
620+
This setup is per-action. If this is not set, the default callback URL set by
621+
CreateCall/AnswerCall will be used.
622+
:paramtype operation_callback_url: str or None
623+
:keyword interrupt_call_media_operation: If set play can barge into other existing
624+
queued-up/currently-processing requests.
625+
:paramtype interrupt_call_media_operation: bool
626+
:return: None
627+
:rtype: None
628+
:raises ~azure.core.exceptions.HttpResponseError:
629+
"""
630+
warnings.warn(
631+
"The method 'play_media_to_all' is deprecated. Please use 'play_media' instead.",
632+
DeprecationWarning
633+
)
634+
635+
@distributed_trace
636+
def play_media_to_all(
637+
self,
638+
**kwargs
639+
) -> None:
640+
550641
self._play_media(
551-
play_source=play_source,
552-
loop=loop,
553-
operation_context=operation_context,
554-
operation_callback_url=operation_callback_url,
555-
interrupt_call_media_operation=interrupt_call_media_operation,
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),
556648
**kwargs
557649
)
558650

559-
@distributed_trace
651+
@overload
560652
def start_recognizing_media(
561653
self,
562654
input_type: Union[str, 'RecognizeInputType'],
@@ -623,6 +715,97 @@ def start_recognizing_media(
623715
:rtype: None
624716
:raises ~azure.core.exceptions.HttpResponseError:
625717
"""
718+
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:
792+
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)
626809
options = RecognizeOptions(
627810
interrupt_prompt=interrupt_prompt,
628811
initial_silence_timeout_in_seconds=initial_silence_timeout,
@@ -633,7 +816,6 @@ def start_recognizing_media(
633816

634817
play_source_single: Optional[Union['FileSource', 'TextSource', 'SsmlSource']] = None
635818
if isinstance(play_prompt, list):
636-
warnings.warn("Currently only single play source per request is supported.")
637819
if play_prompt: # Check if the list is not empty
638820
play_source_single = play_prompt[0]
639821
else:
@@ -668,6 +850,7 @@ def start_recognizing_media(
668850
recognize_request = RecognizeRequest(
669851
recognize_input_type=input_type,
670852
play_prompt=play_source_single._to_generated() if play_source_single else None, # pylint:disable=protected-access
853+
play_prompts=[prompt._to_generated() for prompt in play_prompts] if play_prompts else None, # pylint:disable=protected-access
671854
interrupt_call_media_operation=interrupt_call_media_operation,
672855
operation_context=operation_context,
673856
recognize_options=options,

0 commit comments

Comments
 (0)