Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Editor/LinkXmlTransferer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.UnityLinker;
using UnityEditor.Build.Reporting;

namespace OpenAI
{
public class LinkXmlTransferer : IUnityLinkerProcessor
{
private const string SearchFolder = "Packages/com.srcnalt.openai-unity/Resources";

int IOrderedCallback.callbackOrder => 0;

public string GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data)
{
string[] linkXmlGuid = AssetDatabase.FindAssets("link", new string[] { SearchFolder });
string linkXmlPath = AssetDatabase.GUIDToAssetPath(linkXmlGuid[0]);
return Path.GetFullPath(linkXmlPath);
}

public void OnBeforeRun(BuildReport report, UnityLinkerBuildPipelineData data) { }

public void OnAfterRun(BuildReport report, UnityLinkerBuildPipelineData data) { }
}
}
11 changes: 11 additions & 0 deletions Editor/LinkXmlTransferer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Editor/OpenAI.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "OpenAI.Editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/OpenAI.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Resources/link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<linker>
<assembly fullname="OpenAI.Runtime" preserve="all" />
</linker>
3 changes: 3 additions & 0 deletions Resources/link.xml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/OpenAIApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private async Task<T> DispatchRequest<T>(string path, List<IMultipartFormSection
var formSections = UnityWebRequest.SerializeFormSections(form, boundary);
var contentType = $"{ContentType.MultipartFormData}; boundary={Encoding.UTF8.GetString(boundary)}";
request.uploadHandler = new UploadHandlerRaw(formSections) {contentType = contentType};
request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
request.downloadHandler = new DownloadHandlerBuffer();
var asyncOperation = request.SendWebRequest();

while (!asyncOperation.isDone) await Task.Yield();
Expand Down
15 changes: 12 additions & 3 deletions Samples~/Whisper/Whisper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;

namespace OpenAI
Expand All @@ -21,6 +20,9 @@ public class Whisper : MonoBehaviour

private void Start()
{
#if UNITY_WEBGL && !UNITY_EDITOR
dropdown.options.Add(new Dropdown.OptionData("Microphone not supported on WebGL"));
#else
foreach (var device in Microphone.devices)
{
dropdown.options.Add(new Dropdown.OptionData(device));
Expand All @@ -30,6 +32,7 @@ private void Start()

var index = PlayerPrefs.GetInt("user-mic-device-index");
dropdown.SetValueWithoutNotify(index);
#endif
}

private void ChangeMicrophone(int index)
Expand All @@ -43,22 +46,28 @@ private void StartRecording()
recordButton.enabled = false;

var index = PlayerPrefs.GetInt("user-mic-device-index");

#if !UNITY_WEBGL
clip = Microphone.Start(dropdown.options[index].text, false, duration, 44100);
#endif
}

private async void EndRecording()
{
message.text = "Transcripting...";

#if !UNITY_WEBGL
Microphone.End(null);
#endif

byte[] data = SaveWav.Save(fileName, clip);

var req = new CreateAudioTranscriptionsRequest
{
FileData = new FileData() {Data = data, Name = "audio.wav"},
// File = Application.persistentDataPath + "/" + fileName,
Model = "whisper-1",
Language = "en"
Language = "id"
};
var res = await openai.CreateAudioTranscription(req);

Expand Down