Skip to content

Commit 4388873

Browse files
committed
add json to response object
1 parent 60f3534 commit 4388873

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Examples/ServiceExamples/Scripts/ExampleCustomHeaders.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ private void OnMessage(MessageResponse response, Dictionary<string, object> cust
153153

154154
private void OnRecognize(SpeechRecognitionEvent results, Dictionary<string, object> customData)
155155
{
156-
Log.Debug("ExampleCustomHeader.OnRecognize()", "Response: {0}", customData["json"].ToString());
157-
158156
if (customData != null)
159157
{
158+
Log.Debug("ExampleCustomHeader.OnRecognize()", "Response: {0}", customData["json"].ToString());
160159
if (customData.ContainsKey(Constants.String.RESPONSE_HEADERS))
161160
{
162161
Log.Debug("ExampleCustomHeader.OnRecognize()", "Response headers:");

Plugins/websocket-sharp.dll

0 Bytes
Binary file not shown.

Scripts/Services/SpeechToText/v1/SpeechToText.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,13 @@ private void OnGetModelResponse(RESTConnector.Request req, RESTConnector.Respons
485485
/// This callback object is used by the Recognize() and StartListening() methods.
486486
/// </summary>
487487
/// <param name="results">The ResultList object containing the results.</param>
488-
public delegate void OnRecognize(SpeechRecognitionEvent results);
488+
public delegate void OnRecognize(SpeechRecognitionEvent results, Dictionary<string, object> customData = null);
489489

490490
/// <summary>
491491
/// This callback object is used by the RecognizeSpeaker() method.
492492
/// </summary>
493493
/// <param name="speakerRecognitionEvent">Array of speaker label results.</param>
494-
public delegate void OnRecognizeSpeaker(SpeakerRecognitionEvent speakerRecognitionEvent);
494+
public delegate void OnRecognizeSpeaker(SpeakerRecognitionEvent speakerRecognitionEvent, Dictionary<string, object> customData = null);
495495

496496
/// <summary>
497497
/// This starts the service listening and it will invoke the callback for any recognized speech.
@@ -510,7 +510,7 @@ public bool StartListening(OnRecognize callback, OnRecognizeSpeaker speakerLabel
510510
if (!CreateListenConnector())
511511
return false;
512512

513-
Dictionary<string, string> customHeaders = null;
513+
Dictionary<string, string> customHeaders = new Dictionary<string, string>();
514514
if (customData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS))
515515
{
516516
foreach (KeyValuePair<string, string> kvp in customData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary<string, string>)
@@ -756,7 +756,8 @@ private void OnListenMessage(WSConnector.Message msg)
756756
if (msg is WSConnector.TextMessage)
757757
{
758758
WSConnector.TextMessage tm = (WSConnector.TextMessage)msg;
759-
759+
Dictionary<string, object> customData = new Dictionary<string, object>();
760+
customData.Add("json", tm.Text);
760761
IDictionary json = Json.Deserialize(tm.Text) as IDictionary;
761762
if (json != null)
762763
{
@@ -771,7 +772,7 @@ private void OnListenMessage(WSConnector.Message msg)
771772
// SendStart();
772773

773774
if (_listenCallback != null)
774-
_listenCallback(results);
775+
_listenCallback(results, customData);
775776
else
776777
StopListening(); // automatically stop listening if our callback is destroyed.
777778
}

0 commit comments

Comments
 (0)