Skip to content

Commit

Permalink
Implement generci parser for Transcription, Audio data (#39250)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishesingh-msft authored Oct 18, 2023
1 parent de7daf4 commit a8a8b96
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ internal AnswerCallResult() { }
public Azure.Communication.CallAutomation.AnswerCallEventResult WaitForEventProcessor(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task<Azure.Communication.CallAutomation.AnswerCallEventResult> WaitForEventProcessorAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class AudioData : Azure.Communication.CallAutomation.StreamingData
{
internal AudioData() { }
public string Data { get { throw null; } }
public bool IsSilent { get { throw null; } }
public Azure.Communication.CommunicationIdentifier Participant { get { throw null; } }
public System.DateTime Timestamp { get { throw null; } }
}
public partial class AudioMetadata : Azure.Communication.CallAutomation.StreamingData
{
public AudioMetadata() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("channels")]
public int Channels { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("encoding")]
public string Encoding { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("length")]
public int Length { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("subscriptionId")]
public string MediaSubscriptionId { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("sampleRate")]
public int SampleRate { get { throw null; } set { } }
}
public partial class BlobStorage : Azure.Communication.CallAutomation.ExternalStorage
{
public BlobStorage(System.Uri containerUri) { }
Expand Down Expand Up @@ -830,14 +852,6 @@ public GroupCallLocator(string id) { }
public static bool operator !=(Azure.Communication.CallAutomation.MediaStreamingAudioChannel left, Azure.Communication.CallAutomation.MediaStreamingAudioChannel right) { throw null; }
public override string ToString() { throw null; }
}
public partial class MediaStreamingAudioData : Azure.Communication.CallAutomation.MediaStreamingPackageBase
{
internal MediaStreamingAudioData() { }
public string Data { get { throw null; } }
public bool IsSilent { get { throw null; } }
public Azure.Communication.CommunicationIdentifier Participant { get { throw null; } }
public System.DateTime Timestamp { get { throw null; } }
}
public partial class MediaStreamingConfiguration
{
public MediaStreamingConfiguration(System.Uri transportUrl, Azure.Communication.CallAutomation.MediaStreamingTransport transportType, Azure.Communication.CallAutomation.MediaStreamingContent contentType, Azure.Communication.CallAutomation.MediaStreamingAudioChannel audioChannelType) { }
Expand All @@ -863,20 +877,6 @@ public MediaStreamingConfiguration(System.Uri transportUrl, Azure.Communication.
public static bool operator !=(Azure.Communication.CallAutomation.MediaStreamingContent left, Azure.Communication.CallAutomation.MediaStreamingContent right) { throw null; }
public override string ToString() { throw null; }
}
public partial class MediaStreamingMetadata : Azure.Communication.CallAutomation.MediaStreamingPackageBase
{
public MediaStreamingMetadata() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("channels")]
public int Channels { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("encoding")]
public string Encoding { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("length")]
public int Length { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("subscriptionId")]
public string MediaSubscriptionId { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("sampleRate")]
public int SampleRate { get { throw null; } set { } }
}
public partial class MediaStreamingOptions
{
public MediaStreamingOptions(System.Uri transportUri, Azure.Communication.CallAutomation.MediaStreamingTransport transportType, Azure.Communication.CallAutomation.MediaStreamingContent contentType, Azure.Communication.CallAutomation.MediaStreamingAudioChannel audioChannelType) { }
Expand All @@ -885,16 +885,6 @@ public MediaStreamingOptions(System.Uri transportUri, Azure.Communication.CallAu
public Azure.Communication.CallAutomation.MediaStreamingTransport MediaStreamingTransport { get { throw null; } }
public System.Uri TransportUri { get { throw null; } }
}
public abstract partial class MediaStreamingPackageBase
{
protected MediaStreamingPackageBase() { }
}
public static partial class MediaStreamingPackageParser
{
public static Azure.Communication.CallAutomation.MediaStreamingPackageBase Parse(System.BinaryData json) { throw null; }
public static Azure.Communication.CallAutomation.MediaStreamingPackageBase Parse(byte[] receivedBytes) { throw null; }
public static Azure.Communication.CallAutomation.MediaStreamingPackageBase Parse(string stringJson) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct MediaStreamingTransport : System.IEquatable<Azure.Communication.CallAutomation.MediaStreamingTransport>
{
Expand Down Expand Up @@ -1230,6 +1220,11 @@ internal ResultInformation() { }
public string Message { get { throw null; } }
public int? SubCode { get { throw null; } }
}
public enum ResultStatus
{
Intermediate = 0,
Final = 1,
}
public partial class SendDtmfCompleted : Azure.Communication.CallAutomation.CallAutomationEventBase
{
internal SendDtmfCompleted() { }
Expand Down Expand Up @@ -1340,6 +1335,20 @@ public partial class StopTranscriptionOptions
public StopTranscriptionOptions() { }
public string OperationContext { get { throw null; } set { } }
}
public abstract partial class StreamingData
{
protected StreamingData() { }
}
public static partial class StreamingDataParser
{
public static Azure.Communication.CallAutomation.StreamingData Parse(System.BinaryData json) { throw null; }
public static Azure.Communication.CallAutomation.StreamingData Parse(byte[] receivedBytes) { throw null; }
public static Azure.Communication.CallAutomation.StreamingData Parse(string stringJson) { throw null; }
}
public enum TextFormat
{
Display = 0,
}
public partial class TextSource : Azure.Communication.CallAutomation.PlaySource
{
public TextSource(string text) { }
Expand All @@ -1357,13 +1366,24 @@ internal ToneInfo() { }
public int SequenceId { get { throw null; } }
public Azure.Communication.CallAutomation.DtmfTone Tone { get { throw null; } }
}
public partial class TranscriptionData : Azure.Communication.CallAutomation.StreamingData
{
internal TranscriptionData() { }
public double Confidence { get { throw null; } set { } }
public Azure.Communication.CallAutomation.TextFormat Format { get { throw null; } set { } }
public ulong Offset { get { throw null; } set { } }
public Azure.Communication.CommunicationUserIdentifier Participant { get { throw null; } set { } }
public Azure.Communication.CallAutomation.ResultStatus ResultStatus { get { throw null; } set { } }
public string Text { get { throw null; } set { } }
public System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.WordData> Words { get { throw null; } set { } }
}
public partial class TranscriptionFailed : Azure.Communication.CallAutomation.CallAutomationEventBase
{
internal TranscriptionFailed() { }
public Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdateResult { get { throw null; } }
public static Azure.Communication.CallAutomation.TranscriptionFailed Deserialize(string content) { throw null; }
}
public partial class TranscriptionMetadata : Azure.Communication.CallAutomation.TranscriptionPackageBase
public partial class TranscriptionMetadata : Azure.Communication.CallAutomation.StreamingData
{
public TranscriptionMetadata() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("callConnectionId")]
Expand All @@ -1383,16 +1403,6 @@ public TranscriptionOptions(System.Uri transportUri, Azure.Communication.CallAut
public Azure.Communication.CallAutomation.TranscriptionTransport TranscriptionTransport { get { throw null; } }
public System.Uri TransportUrl { get { throw null; } }
}
public abstract partial class TranscriptionPackageBase
{
protected TranscriptionPackageBase() { }
}
public static partial class TranscriptionPackageParser
{
public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(System.BinaryData json) { throw null; }
public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(byte[] receivedBytes) { throw null; }
public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(string stringJson) { throw null; }
}
public partial class TranscriptionResumed : Azure.Communication.CallAutomation.CallAutomationEventBase
{
internal TranscriptionResumed() { }
Expand Down Expand Up @@ -1526,29 +1536,6 @@ public partial class VoipHeader : Azure.Communication.CallAutomation.CustomConte
{
public VoipHeader(string key, string value) : base (default(string), default(string)) { }
}
}
namespace Azure.Communication.CallAutomation.Models.Transcription
{
public enum ResultStatus
{
Intermediate = 0,
Final = 1,
}
public enum TextFormat
{
Display = 0,
}
public partial class TranscriptionData : Azure.Communication.CallAutomation.TranscriptionPackageBase
{
internal TranscriptionData() { }
public double Confidence { get { throw null; } set { } }
public Azure.Communication.CallAutomation.Models.Transcription.TextFormat Format { get { throw null; } set { } }
public ulong Offset { get { throw null; } set { } }
public Azure.Communication.CommunicationUserIdentifier Participant { get { throw null; } set { } }
public Azure.Communication.CallAutomation.Models.Transcription.ResultStatus ResultStatus { get { throw null; } set { } }
public string Text { get { throw null; } set { } }
public System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.Models.Transcription.WordData> Words { get { throw null; } set { } }
}
public partial class WordData
{
public WordData() { }
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Streaming audio.
/// Streaming Audio.
/// </summary>
public class MediaStreamingAudioData : MediaStreamingPackageBase
public class AudioData : StreamingData
{
internal MediaStreamingAudioData(string data, DateTime timestamp, string participantId, bool silent)
internal AudioData(string data, DateTime timestamp, string participantId, bool silent)
{
Data = data;
Timestamp = timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Streaming audio.
/// Streaming Audio.
/// </summary>
internal class MediaStreamingAudioDataInternal
internal class AudioDataInternal
{
/// <summary>
/// The audio data in base64 string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Metadata package for Media Streaming.
/// Metadata for Audio Streaming.
/// </summary>
public class MediaStreamingMetadata : MediaStreamingPackageBase
public class AudioMetadata : StreamingData
{
/// <summary>
/// Subscription Id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Transcription Package.
/// Base class for Streaming Data
/// </summary>
public abstract class TranscriptionPackageBase
public abstract class StreamingData
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text;
using System.Text.Json;

namespace Azure.Communication.CallAutomation
{
/// <summary>
/// A generic parser for different packages, such as Media(Audio) or Transcription, received as
/// part of streaming over websocket
/// </summary>
public static class StreamingDataParser
{
/// <summary>
/// Parsing a MediaStreaming package from BinaryData.
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static StreamingData Parse(BinaryData json)
{
return Parse(json.ToString());
}

/// <summary>
/// Parsing a MediaStreaming package from a byte array.
/// </summary>
/// <param name="receivedBytes">a UTF8 byte array.</param>
/// <returns></returns>
public static StreamingData Parse(byte[] receivedBytes)
{
return Parse(Encoding.UTF8.GetString(receivedBytes));
}

/// <summary>
/// Parse the incoming package.
/// </summary>
/// <param name="stringJson"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static StreamingData Parse(string stringJson)
{
JsonElement package = JsonDocument.Parse(stringJson).RootElement;

string kind = package.GetProperty("kind").ToString();

switch (kind)
{
#region Audio
case "AudioMetadata":
return JsonSerializer.Deserialize<AudioMetadata>(package.GetProperty("audioMetadata").ToString());

case "AudioData":
AudioDataInternal audioInternal = JsonSerializer.Deserialize<AudioDataInternal>(package.GetProperty("audioData").ToString());
return new AudioData(
audioInternal.Data, audioInternal.Timestamp, audioInternal.ParticipantRawId, audioInternal.Silent);

#endregion

#region Transcription
case "TranscriptionMetadata":
return JsonSerializer.Deserialize<TranscriptionMetadata>(package.GetProperty("transcriptionMetadata").ToString());

case "TranscriptionData":
TranscriptionDataInternal transcriptionDataInternal = JsonSerializer.Deserialize<TranscriptionDataInternal>(
package.GetProperty("transcriptionData").ToString()
);
return new TranscriptionData(
transcriptionDataInternal.Text,
transcriptionDataInternal.Format,
transcriptionDataInternal.Confidence,
transcriptionDataInternal.Offset,
transcriptionDataInternal.Words,
transcriptionDataInternal.ParticipantRawID,
transcriptionDataInternal.ResultStatus
);

#endregion

default:
throw new NotSupportedException(stringJson);
}
}
}
}
Loading

0 comments on commit a8a8b96

Please sign in to comment.