@@ -135,74 +135,74 @@ private IEnumerator RecordingHandler()
135
135
// Init samples
136
136
float [ ] samples = null ;
137
137
138
- while ( _recordingRoutine != 0 && _recording != null )
139
- {
140
- // Get the mic position
141
- int microphonePosition = Microphone . GetPosition ( _microphoneID ) ;
142
- if ( microphonePosition > _recording . samples || ! Microphone . IsRecording ( _microphoneID ) )
143
- {
144
- Log . Error ( "ExampleStreaming" , "Microphone disconnected." ) ;
145
-
146
- StopRecording ( ) ;
147
- yield break ;
148
- }
149
-
150
- int sampleStart = chunkSize * chunkNum ;
151
- int sampleEnd = chunkSize * ( chunkNum + 1 ) ;
152
-
153
- #if ENABLE_DEBUGGING
154
- Log . Debug ( "ExampleStreamingChunks" , "microphonePosition: {0} | sampleStart: {1} | sampleEnd: {2} | chunkNum: {3}" ,
155
- microphonePosition . ToString ( ) ,
156
- sampleStart . ToString ( ) ,
157
- sampleEnd . ToString ( ) ,
158
- chunkNum . ToString ( ) ) ;
159
- #endif
160
- //If the write position is past the end of the chunk or if write position is before the start of the chunk
161
- while ( microphonePosition > sampleEnd || microphonePosition < sampleStart )
162
- {
163
- // Init samples
164
- samples = new float [ chunkSize ] ;
165
- // Write data from recording into samples starting from the chunkStart
166
- _recording . GetData ( samples , sampleStart ) ;
167
-
168
- // Create AudioData and use the samples we just created
169
- AudioData record = new AudioData ( ) ;
170
- record . MaxLevel = Mathf . Max ( Mathf . Abs ( Mathf . Min ( samples ) ) , Mathf . Max ( samples ) ) ;
171
- record . Clip = AudioClip . Create ( "Recording" , chunkSize , _recording . channels , _recordingHZ , false ) ;
172
- record . Clip . SetData ( samples , 0 ) ;
173
-
174
- // Send the newly created AudioData to the service
175
- _speechToText . OnListen ( record ) ;
176
-
177
- // Iterate or reset chunkNum
178
- if ( chunkNum < _chunkCount - 1 )
179
- {
180
- chunkNum ++ ;
181
- #if ENABLE_DEBUGGING
182
- Log . Debug ( "ExampleStreamingChunks" , "Iterating chunkNum: {0}" , chunkNum ) ;
183
- #endif
184
- }
185
- else
186
- {
187
- chunkNum = 0 ;
188
- #if ENABLE_DEBUGGING
189
- Log . Debug ( "ExampleStreamingChunks" , "Resetting chunkNum: {0}" , chunkNum ) ;
190
- #endif
191
- }
192
-
193
- #if ENABLE_TIME_LOGGING
194
- Log . Debug ( "ExampleStreamingChunks" , "Sending data - time since last transmission: {0} ms" , Mathf . Floor ( ( float ) ( DateTime . Now - now ) . TotalMilliseconds ) ) ;
195
- now = DateTime . Now ;
196
- #endif
197
- sampleStart = chunkSize * chunkNum ;
198
- sampleEnd = chunkSize * ( chunkNum + 1 ) ;
199
- }
200
-
201
- yield return 0 ;
202
- }
203
-
204
- yield break ;
205
- }
138
+ while ( _recordingRoutine != 0 && _recording != null )
139
+ {
140
+ // Get the mic position
141
+ int microphonePosition = Microphone . GetPosition ( _microphoneID ) ;
142
+ if ( microphonePosition > _recording . samples || ! Microphone . IsRecording ( _microphoneID ) )
143
+ {
144
+ Log . Error ( "ExampleStreaming" , "Microphone disconnected." ) ;
145
+
146
+ StopRecording ( ) ;
147
+ yield break ;
148
+ }
149
+
150
+ int sampleStart = chunkSize * chunkNum ;
151
+ int sampleEnd = chunkSize * ( chunkNum + 1 ) ;
152
+
153
+ #if ENABLE_DEBUGGING
154
+ Log . Debug ( "ExampleStreamingChunks" , "microphonePosition: {0} | sampleStart: {1} | sampleEnd: {2} | chunkNum: {3}" ,
155
+ microphonePosition . ToString ( ) ,
156
+ sampleStart . ToString ( ) ,
157
+ sampleEnd . ToString ( ) ,
158
+ chunkNum . ToString ( ) ) ;
159
+ #endif
160
+ //If the write position is past the end of the chunk or if write position is before the start of the chunk
161
+ while ( microphonePosition > sampleEnd || microphonePosition < sampleStart )
162
+ {
163
+ // Init samples
164
+ samples = new float [ chunkSize ] ;
165
+ // Write data from recording into samples starting from the chunkStart
166
+ _recording . GetData ( samples , sampleStart ) ;
167
+
168
+ // Create AudioData and use the samples we just created
169
+ AudioData record = new AudioData ( ) ;
170
+ record . MaxLevel = Mathf . Max ( samples ) ;
171
+ record . Clip = AudioClip . Create ( "Recording" , chunkSize , _recording . channels , _recordingHZ , false ) ;
172
+ record . Clip . SetData ( samples , 0 ) ;
173
+
174
+ // Send the newly created AudioData to the service
175
+ _speechToText . OnListen ( record ) ;
176
+
177
+ // Iterate or reset chunkNum
178
+ if ( chunkNum < _chunkCount - 1 )
179
+ {
180
+ chunkNum ++ ;
181
+ #if ENABLE_DEBUGGING
182
+ Log . Debug ( "ExampleStreamingChunks" , "Iterating chunkNum: {0}" , chunkNum ) ;
183
+ #endif
184
+ }
185
+ else
186
+ {
187
+ chunkNum = 0 ;
188
+ #if ENABLE_DEBUGGING
189
+ Log . Debug ( "ExampleStreamingChunks" , "Resetting chunkNum: {0}" , chunkNum ) ;
190
+ #endif
191
+ }
192
+
193
+ #if ENABLE_TIME_LOGGING
194
+ Log . Debug ( "ExampleStreamingChunks" , "Sending data - time since last transmission: {0} ms" , Mathf . Floor ( ( float ) ( DateTime . Now - now ) . TotalMilliseconds ) ) ;
195
+ now = DateTime . Now ;
196
+ #endif
197
+ sampleStart = chunkSize * chunkNum ;
198
+ sampleEnd = chunkSize * ( chunkNum + 1 ) ;
199
+ }
200
+
201
+ yield return 0 ;
202
+ }
203
+
204
+ yield break ;
205
+ }
206
206
207
207
private void OnRecognize ( SpeechRecognitionEvent result )
208
208
{
0 commit comments