Skip to content

Commit 4af1ab3

Browse files
committed
refactor: Generating binary return types instead of memeory streams
1 parent 8689b64 commit 4af1ab3

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ private void OnListVoicesResponse(RESTConnector.Request req, RESTConnector.Respo
383383
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
384384
/// json output from the REST call will be passed in this object as the value of the 'json'
385385
/// key.</string></param>
386-
/// <returns><see cref="System.IO.MemoryStream" />System.IO.MemoryStream</returns>
387-
public bool Synthesize(Callback<System.IO.MemoryStream> callback, string text, Dictionary<string, object> customData = null, string voice = null, string customizationId = null, string accept = null)
386+
/// <returns><see cref="byte[]" />byte[]</returns>
387+
public bool Synthesize(Callback<byte[]> callback, string text, Dictionary<string, object> customData = null, string voice = null, string customizationId = null, string accept = null)
388388
{
389389
if (callback == null)
390390
throw new ArgumentNullException("`callback` is required for `Synthesize`");
391391
if (string.IsNullOrEmpty(text))
392392
throw new ArgumentNullException("`text` is required for `Synthesize`");
393393

394-
RequestObject<System.IO.MemoryStream> req = new RequestObject<System.IO.MemoryStream>
394+
RequestObject<byte[]> req = new RequestObject<byte[]>
395395
{
396396
Callback = callback,
397397
HttpMethod = UnityWebRequest.kHttpVerbPOST,
@@ -446,18 +446,18 @@ public bool Synthesize(Callback<System.IO.MemoryStream> callback, string text, D
446446

447447
private void OnSynthesizeResponse(RESTConnector.Request req, RESTConnector.Response resp)
448448
{
449-
DetailedResponse<System.IO.MemoryStream> response = new DetailedResponse<System.IO.MemoryStream>();
450-
Dictionary<string, object> customData = ((RequestObject<System.IO.MemoryStream>)req).CustomData;
449+
DetailedResponse<byte[]> response = new DetailedResponse<byte[]>();
450+
Dictionary<string, object> customData = ((RequestObject<byte[]>)req).CustomData;
451451
foreach (KeyValuePair<string, string> kvp in resp.Headers)
452452
{
453453
response.Headers.Add(kvp.Key, kvp.Value);
454454
}
455455
response.StatusCode = resp.HttpResponseCode;
456456

457-
response.Result = new System.IO.MemoryStream(resp.Data);
457+
response.Result = resp.Data;
458458

459-
if (((RequestObject<System.IO.MemoryStream>)req).Callback != null)
460-
((RequestObject<System.IO.MemoryStream>)req).Callback(response, resp.Error, customData);
459+
if (((RequestObject<byte[]>)req).Callback != null)
460+
((RequestObject<byte[]>)req).Callback(response, resp.Error, customData);
461461
}
462462
/// <summary>
463463
/// Get pronunciation.

Scripts/Services/VisualRecognition/V3/VisualRecognitionService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,15 @@ private void OnUpdateClassifierResponse(RESTConnector.Request req, RESTConnector
883883
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
884884
/// json output from the REST call will be passed in this object as the value of the 'json'
885885
/// key.</string></param>
886-
/// <returns><see cref="System.IO.MemoryStream" />System.IO.MemoryStream</returns>
887-
public bool GetCoreMlModel(Callback<System.IO.MemoryStream> callback, string classifierId, Dictionary<string, object> customData = null)
886+
/// <returns><see cref="byte[]" />byte[]</returns>
887+
public bool GetCoreMlModel(Callback<byte[]> callback, string classifierId, Dictionary<string, object> customData = null)
888888
{
889889
if (callback == null)
890890
throw new ArgumentNullException("`callback` is required for `GetCoreMlModel`");
891891
if (string.IsNullOrEmpty(classifierId))
892892
throw new ArgumentNullException("`classifierId` is required for `GetCoreMlModel`");
893893

894-
RequestObject<System.IO.MemoryStream> req = new RequestObject<System.IO.MemoryStream>
894+
RequestObject<byte[]> req = new RequestObject<byte[]>
895895
{
896896
Callback = callback,
897897
HttpMethod = UnityWebRequest.kHttpVerbGET,
@@ -927,18 +927,18 @@ public bool GetCoreMlModel(Callback<System.IO.MemoryStream> callback, string cla
927927

928928
private void OnGetCoreMlModelResponse(RESTConnector.Request req, RESTConnector.Response resp)
929929
{
930-
DetailedResponse<System.IO.MemoryStream> response = new DetailedResponse<System.IO.MemoryStream>();
931-
Dictionary<string, object> customData = ((RequestObject<System.IO.MemoryStream>)req).CustomData;
930+
DetailedResponse<byte[]> response = new DetailedResponse<byte[]>();
931+
Dictionary<string, object> customData = ((RequestObject<byte[]>)req).CustomData;
932932
foreach (KeyValuePair<string, string> kvp in resp.Headers)
933933
{
934934
response.Headers.Add(kvp.Key, kvp.Value);
935935
}
936936
response.StatusCode = resp.HttpResponseCode;
937937

938-
response.Result = new System.IO.MemoryStream(resp.Data);
938+
response.Result = resp.Data;
939939

940-
if (((RequestObject<System.IO.MemoryStream>)req).Callback != null)
941-
((RequestObject<System.IO.MemoryStream>)req).Callback(response, resp.Error, customData);
940+
if (((RequestObject<byte[]>)req).Callback != null)
941+
((RequestObject<byte[]>)req).Callback(response, resp.Error, customData);
942942
}
943943
/// <summary>
944944
/// Delete labeled data.

Tests/PersonalityInsightsV3IntegrationTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ public IEnumerator TestProfileAsCsv()
129129
profileAsCsvResponse = response.Result;
130130
Assert.IsNotNull(profileAsCsvResponse);
131131
Assert.IsNull(error);
132-
133-
//// Save file
134-
//using (FileStream fs = File.Create(Application.dataPath + "/personality-profile.csv"))
135-
//{
136-
// profileAsCsvResponse.WriteTo(fs);
137-
// fs.Close();
138-
// profileAsCsvResponse.Close();
139-
//}
132+
133+
// Save file
134+
using (FileStream fs = File.Create(Application.dataPath + "/personality-profile.csv"))
135+
{
136+
profileAsCsvResponse.WriteTo(fs);
137+
fs.Close();
138+
profileAsCsvResponse.Close();
139+
}
140140
},
141141
content: content,
142142
contentLanguage: "en",

Tests/TextToSpeechIntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ public IEnumerator TestListVoices()
124124
public IEnumerator TestSynthesize()
125125
{
126126
Log.Debug("TextToSpeechServiceV1IntegrationTests", "Attempting to Synthesize...");
127-
System.IO.MemoryStream synthesizeResponse = null;
127+
byte[] synthesizeResponse = null;
128128
AudioClip clip = null;
129129
service.Synthesize(
130-
callback: (DetailedResponse<System.IO.MemoryStream> response, IBMError error, Dictionary<string, object> customResponseData) =>
130+
callback: (DetailedResponse<byte[]> response, IBMError error, Dictionary<string, object> customResponseData) =>
131131
{
132132
synthesizeResponse = response.Result;
133133
Assert.IsNotNull(synthesizeResponse);
134134
Assert.IsNull(error);
135-
clip = WaveFile.ParseWAV("myClip", synthesizeResponse.ToArray());
135+
clip = WaveFile.ParseWAV("myClip", synthesizeResponse);
136136
PlayClip(clip);
137137

138138
},

Tests/VisualRecognitionV3IntegrationTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ public IEnumerator WaitForClassifier2()
296296
public IEnumerator TestGetCoreMlModel()
297297
{
298298
Log.Debug("VisualRecognitionServiceV3IntegrationTests", "Attempting to GetCoreMlModel...");
299-
System.IO.MemoryStream getCoreMlModelResponse = null;
299+
byte[] getCoreMlModelResponse = null;
300300
service.GetCoreMlModel(
301-
callback: (DetailedResponse<System.IO.MemoryStream> response, IBMError error, Dictionary<string, object> customResponseData) =>
301+
callback: (DetailedResponse<byte[]> response, IBMError error, Dictionary<string, object> customResponseData) =>
302302
{
303303
getCoreMlModelResponse = response.Result;
304304
Assert.IsNotNull(getCoreMlModelResponse);
@@ -307,9 +307,8 @@ public IEnumerator TestGetCoreMlModel()
307307
// Save file
308308
using (FileStream fs = File.Create(Application.dataPath + "/myModel.mlmodel"))
309309
{
310-
getCoreMlModelResponse.WriteTo(fs);
310+
fs.Write(getCoreMlModelResponse, 0, getCoreMlModelResponse.Length);
311311
fs.Close();
312-
getCoreMlModelResponse.Close();
313312
}
314313
},
315314
classifierId: classifierId,

0 commit comments

Comments
 (0)