Skip to content

Commit 5c2c3ca

Browse files
authored
Merge pull request #3 from neocortex-link/feature/request-unification
API Updates / Request Unification
2 parents aa89e1c + 22059df commit 5c2c3ca

25 files changed

+336
-292
lines changed

Editor/AudioReceiverEditor.cs renamed to Editor/NeocortexAudioReceiverEditor.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@
44
namespace Neocortex.Editor
55
{
66
[CustomEditor(typeof(NeocortexAudioReceiver))]
7-
public class AudioReceiverEditor : UnityEditor.Editor
7+
public class NeocortexAudioReceiverEditor : UnityEditor.Editor
88
{
9-
private const string MIC_INDEX_KEY = "neocortex-mix-index";
9+
private const string MIC_INDEX_KEY = "neocortex-mic-index";
1010

1111
private string[] microphoneOptions;
1212
private int selectedMicrophoneIndex;
1313

14+
private SerializedProperty onAudioRecorded;
15+
private SerializedProperty onRecordingFailed;
16+
1417
private void OnEnable()
1518
{
1619
microphoneOptions = Microphone.devices;
1720
selectedMicrophoneIndex = PlayerPrefs.GetInt(MIC_INDEX_KEY, 0);
1821

1922
NeocortexAudioReceiver audioReceiver = (NeocortexAudioReceiver)target;
2023
audioReceiver.SelectedMicrophone = microphoneOptions[selectedMicrophoneIndex];
24+
25+
onAudioRecorded = serializedObject.FindProperty("OnAudioRecorded");
26+
onRecordingFailed = serializedObject.FindProperty("OnRecordingFailed");
2127
}
2228

2329
public override void OnInspectorGUI()
@@ -36,6 +42,14 @@ public override void OnInspectorGUI()
3642
{
3743
EditorGUILayout.LabelField("No microphones available.");
3844
}
45+
46+
GUILayout.Space(8);
47+
EditorGUILayout.PropertyField(onAudioRecorded);
48+
serializedObject.ApplyModifiedProperties();
49+
50+
GUILayout.Space(8);
51+
EditorGUILayout.PropertyField(onRecordingFailed);
52+
serializedObject.ApplyModifiedProperties();
3953
}
4054
}
4155
}

Editor/UI/NeocortexChatPanelEditor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using UnityEditor;
32
using UnityEngine;
43

README.md

Lines changed: 111 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,108 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
4444
<img width="393" alt="neocortex_unity_smart_agent_component" src="https://github.com/user-attachments/assets/9613bb88-87a9-4ba5-b412-d404c0bf63e3">
4545
</p>
4646

47-
**public async void Send(string message)**
48-
- Sends a message to the Neocortex project
47+
**public async void TextToText(string message)**
48+
- Send a text message to the Neocortex project, and expect a text response.
4949
- Parameters:
50-
- `message`: The message to send
50+
- `message`: The text message to send.
5151
- Example:
5252
```csharp
5353
var smartAgent = GetComponent<NeocortexSmartAgent>();
54-
smartAgent.Send("Hello, Neocortex!");
54+
smartAgent.OnChatResponseReceived.AddListener((response) =>
55+
{
56+
Debug.Log($"Message: {response.message}");
57+
Debug.Log($"Action: {response.action}");
58+
});
59+
smartAgent.TextToText("Hello, Neocortex!");
60+
```
61+
62+
**public async void TextToAudio(string message)**
63+
- Send a text message to the Neocortex project, and expect a audio response.
64+
- Parameters:
65+
- `message`: The text message to send.
66+
- Example:
67+
```csharp
68+
var audioSource = GetComponent<AudioSource>();
69+
var smartAgent = GetComponent<NeocortexSmartAgent>();
70+
smartAgent.OnChatResponseReceived.AddListener((response) =>
71+
{
72+
Debug.Log($"Message: {response.message}");
73+
Debug.Log($"Action: {response.action}");
74+
});
75+
smartAgent.OnAudioResponseReceived.AddListener((audioClip) =>
76+
{
77+
audioSource.clip = audioClip;
78+
audioSource.Play();
79+
});
80+
81+
smartAgent.TextToAudio("Hello, Neocortex!");
5582
```
5683

