@@ -13,9 +13,26 @@ namespace Azure.Communication.CallAutomation.Tests.MediaStreaming
1313 internal class StreamingDataParserTests
1414 {
1515 #region Audio
16-
1716 [ Test ]
1817 public void ParseAudioMetadata_Test ( )
18+ {
19+ string metadataJson = "{"
20+ + "\" kind\" : \" AudioMetadata\" ,"
21+ + "\" audioMetadata\" : {"
22+ + "\" subscriptionId\" : \" subscriptionId\" ,"
23+ + "\" encoding\" : \" encodingType\" ,"
24+ + "\" sampleRate\" : 8,"
25+ + "\" channels\" : 2,"
26+ + "\" length\" : 640"
27+ + "}"
28+ + "}" ;
29+
30+ AudioMetadata streamingMetadata = ( AudioMetadata ) StreamingDataParser . Parse ( metadataJson ) ;
31+ ValidateAudioMetadata ( streamingMetadata ) ;
32+ }
33+
34+ [ Test ]
35+ public void ParseAudioMetadata_bytes_Test ( )
1936 {
2037 string metadataJson = "{"
2138 + "\" kind\" : \" AudioMetadata\" ,"
@@ -34,6 +51,23 @@ public void ParseAudioMetadata_Test()
3451 ValidateAudioMetadata ( streamingMetadata ) ;
3552 }
3653
54+ [ Test ]
55+ public void ParseAudioData_Test ( )
56+ {
57+ string audioJson = "{"
58+ + "\" kind\" : \" AudioData\" ,"
59+ + "\" audioData\" : {"
60+ + "\" data\" : \" AQIDBAU=\" ," // [1, 2, 3, 4, 5]
61+ + "\" timestamp\" : \" 2022-08-23T11:48:05Z\" ,"
62+ + "\" participantRawID\" : \" participantId\" ,"
63+ + "\" silent\" : false"
64+ + "}"
65+ + "}" ;
66+
67+ AudioData streamingAudio = ( AudioData ) StreamingDataParser . Parse ( audioJson ) ;
68+ ValidateAudioData ( streamingAudio ) ;
69+ }
70+
3771 [ Test ]
3872 public void ParseAudioData_NoParticipantIdSilent_Test ( )
3973 {
@@ -50,6 +84,23 @@ public void ParseAudioData_NoParticipantIdSilent_Test()
5084 ValidateAudioDataNoParticipant ( streamingAudio ) ;
5185 }
5286
87+ [ Test ]
88+ public void ParseBinaryAudioData ( )
89+ {
90+ JObject jsonData = new JObject ( ) ;
91+ jsonData [ "kind" ] = "AudioData" ;
92+ jsonData [ "audioData" ] = new JObject ( ) ;
93+ jsonData [ "audioData" ] ! [ "data" ] = "AQIDBAU=" ;
94+ jsonData [ "audioData" ] ! [ "timestamp" ] = "2022-08-23T11:48:05Z" ;
95+ jsonData [ "audioData" ] ! [ "participantRawID" ] = "participantId" ;
96+ jsonData [ "audioData" ] ! [ "silent" ] = false ;
97+
98+ var binaryData = BinaryData . FromString ( jsonData . ToString ( ) ) ;
99+
100+ AudioData streamingAudio = ( AudioData ) StreamingDataParser . Parse ( binaryData ) ;
101+ ValidateAudioData ( streamingAudio ) ;
102+ }
103+
53104 [ Test ]
54105 public void ParseAudioDataEventsWithBinaryArray ( )
55106 {
@@ -99,6 +150,83 @@ private static void ValidateAudioDataNoParticipant(AudioData streamingAudio)
99150
100151 #region Transcription
101152
153+ [ Test ]
154+ public void ParseTranscriptionData_Test ( )
155+ {
156+ var transcriptionJson =
157+ "{" +
158+ "\" kind\" :\" TranscriptionData\" ," +
159+ "\" transcriptionData\" :" +
160+ "{" +
161+ "\" text\" :\" Hello World!\" ," +
162+ "\" format\" :\" display\" ," +
163+ "\" confidence\" :0.98," +
164+ "\" offset\" :1," +
165+ "\" duration\" :2," +
166+ "\" words\" :" +
167+ "[" +
168+ "{" +
169+ "\" text\" :\" Hello\" ," +
170+ "\" offset\" :1," +
171+ "\" duration\" :1" +
172+ "}," +
173+ "{" +
174+ "\" text\" :\" World\" ," +
175+ "\" offset\" :6," +
176+ "\" duration\" :1" +
177+ "}" +
178+ "]," +
179+ "\" participantRawID\" :\" abc12345\" ," +
180+ "\" resultStatus\" :\" final\" " +
181+ "}" +
182+ "}" ;
183+
184+ TranscriptionData transcription = ( TranscriptionData ) StreamingDataParser . Parse ( transcriptionJson ) ;
185+ ValidateTranscriptionData ( transcription ) ;
186+ }
187+
188+ [ Test ]
189+ public void ParseTranscriptionBinaryData ( )
190+ {
191+ JObject jsonData = new ( )
192+ {
193+ [ "kind" ] = "TranscriptionData" ,
194+ [ "transcriptionData" ] = new JObject ( )
195+ } ;
196+ jsonData [ "transcriptionData" ] ! [ "text" ] = "Hello World!" ;
197+ jsonData [ "transcriptionData" ] ! [ "format" ] = "display" ;
198+ jsonData [ "transcriptionData" ] ! [ "confidence" ] = 0.98d ;
199+ jsonData [ "transcriptionData" ] ! [ "offset" ] = 1 ;
200+ jsonData [ "transcriptionData" ] ! [ "duration" ] = 2 ;
201+
202+ JArray words = new ( ) ;
203+ jsonData [ "transcriptionData" ] ! [ "words" ] = words ;
204+
205+ JObject word0 = new ( )
206+ {
207+ [ "text" ] = "Hello" ,
208+ [ "offset" ] = 1 ,
209+ [ "duration" ] = 1
210+ } ;
211+ words . Add ( word0 ) ;
212+
213+ JObject word1 = new ( )
214+ {
215+ [ "text" ] = "World" ,
216+ [ "offset" ] = 6 ,
217+ [ "duration" ] = 1
218+ } ;
219+ words . Add ( word1 ) ;
220+
221+ jsonData [ "transcriptionData" ] ! [ "participantRawID" ] = "abc12345" ;
222+ jsonData [ "transcriptionData" ] ! [ "resultStatus" ] = "final" ;
223+
224+ var binaryData = BinaryData . FromString ( jsonData . ToString ( ) ) ;
225+
226+ TranscriptionData transcription = ( TranscriptionData ) StreamingDataParser . Parse ( binaryData ) ;
227+ ValidateTranscriptionData ( transcription ) ;
228+ }
229+
102230 [ Test ]
103231 public void ParseTranscriptionMetadata_Test ( )
104232 {
0 commit comments