Skip to content

Commit

Permalink
Adding duration field to TranscriptionData object. (#41541)
Browse files Browse the repository at this point in the history
* Adding duration to transcription data

* Fixing Transcription and Media Streaming Data participants' types.
  • Loading branch information
cochi2 authored Jan 25, 2024
1 parent 2acc46c commit caa3842
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1405,9 +1405,10 @@ public partial class TranscriptionData : Azure.Communication.CallAutomation.Stre
{
internal TranscriptionData() { }
public double Confidence { get { throw null; } set { } }
public ulong Duration { 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.CommunicationIdentifier 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 { } }
Expand Down Expand Up @@ -1607,6 +1608,8 @@ internal UserConsent() { }
public partial class WordData
{
public WordData() { }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("duration")]
public ulong Duration { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("offset")]
public ulong Offset { get { throw null; } set { } }
[System.Text.Json.Serialization.JsonPropertyNameAttribute("text")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal AudioData(string data, DateTime timestamp, string participantId, bool s
Timestamp = timestamp;
if (participantId != null)
{
Participant = new CommunicationUserIdentifier(participantId);
Participant = CommunicationIdentifier.FromRawId(participantId);;
}
IsSilent = silent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static StreamingData Parse(string stringJson)
transcriptionDataInternal.Format,
transcriptionDataInternal.Confidence,
transcriptionDataInternal.Offset,
transcriptionDataInternal.Duration,
transcriptionDataInternal.Words,
transcriptionDataInternal.ParticipantRawID,
transcriptionDataInternal.ResultStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ namespace Azure.Communication.CallAutomation
/// </summary>
public class TranscriptionData : StreamingData
{
internal TranscriptionData(string text, string format, double confidence, ulong offset, IEnumerable<WordData> words, string participantRawID, string resultStatus)
internal TranscriptionData(string text, string format, double confidence, ulong offset, ulong duration, IEnumerable<WordData> words, string participantRawID, string resultStatus)
{
Text = text;
Format = ConvertToTextFormatEnum(format);
Confidence = confidence;
Offset = offset;
Duration = duration;
Words = words;
if (participantRawID != null)
{
Participant = new CommunicationUserIdentifier(participantRawID);
Participant = CommunicationIdentifier.FromRawId(participantRawID);
}
ResultStatus = ConvertToResultStatusEnum(resultStatus);
}
Expand All @@ -46,6 +47,11 @@ internal TranscriptionData(string text, string format, double confidence, ulong

public ulong Offset { get; set; }

/// <summary>
/// Duration in ticks. 1 tick = 100 nanoseconds.
/// </summary>
public ulong Duration { get; set; }

/// <summary>
/// The result for each word of the phrase
/// </summary>
Expand All @@ -54,7 +60,7 @@ internal TranscriptionData(string text, string format, double confidence, ulong
/// <summary>
/// The identified speaker based on participant raw ID
/// </summary>
public CommunicationUserIdentifier Participant { get; set; }
public CommunicationIdentifier Participant { get; set; }

/// <summary>
/// Status of the result of transcription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ internal class TranscriptionDataInternal
[JsonPropertyName("offset")]
public ulong Offset { get; set; }

/// <summary>
/// Duration in ticks. 1 tick = 100 nanoseconds.
/// </summary>
[JsonPropertyName("duration")]
public ulong Duration { get; set; }

/// <summary>
/// The result for each word of the phrase
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ public class WordData
/// </summary>
[JsonPropertyName("offset")]
public ulong Offset { get; set; }

/// <summary>
/// Duration in ticks. 1 tick = 100 nanoseconds.
/// </summary>
[JsonPropertyName("duration")]
public ulong Duration { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,18 @@ public void ParseTranscriptionData_Test()
"\"format\":\"display\"," +
"\"confidence\":0.98," +
"\"offset\":1," +
"\"duration\":2," +
"\"words\":" +
"[" +
"{" +
"\"text\":\"Hello\"," +
"\"offset\":1" +
"\"offset\":1," +
"\"duration\":1" +
"}," +
"{" +
"\"text\":\"World\"," +
"\"offset\":6" +
"\"offset\":6," +
"\"duration\":1" +
"}" +
"]," +
"\"participantRawID\":\"abc12345\"," +
Expand All @@ -192,21 +195,24 @@ public void ParseTranscriptionBinaryData()
jsonData["transcriptionData"]!["format"] = "display";
jsonData["transcriptionData"]!["confidence"] = 0.98d;
jsonData["transcriptionData"]!["offset"] = 1;
jsonData["transcriptionData"]!["duration"] = 2;

JArray words = new();
jsonData["transcriptionData"]!["words"] = words;

JObject word0 = new()
{
["text"] = "Hello",
["offset"] = 1
["offset"] = 1,
["duration"] = 1
};
words.Add(word0);

JObject word1 = new()
{
["text"] = "World",
["offset"] = 6
["offset"] = 6,
["duration"] = 1
};
words.Add(word1);

Expand All @@ -231,21 +237,24 @@ public void ParseTranscriptionDataEventsWithBinaryArray()
jsonData["transcriptionData"]!["format"] = "display";
jsonData["transcriptionData"]!["confidence"] = 0.98d;
jsonData["transcriptionData"]!["offset"] = 1;
jsonData["transcriptionData"]!["duration"] = 2;

JArray words = new();
jsonData["transcriptionData"]!["words"] = words;

JObject word0 = new()
{
["text"] = "Hello",
["offset"] = 1
["offset"] = 1,
["duration"] = 1
};
words.Add(word0);

JObject word1 = new()
{
["text"] = "World",
["offset"] = 6
["offset"] = 6,
["duration"] = 1
};
words.Add(word1);

Expand Down Expand Up @@ -275,14 +284,17 @@ private static void ValidateTranscriptionData(TranscriptionData transcription)
Assert.AreEqual(TextFormat.Display, transcription.Format);
Assert.AreEqual(0.98d, transcription.Confidence);
Assert.AreEqual(1, transcription.Offset);
Assert.AreEqual(2, transcription.Duration);

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

Assert.IsTrue(transcription.Participant is CommunicationIdentifier);
Assert.AreEqual("abc12345", transcription.Participant.RawId);
Expand Down

0 comments on commit caa3842

Please sign in to comment.