Skip to content

Commit

Permalink
Transcription package fix: (#39066)
Browse files Browse the repository at this point in the history
1> Made non-internal TranscriptionData & Word classes as public
2> Rename Word to WordData, as single word classes are not allowed
3> Cleanup vars & references
  • Loading branch information
abhishesingh-msft authored Oct 3, 2023
1 parent dd0510e commit 45bb7ed
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1535,4 +1535,23 @@ 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() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("offset")]
public ulong Offset { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("text")]
public string Text { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Azure.Communication.CallAutomation.Models.Transcription
/// <summary>
/// Streaming Transcription.
/// </summary>
internal class TranscriptionData : TranscriptionPackageBase
public class TranscriptionData : TranscriptionPackageBase
{
internal TranscriptionData(string text, string format, double confidence, ulong offset, IEnumerable<Word> words, string participantRawID, string resultStatus)
internal TranscriptionData(string text, string format, double confidence, ulong offset, IEnumerable<WordData> words, string participantRawID, string resultStatus)
{
Text = text;
Format = ConvertToTextFormatEnum(format);
Expand Down Expand Up @@ -50,7 +50,7 @@ internal TranscriptionData(string text, string format, double confidence, ulong
/// <summary>
/// The result for each word of the phrase
/// </summary>
public IEnumerable<Word> Words { get; set; }
public IEnumerable<WordData> Words { get; set; }

/// <summary>
/// The identified speaker based on participant raw ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class TranscriptionDataInternal
/// The result for each word of the phrase
/// </summary>
[JsonPropertyName("words")]
public IEnumerable<Word> Words { get; set; }
public IEnumerable<WordData> Words { get; set; }

/// <summary>
/// The identified speaker based on participant raw ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public static TranscriptionPackageBase Parse(byte[] receivedBytes)
public static TranscriptionPackageBase Parse(string stringJson)
{
JsonElement package = JsonDocument.Parse(stringJson).RootElement;
if (package.GetProperty("kind").ToString() == "TranscriptionMetadata")

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

if (kind == "TranscriptionMetadata")
{
return JsonSerializer.Deserialize<TranscriptionMetadata>(package.GetProperty("transcriptionMetadata").ToString());
}
else if (package.GetProperty("kind").ToString() == "TranscriptionData")
else if (kind == "TranscriptionData")
{
TranscriptionDataInternal transcriptionDataInternal = JsonSerializer.Deserialize<TranscriptionDataInternal>(
package.GetProperty("transcriptionData").ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

namespace Azure.Communication.CallAutomation.Models.Transcription
{
internal class Word
/// <summary>
/// The result for each word of the phrase
/// </summary>
public class WordData
{
/// <summary>
/// Text in the phrase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void ValidateTranscriptionData(TranscriptionData transcription)
Assert.AreEqual(1, transcription.Offset);

// validate individual words
IList<Word> words = transcription.Words.ToList();
IList<WordData> words = transcription.Words.ToList();
Assert.AreEqual(2, words.Count);
Assert.AreEqual("Hello", words[0].Text);
Assert.AreEqual(1, words[0].Offset);
Expand Down

0 comments on commit 45bb7ed

Please sign in to comment.