Skip to content

Commit

Permalink
Added Interrupt audio and announce api (#47533)
Browse files Browse the repository at this point in the history
* Added Interrupt audio and announce api

* pushed assets.json file

* updating the live test

* adding the events

* updating the playoptions

---------

Co-authored-by: Vinothini Dharmaraj <[email protected]>
  • Loading branch information
v-pivamshi and v-vdharmaraj authored Dec 23, 2024
1 parent 525faf2 commit 67033da
Show file tree
Hide file tree
Showing 35 changed files with 2,100 additions and 208 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/communication/Azure.Communication.CallAutomation",
"Tag": "net/communication/Azure.Communication.CallAutomation_42ef7c9c87"
"Tag": "net/communication/Azure.Communication.CallAutomation_639a28e13e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,39 @@ public class HoldEventResult
/// </summary>
public bool IsSuccess { get; internal set; }

/// <summary>
/// <see cref="HoldAudioCompleted"/> event will be returned once the hold audio is completed successfully.
/// </summary>
public HoldAudioCompleted SuccessResult { get; }

/// <summary>
/// <see cref="HoldAudioStarted"/> event will be returned once the hold audio has started successfully.
/// </summary>
public HoldAudioStarted StartResult { get; }

/// <summary>
/// <see cref="HoldAudioPaused"/> event will be returned once the hold audio is paused successfully.
/// </summary>
public HoldAudioPaused PauseResult { get; }

/// <summary>
/// <see cref="HoldAudioResumed"/> event will be returned once the hold audio is resumed successfully.
/// </summary>
public HoldAudioResumed ResumeResult { get; }

/// <summary>
/// <see cref="HoldFailed"/> event will be returned once the hold failed.
/// </summary>
public HoldFailed FailureResult { get; }

internal HoldEventResult(bool isSuccess, HoldFailed failureResult)
internal HoldEventResult(bool isSuccess, HoldAudioCompleted successResult, HoldFailed failureResult, HoldAudioStarted startResult, HoldAudioPaused pauseResult, HoldAudioResumed resumeResult)
{
IsSuccess = isSuccess;
SuccessResult = successResult;
FailureResult = failureResult;
StartResult = startResult;
PauseResult = pauseResult;
ResumeResult = resumeResult;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Communication.CallAutomation
{
/// <summary><see cref="InterruptAudioAndAnnounceEventResult"/> is returned from WaitForEvent of <see cref="InterruptAudioAndAnnounceResult"/>.</summary>
public class InterruptAudioAndAnnounceEventResult
{
/// <summary>
/// Indicates whether the returned event is considered successful or not.
/// </summary>
public bool IsSuccess { get; internal set; }

/// <summary>
/// <see cref="PlayStarted"/> event will be returned once the play has started successfully.
/// </summary>
public PlayStarted StartResult { get; }

/// <summary>
/// <see cref="PlayPaused"/> event will be returned once the play is paused successfully.
/// </summary>
public PlayPaused PauseResult { get; }

/// <summary>
/// <see cref="PlayResumed"/> event will be returned once the play is resumed successfully.
/// </summary>
public PlayResumed ResumeResult { get; }

/// <summary>
/// <see cref="PlayCompleted"/> event will be returned once the play is completed successfully.
/// </summary>
public PlayCompleted SuccessResult { get; }

/// <summary>
/// <see cref="PlayFailed"/> event will be returned once the play failed.
/// </summary>
public PlayFailed FailureResult { get; }

internal InterruptAudioAndAnnounceEventResult(bool isSuccess, PlayCompleted successResult, PlayFailed failureResult, PlayStarted startResult, PlayPaused pauseResult, PlayResumed resumeResult)
{
IsSuccess = isSuccess;
SuccessResult = successResult;
FailureResult = failureResult;
StartResult = startResult;
PauseResult = pauseResult;
ResumeResult = resumeResult;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ public class PlayEventResult
/// </summary>
public bool IsSuccess { get; internal set; }

/// <summary>
/// <see cref="PlayStarted"/> event will be returned once the play has started successfully.
/// </summary>
public PlayStarted StartResult { get; }

/// <summary>
/// <see cref="PlayPaused"/> event will be returned once the play is paused successfully.
/// </summary>
public PlayPaused PauseResult { get; }

/// <summary>
/// <see cref="PlayResumed"/> event will be returned once the play is resumed successfully.
/// </summary>
public PlayResumed ResumeResult { get; }

/// <summary>
/// <see cref="PlayCompleted"/> event will be returned once the play is completed successfully.
/// </summary>
Expand All @@ -21,11 +36,14 @@ public class PlayEventResult
/// </summary>
public PlayFailed FailureResult { get; }

internal PlayEventResult(bool isSuccess, PlayCompleted successResult, PlayFailed failureResult)
internal PlayEventResult(bool isSuccess, PlayCompleted successResult, PlayFailed failureResult, PlayStarted startResult, PlayPaused pauseResult, PlayResumed resumeResult)
{
IsSuccess = isSuccess;
SuccessResult = successResult;
FailureResult = failureResult;
StartResult = startResult;
PauseResult = pauseResult;
ResumeResult = resumeResult;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.Pipeline;

namespace Azure.Communication.CallAutomation
Expand Down Expand Up @@ -1270,7 +1269,7 @@ public virtual Response StartTranscription(StartTranscriptionOptions options = d
{
var request = options == default
? new StartTranscriptionRequestInternal()
: new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext, OperationCallbackUri=options.OperationCallbackUri, SpeechRecognitionModelEndpointId=options.SpeechRecognitionModelEndpointId };
: new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext, OperationCallbackUri = options.OperationCallbackUri, SpeechRecognitionModelEndpointId = options.SpeechRecognitionModelEndpointId };

return CallMediaRestClient.StartTranscription(CallConnectionId, request, cancellationToken);
}
Expand Down Expand Up @@ -1545,5 +1544,64 @@ public virtual async Task<Response> StopMediaStreamingAsync(StopMediaStreamingOp
throw;
}
}

/// <summary>
/// Interrupts current hold audio and plays the announcement passed as a parameter. Resumes the hold audio after announcement completes.
/// </summary>
/// <param name="announcementOptions"></param>
/// <param name="cancellationToken"></param>
/// <returns>Returns <see cref="InterruptAudioAndAnnounceResult"/>, which can be used to wait for Play's related events.</returns>
public virtual Response<InterruptAudioAndAnnounceResult> InterruptAudioAndAnnounce(InterruptAudioAndAnnounceOptions announcementOptions, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(InterruptAudioAndAnnounce)}");
scope.Start();
try
{
InterruptAudioAndAnnounceRequestInternal request = new InterruptAudioAndAnnounceRequestInternal(
announcementOptions.Announcement.Select(t => TranslatePlaySourceToInternal(t)).ToList(),
CommunicationIdentifierSerializer.Serialize(announcementOptions.PlayTo),
announcementOptions.OperationContext);

var response = CallMediaRestClient.InterruptAudioAndAnnounce(CallConnectionId, request, cancellationToken);
var result = new InterruptAudioAndAnnounceResult();

result.SetEventProcessor(EventProcessor, CallConnectionId, request.OperationContext);
return Response.FromValue(result, response);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Plays a file.
/// </summary>
/// <param name="announcementOptions"></param>
/// <param name="cancellationToken"></param>
/// <returns>Returns <see cref="InterruptAudioAndAnnounceResult"/>, which can be used to wait for Play's related events.</returns>
public async virtual Task<Response<InterruptAudioAndAnnounceResult>> InterruptAudioAndAnnounceAsync(InterruptAudioAndAnnounceOptions announcementOptions, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(InterruptAudioAndAnnounce)}");
scope.Start();
try
{
InterruptAudioAndAnnounceRequestInternal request = new InterruptAudioAndAnnounceRequestInternal(
announcementOptions.Announcement.Select(t => TranslatePlaySourceToInternal(t)).ToList(),
CommunicationIdentifierSerializer.Serialize(announcementOptions.PlayTo));

var response = await CallMediaRestClient.InterruptAudioAndAnnounceAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false);
var result = new InterruptAudioAndAnnounceResult();

result.SetEventProcessor(EventProcessor, CallConnectionId, request.OperationContext);
return Response.FromValue(result, response);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 67033da

Please sign in to comment.