@@ -44,38 +44,108 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
44
44
<img width =" 393 " alt =" neocortex_unity_smart_agent_component " src =" https://github.com/user-attachments/assets/9613bb88-87a9-4ba5-b412-d404c0bf63e3 " >
45
45
</p >
46
46
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.
49
49
- Parameters:
50
- - ` message ` : The message to send
50
+ - ` message ` : The text message to send.
51
51
- Example:
52
52
``` csharp
53
53
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!" );
55
82
```
56
83
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 .
59
86
- Parameters :
60
- - `audio `: The audio data to send
87
+ - `audioClip `: The audio clip to send .
61
88
- Example :
62
89
```csharp
63
90
var smartAgent = GetComponent <NeocortexSmartAgent >();
91
+ smartAgent .OnTranscriptionReceived .AddListener ((message ) =>
92
+ {
93
+ Debug .Log ($" You: {message }" );
94
+ });
95
+
64
96
var audioReceiver = GetComponent <NeocortexAudioReceiver >();
65
- audioReceiver .OnAudioRecorded += ( audioData ) =>
97
+ audioReceiver .OnAudioRecorded . AddListener (( audioClip ) =>
66
98
{
67
- smartAgent .Send (audioData );
68
- };
99
+ Debug .Log ($" Audio Data Length: {audioClip .samples }" );
100
+ smartAgent .AudioToText (audioClip );
101
+ });
69
102
70
- // Start recording audio for 5 seconds
103
+ // Start recording audio for 3 seconds
71
104
audioReceiver .StartMicrophone ();
72
- await Task .Delay (5000 );
105
+ await Task .Delay (3000 );
73
106
audioReceiver .StopMicrophone ();
74
107
```
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 .
77
111
- 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 .
79
149
- Example :
80
150
```csharp
81
151
var smartAgent = GetComponent <NeocortexSmartAgent >();
@@ -86,10 +156,10 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
86
156
};
87
157
```
88
158
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.
91
161
- Parameters :
92
- - `message `: The transcribed message
162
+ - `message `: The transcribed audio message .
93
163
- Example :
94
164
```csharp
95
165
var smartAgent = GetComponent <NeocortexSmartAgent >();
@@ -99,10 +169,10 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
99
169
};
100
170
```
101
171
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.
104
174
- Parameters :
105
- - `audioClip `: The audio clip received from the Neocortex project
175
+ - `audioClip `: The audio clip received from the Neocortex project .
106
176
- Example :
107
177
```csharp
108
178
var audioSource = GetComponent <AudioSource >();
@@ -114,6 +184,19 @@ The `Neocortex Smart Agent` component is the main component that allows you to i
114
184
};
115
185
```
116
186
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
+
117
200
### NeocortexAudioReceiver component
118
201
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 :
119
202
- pick the microphone device to use
@@ -140,17 +223,17 @@ The `NeocortexAudioReceiver` component is used to record audio data from the mic
140
223
audioReceiver .StopMicrophone ();
141
224
```
142
225
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.
147
230
- Example:
148
231
``` csharp
149
232
var audioReceiver = GetComponent <NeocortexAudioReceiver >();
150
- audioReceiver .OnAudioRecorded += ( audioData ) =>
233
+ audioReceiver .OnAudioRecorded . AddListener (( audioClip ) =>
151
234
{
152
- Debug .Log ($" Audio Data Length: {audioData . Length }" );
153
- };
235
+ Debug .Log ($" Audio Data Length: {audioClip . samples }" );
236
+ }) ;
154
237
```
155
238
156
239
## Sample Projects
0 commit comments