-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement generci parser for Transcription, Audio data (#39250)
- Loading branch information
1 parent
de7daf4
commit a8a8b96
Showing
18 changed files
with
286 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
...Azure.Communication.CallAutomation/src/Models/MediaStreaming/MediaStreamingPackageBase.cs
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
...ure.Communication.CallAutomation/src/Models/MediaStreaming/MediaStreamingPackageParser.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...munication/Azure.Communication.CallAutomation/src/Models/Streaming/StreamingDataParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.