Skip to content

Commit

Permalink
Added transcription APIs and events (Azure#38988)
Browse files Browse the repository at this point in the history
* Autorest generated code

* Adding SDK methods for start, stop and update transcription

* Add transcription options for the create & answer call

* Adding events

* Adding event parser test cases

* Adding tests

* Refactoring code to make options param optional

* Adding models and parser for the transcription schema

* Fixing enum conversion logic for transcription schema

* Cleaning up code

* Add transcription options in create/answer/group call and tests

* Updted TranscriptionUpdate to take TranscriptionUpdate and TranscriptionStatusDetails as enums

* Fixed API typo

* Adding SDK methods for start, stop and update transcription

* Add transcription options for the create & answer call

* Adding models and parser for the transcription schema

* Adding events

* Adding event parser test cases

* Adding tests

* Refactoring code to make options param optional

* Fixing enum conversion logic for transcription schema

* Cleaning up code

* Add transcription options in create/answer/group call and tests

* Updted TranscriptionUpdate to take TranscriptionUpdate and TranscriptionStatusDetails as enums

* Fixed API typo

* Updated contract after rebase

* Removed duplicate tests

* Update in transcription ws schema

* Fixed TranscriptionOptions review comment

* Fixing TranscriptionOptions arguments in create call, group call & answer call

* Fixing build issues

---------

Co-authored-by: abhishesingh-msft <[email protected]>
  • Loading branch information
vivekmore-msft and abhishesingh-msft authored Sep 28, 2023
1 parent 29f601e commit 42f7757
Show file tree
Hide file tree
Showing 63 changed files with 2,097 additions and 127 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public virtual async Task<Response<AnswerCallResult>> AnswerCallAsync(AnswerCall
throw;
}
}

/// Answer an incoming call.
/// <param name="incomingCallContext"> The incoming call context </param>
/// <param name="callbackUri"> The callback Uri to receive status notifications. </param>
Expand Down Expand Up @@ -246,6 +245,7 @@ private AnswerCallRequestInternal CreateAnswerCallRequest(AnswerCallOptions opti
request.AzureCognitiveServicesEndpointUrl = options.AzureCognitiveServicesEndpointUri.AbsoluteUri;
}
request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions);
request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions);
request.AnsweredByIdentifier = Source == null ? null : new CommunicationUserIdentifierModel(Source.Id);
request.OperationContext = options.OperationContext;

Expand Down Expand Up @@ -624,6 +624,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateCallOptions options)
}
request.OperationContext = options.OperationContext;
request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions);
request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions);

return request;
}
Expand Down Expand Up @@ -652,6 +653,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateGroupCallOptions optio
}
request.OperationContext = options.OperationContext;
request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions);
request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions);

return request;
}
Expand All @@ -675,6 +677,13 @@ private static MediaStreamingOptionsInternal CreateMediaStreamingOptionsInternal
: new MediaStreamingOptionsInternal(configuration.TransportUri.AbsoluteUri, configuration.MediaStreamingTransport, configuration.MediaStreamingContent,
configuration.MediaStreamingAudioChannel);
}
private static TranscriptionOptionsInternal CreateTranscriptionOptionsInternal(TranscriptionOptions configuration)
{
return configuration == default
? default
: new TranscriptionOptionsInternal(configuration.TransportUrl.AbsoluteUri, configuration.TranscriptionTransport, configuration.Locale,
configuration.StartTranscription);
}

/// <summary> Initializes a new instance of CallConnection. <see cref="CallConnection"/>.</summary>
/// <param name="callConnectionId"> The call connection id for the GetCallConnection instance. </param>
Expand Down
144 changes: 144 additions & 0 deletions sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,149 @@ public virtual Response<SendDtmfResult> SendDtmf(IEnumerable<DtmfTone> tones, Co
throw;
}
}

/// <summary>
/// Starts transcription in the call.
/// </summary>
/// <param name="options">An optional object containing start transcription options and configurations.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual Response StartTranscription(StartTranscriptionOptions options = default, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StartTranscription)}");
scope.Start();
try
{
var request = options == default
? new StartTranscriptionRequestInternal()
: new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext };

return CallMediaRestClient.StartTranscription(CallConnectionId, request, cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Starts transcription in the call.
/// </summary>
/// <param name="options">An optional object containing start transcription options and configurations.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual async Task<Response> StartTranscriptionAsync(StartTranscriptionOptions options = default, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StartTranscription)}");
scope.Start();
try
{
var request = options == default
? new StartTranscriptionRequestInternal()
: new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext };

return await CallMediaRestClient.StartTranscriptionAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Stops transcription in the call.
/// </summary>
/// <param name="options">An optional object containing stop transcription options and configurations.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual Response StopTranscription(StopTranscriptionOptions options = default, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StopTranscription)}");
scope.Start();
try
{
var request = options == default
? new StopTranscriptionRequestInternal()
: new StopTranscriptionRequestInternal() { OperationContext = options.OperationContext };

return CallMediaRestClient.StopTranscription(CallConnectionId, request, cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Stops transcription in the call.
/// </summary>
/// <param name="options">An optional object containing stop transcription options and configurations.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual async Task<Response> StopTranscriptionAsync(StopTranscriptionOptions options = default, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StopTranscription)}");
scope.Start();
try
{
var request = options == default
? new StopTranscriptionRequestInternal()
: new StopTranscriptionRequestInternal() { OperationContext = options.OperationContext };

return await CallMediaRestClient.StopTranscriptionAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// API to change transcription language.
/// </summary>
/// <param name="locale">Defines new locale for transcription.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual Response UpdateTranscriptionData(String locale, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(UpdateTranscriptionData)}");
scope.Start();
try
{
UpdateTranscriptionDataRequestInternal request = new UpdateTranscriptionDataRequestInternal(locale);
return CallMediaRestClient.UpdateTranscriptionData(CallConnectionId, request, cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// API to change transcription language.
/// </summary>
/// <param name="locale">Defines new locale for transcription.</param>
/// <param name="cancellationToken">An optional CancellationToken to cancel the request.</param>
/// <returns>Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error.</returns>
public virtual async Task<Response> UpdateTranscriptionDataAsync(String locale, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(UpdateTranscriptionData)}");
scope.Start();
try
{
UpdateTranscriptionDataRequestInternal request = new UpdateTranscriptionDataRequestInternal(locale);
return await CallMediaRestClient.UpdateTranscriptionDataAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}
}
}

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

Loading

0 comments on commit 42f7757

Please sign in to comment.