1
1
using System ;
2
+ using System . Collections ;
2
3
using System . IO ;
3
4
using UnityEngine ;
4
5
using System . Text ;
@@ -195,6 +196,21 @@ private async Task<string> DispatchSimpleRequest(string path, byte[] payload = n
195
196
196
197
return data ;
197
198
}
199
+
200
+ private async Task < AudioClip > DispatchAudioRequest ( string path , byte [ ] payload = null )
201
+ {
202
+ using var request = UnityWebRequest . Put ( path , payload ) ;
203
+ request . method = UnityWebRequest . kHttpVerbGET ;
204
+ request . SetHeaders ( Configuration , ContentType . ApplicationJson ) ;
205
+ request . downloadHandler = new DownloadHandlerAudioClip ( path , AudioType . WAV ) ;
206
+
207
+ var asyncOperation = request . SendWebRequest ( ) ;
208
+ while ( ! asyncOperation . isDone ) await Task . Yield ( ) ;
209
+
210
+ AudioClip audioClip = DownloadHandlerAudioClip . GetContent ( request ) ;
211
+
212
+ return audioClip ;
213
+ }
198
214
199
215
200
216
/// <summary>
@@ -335,7 +351,7 @@ public async Task<string> CreateChatCompletionSimplePrompt(CreateChatCompletionR
335
351
/// </summary>
336
352
/// <param name="request">See <see cref="CreateChatCompletionRequestPrompt"/></param>
337
353
/// <returns>string</returns>
338
- public async Task < VoiceResponse > CreateSpeechPrompt ( CreateChatCompletionRequestPrompt request )
354
+ public async Task < AudioClip > CreateSpeechPrompt ( CreateChatCompletionRequestPrompt request )
339
355
{
340
356
var path = $ "{ BASE_PATH } /unity/voice";
341
357
@@ -360,9 +376,8 @@ public async Task<VoiceResponse> CreateSpeechPrompt(CreateChatCompletionRequestP
360
376
Jailbreak = "default" ,
361
377
} ;
362
378
363
-
364
379
var payload = CreatePayloadKoala ( req ) ;
365
- return await DispatchSimpleRequest ( path , payload ) ;
380
+ return await DispatchAudioRequest ( path , payload ) ;
366
381
}
367
382
368
383
@@ -382,6 +397,34 @@ public void CreateChatCompletionAsync(CreateChatCompletionRequest request,
382
397
383
398
DispatchRequest ( path , UnityWebRequest . kHttpVerbPOST , onResponse , onComplete , token , payload ) ;
384
399
}
400
+
401
+ // /// <summary>
402
+ // /// Transcribes audio into the input language.
403
+ // /// </summary>
404
+ // /// <param name="request">See <see cref="CreateAudioTranscriptionsRequest"/></param>
405
+ // /// <returns>See <see cref="CreateAudioResponse"/></returns>
406
+ // public async Task<CreateAudioResponse> CreateAudioTranscription(CreateAudioTranscriptionsRequest request)
407
+ // {
408
+ // var path = $"{BASE_PATH}/audio/transcriptions";
409
+ //
410
+ // var form = new List<IMultipartFormSection>();
411
+ // if (string.IsNullOrEmpty(request.File))
412
+ // {
413
+ // form.AddData(request.FileData, "file", $"audio/{Path.GetExtension(request.File)}");
414
+ // }
415
+ // else
416
+ // {
417
+ // form.AddFile(request.File, "file", $"audio/{Path.GetExtension(request.File)}");
418
+ // }
419
+ // form.AddValue(request.Model, "model");
420
+ // form.AddValue(request.Prompt, "prompt");
421
+ // form.AddValue(request.ResponseFormat, "response_format");
422
+ // form.AddValue(request.Temperature, "temperature");
423
+ // form.AddValue(request.Language, "language");
424
+ //
425
+ // return await DispatchRequest<CreateAudioResponse>(path, form);
426
+ // }
427
+ //
385
428
386
429
/// <summary>
387
430
/// Classifies if text violates KoalaGPT's Content Policy
0 commit comments