57-
**public async void Send(byte[] audio)**
58-
- Sends an audio clip to the Neocortex project. This method is used with `NeocortexAudioReceiver` component to send audio data to the Neocortex project.
84+
**public async void AudioToText(AudioClip audio)**
85+
- Sends an audio clip to the Neocortex project. This method is used with `NeocortexAudioReceiver` component to send audio data.
5986
- Parameters:
60-
- `audio`: The audio data to send
87+
- `audioClip`: The audio clip to send.
6188
- Example:
6289
```csharp
6390
var smartAgent = GetComponent<NeocortexSmartAgent>();
91+
smartAgent.OnTranscriptionReceived.AddListener((message) =>
92+
{
93+
Debug.Log($"You: {message}");
94+
});
95+
6496
var audioReceiver = GetComponent<NeocortexAudioReceiver>();
65-
audioReceiver.OnAudioRecorded += (audioData) =>
97+
audioReceiver.OnAudioRecorded.AddListener((audioClip) =>
6698
{
67-
smartAgent.Send(audioData);
68-
};
99+
Debug.Log($"Audio Data Length: {audioClip.samples}");
100+
smartAgent.AudioToText(audioClip);
101+
});
69102

70-
// Start recording audio for 5 seconds
103+
// Start recording audio for 3 seconds
71104
audioReceiver.StartMicrophone();
72-
await Task.Delay(5000);
105+
await Task.Delay(3000);
73106
audioReceiver.StopMicrophone();
74107
```
75-
**public event Action<ChatResponse> OnChatResponseReceived**
76-
- Event that is triggered when the Neocortex project responds to a message
108+
109+
**public async void AudioToAudio(AudioClip audio)**
110+
- Sends an audio clip to the Neocortex project and expects an audio response. This method is used with `NeocortexAudioReceiver` component to send audio data.
77111
- Parameters:
78-
- `response`: The response from the Neocortex project
112+
- `audioClip`: The audio clip to send.
113+
- Example:
114+
```csharp
115+
var audioSource = GetComponent<AudioSource>();
116+
var smartAgent = GetComponent<NeocortexSmartAgent>();
117+
smartAgent.OnAudioResponseReceived.AddListener((audioClip) =>
118+
{
119+
audioSource.clip = audioClip;
120+
audioSource.Play();
121+
});
122+
smartAgent.OnTranscriptionReceived.AddListener((message) =>
123+
{
124+
Debug.Log($"You: {message}");
125+
});
126+
smartAgent.OnChatResponseReceived.AddListener((response) =>
127+
{
128+
Debug.Log($"Message: {response.message}");
129+
Debug.Log($"Action: {response.action}");
130+
});
131+
132+
var audioReceiver = GetComponent<NeocortexAudioReceiver>();
133+
audioReceiver.OnAudioRecorded.AddListener((audioClip) =>
134+
{
135+
Debug.Log($"Audio Data Length: {audioClip.samples}");
136+
smartAgent.AudioToAudio(audioClip);
137+
});
138+
139+
// Start recording audio for 3 seconds
140+
audioReceiver.StartMicrophone();
141+
await Task.Delay(3000);
142+
audioReceiver.StopMicrophone();
143+
```
144+
145+
**public UnityEvent<ChatResponse> OnChatResponseReceived**
146+
- Event that is triggered when the Neocortex project responds to a text message.
147+
- Parameters:
148+
- `response`: The response from the Neocortex project.
79149
- Example:
80150
```csharp
81151
var smartAgent = GetComponent<NeocortexSmartAgent>();
@@ -86,10 +156,10 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
86156
};
87157
```
88158

89-
**public event Action<string> OnTranscriptionReceived**
90-
- Event that is triggered when the Neocortex project transcribes an audio message to text
159+
**public UnityEvent<string> OnTranscriptionReceived**
160+
- Event that is triggered when the Neocortex project transcribes an audio message to text.
91161
- Parameters:
92-
- `message`: The transcribed message
162+
- `message`: The transcribed audio message.
93163
- Example:
94164
```csharp
95165
var smartAgent = GetComponent<NeocortexSmartAgent>();
@@ -99,10 +169,10 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
99169
};
100170
```
101171

102-
**public event Action<AudioClip> OnAudioResponseReceived**
103-
- Event that is triggered when the Neocortex project responds with an audio message
172+
**public UnityEvent<AudioClip> OnAudioResponseReceived**
173+
- Event that is triggered when the Neocortex project responds with an audio message.
104174
- Parameters:
105-
- `audioClip`: The audio clip received from the Neocortex project
175+
- `audioClip`: The audio clip received from the Neocortex project.
106176
- Example:
107177
```csharp
108178
var audioSource = GetComponent<AudioSource>();
@@ -114,6 +184,19 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
114184
};
115185
```
116186

