Skip to content

Commit 512d234

Browse files
authored
Merge pull request #68 from srcnalt/feature/cleanup
Avoid Code Stripping for Package
2 parents d51ac7c + 31101f8 commit 512d234

10 files changed

+95
-4
lines changed

Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/LinkXmlTransferer.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.IO;
2+
using UnityEditor;
3+
using UnityEditor.Build;
4+
using UnityEditor.UnityLinker;
5+
using UnityEditor.Build.Reporting;
6+
7+
namespace OpenAI
8+
{
9+
public class LinkXmlTransferer : IUnityLinkerProcessor
10+
{
11+
private const string SearchFolder = "Packages/com.srcnalt.openai-unity/Resources";
12+
13+
int IOrderedCallback.callbackOrder => 0;
14+
15+
public string GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data)
16+
{
17+
string[] linkXmlGuid = AssetDatabase.FindAssets("link", new string[] { SearchFolder });
18+
string linkXmlPath = AssetDatabase.GUIDToAssetPath(linkXmlGuid[0]);
19+
return Path.GetFullPath(linkXmlPath);
20+
}
21+
22+
public void OnBeforeRun(BuildReport report, UnityLinkerBuildPipelineData data) { }
23+
24+
public void OnAfterRun(BuildReport report, UnityLinkerBuildPipelineData data) { }
25+
}
26+
}

Editor/LinkXmlTransferer.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/OpenAI.Editor.asmdef

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "OpenAI.Editor",
3+
"rootNamespace": "",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

Editor/OpenAI.Editor.asmdef.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/link.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<linker>
2+
<assembly fullname="OpenAI.Runtime" preserve="all" />
3+
</linker>

Resources/link.xml.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/OpenAIApi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private async Task<T> DispatchRequest<T>(string path, List<IMultipartFormSection
164164
var formSections = UnityWebRequest.SerializeFormSections(form, boundary);
165165
var contentType = $"{ContentType.MultipartFormData}; boundary={Encoding.UTF8.GetString(boundary)}";
166166
request.uploadHandler = new UploadHandlerRaw(formSections) {contentType = contentType};
167-
request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
167+
request.downloadHandler = new DownloadHandlerBuffer();
168168
var asyncOperation = request.SendWebRequest();
169169

170170
while (!asyncOperation.isDone) await Task.Yield();

Samples~/Whisper/Whisper.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using UnityEngine;
1+
using UnityEngine;
32
using UnityEngine.UI;
43

54
namespace OpenAI
@@ -21,6 +20,9 @@ public class Whisper : MonoBehaviour
2120

2221
private void Start()
2322
{
23+
#if UNITY_WEBGL && !UNITY_EDITOR
24+
dropdown.options.Add(new Dropdown.OptionData("Microphone not supported on WebGL"));
25+
#else
2426
foreach (var device in Microphone.devices)
2527
{
2628
dropdown.options.Add(new Dropdown.OptionData(device));
@@ -30,6 +32,7 @@ private void Start()
3032

3133
var index = PlayerPrefs.GetInt("user-mic-device-index");
3234
dropdown.SetValueWithoutNotify(index);
35+
#endif
3336
}
3437

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

4548
var index = PlayerPrefs.GetInt("user-mic-device-index");
49+
50+
#if !UNITY_WEBGL
4651
clip = Microphone.Start(dropdown.options[index].text, false, duration, 44100);
52+
#endif
4753
}
4854

4955
private async void EndRecording()
5056
{
5157
message.text = "Transcripting...";
5258

59+
#if !UNITY_WEBGL
5360
Microphone.End(null);
61+
#endif
62+
5463
byte[] data = SaveWav.Save(fileName, clip);
5564

5665
var req = new CreateAudioTranscriptionsRequest
5766
{
5867
FileData = new FileData() {Data = data, Name = "audio.wav"},
5968
// File = Application.persistentDataPath + "/" + fileName,
6069
Model = "whisper-1",
61-
Language = "en"
70+
Language = "id"
6271
};
6372
var res = await openai.CreateAudioTranscription(req);
6473

0 commit comments

Comments
 (0)