187+
**public UnityEvent<string> OnRequestFailed**
188+
- Event that is triggered when a request to the Neocortex project fails.
189+
- Parameters:
190+
- `error`: The error message.
191+
- Example:
192+
```csharp
193+
var smartAgent = GetComponent<NeocortexSmartAgent>();
194+
smartAgent.OnRequestFailed += (error) =>
195+
{
196+
Debug.LogError(error);
197+
};
198+
```
199+
117200
### NeocortexAudioReceiver component
118201
The `NeocortexAudioReceiver` component is used to record audio data from the microphone via loudness of the souned, so you can have a hands free chat with the smart agent. On this component you can:
119202
- pick the microphone device to use
@@ -140,17 +223,17 @@ The `NeocortexAudioReceiver` component is used to record audio data from the mic
140223
audioReceiver.StopMicrophone();
141224
```
142225

143-
**public event UnityAction<byte[]> OnAudioRecorded**
144-
- Event that is triggered when audio data is recorded from the microphone
145-
- Parameters:
146-
- `audioData`: The recorded audio data
226+
**public UnityEvent<AudioClip> OnAudioRecorded OnAudioRecorded**
227+
- Event that is triggered when audio data is recorded from the microphone.
228+
- Returns:
229+
- `audioClip`: The recorded audio clip.
147230
- Example:
148231
```csharp
149232
var audioReceiver = GetComponent<NeocortexAudioReceiver>();
150-
audioReceiver.OnAudioRecorded += (audioData) =>
233+
audioReceiver.OnAudioRecorded.AddListener((audioClip) =>
151234
{
152-
Debug.Log($"Audio Data Length: {audioData.Length}");
153-
};
235+
Debug.Log($"Audio Data Length: {audioClip.samples}");
236+
});
154237
```
155238

156239
## Sample Projects

Resources/Prefabs/Audio Chat Input.prefab

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ GameObject:
462462
- component: {fileID: 2962727209791358683}
463463
- component: {fileID: 7710414645333600691}
464464
- component: {fileID: 973319749406882948}
465-
- component: {fileID: 3425882831741277229}
466465
m_Layer: 5
467466
m_Name: Chat State
468467
m_TagString: Untagged
@@ -531,50 +530,6 @@ MonoBehaviour:
531530
m_FillOrigin: 0
532531
m_UseSpriteMesh: 0
533532
m_PixelsPerUnitMultiplier: 1
534-
--- !u!114 &3425882831741277229
535-
MonoBehaviour:
536-
m_ObjectHideFlags: 0
537-
m_CorrespondingSourceObject: {fileID: 0}
538-
m_PrefabInstance: {fileID: 0}
539-
m_PrefabAsset: {fileID: 0}
540-
m_GameObject: {fileID: 969423940934023843}
541-
m_Enabled: 1
542-
m_EditorHideFlags: 0
543-
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
544-
m_Name:
545-
m_EditorClassIdentifier:
546-
m_Navigation:
547-
m_Mode: 3
548-
m_WrapAround: 0
549-
m_SelectOnUp: {fileID: 0}
550-
m_SelectOnDown: {fileID: 0}
551-
m_SelectOnLeft: {fileID: 0}
552-
m_SelectOnRight: {fileID: 0}
553-
m_Transition: 1
554-
m_Colors:
555-
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
556-
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
557-
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
558-
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
559-
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
560-
m_ColorMultiplier: 1
561-
m_FadeDuration: 0.1
562-
m_SpriteState:
563-
m_HighlightedSprite: {fileID: 0}
564-
m_PressedSprite: {fileID: 0}
565-
m_SelectedSprite: {fileID: 0}
566-
m_DisabledSprite: {fileID: 0}
567-
m_AnimationTriggers:
568-
m_NormalTrigger: Normal
569-
m_HighlightedTrigger: Highlighted
570-
m_PressedTrigger: Pressed
571-
m_SelectedTrigger: Selected
572-
m_DisabledTrigger: Disabled
573-
m_Interactable: 1
574-
m_TargetGraphic: {fileID: 973319749406882948}
575-
m_OnClick:
576-
m_PersistentCalls:
577-
m_Calls: []
578533
--- !u!1 &2381234143618097104
579534
GameObject:
580535
m_ObjectHideFlags: 0

Runtime/API/V1/Models/ApiPayload.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using UnityEngine.Networking;
3+
4+
namespace Neocortex.API
5+
{
6+
[Serializable]
7+
public class ApiPayload
8+
{
9+
public string url;
10+
public string method = UnityWebRequest.kHttpVerbPOST;
11+
public byte[] data;
12+
public bool isAudio;
13+
}
14+
}

Runtime/API/V1/Models/ApiRequest.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)