@@ -33,7 +33,7 @@ public class ExampleStreaming : MonoBehaviour
33
33
private string _password = null ;
34
34
private string _url = null ;
35
35
public Text ResultsField ;
36
-
36
+
37
37
private int _recordingRoutine = 0 ;
38
38
private string _microphoneID = null ;
39
39
private AudioClip _recording = null ;
@@ -116,7 +116,7 @@ private void OnError(string error)
116
116
Log . Debug ( "ExampleStreaming" , "Error! {0}" , error ) ;
117
117
}
118
118
119
- #if CHUNK_BUFFER
119
+ #if CHUNK_BUFFER
120
120
121
121
private IEnumerator RecordingHandler ( )
122
122
{
@@ -167,8 +167,8 @@ private IEnumerator RecordingHandler()
167
167
sampleEnd . ToString ( ) ,
168
168
chunkNum . ToString ( ) ) ;
169
169
#endif
170
- //If the write position is past the end of the chunk or if write position is before the start of the chunk and the chunk number is equal to the chunk count
171
- if ( microphonePosition > sampleEnd || ( microphonePosition < sampleStart && chunkNum == ( _chunkCount - 1 ) ) )
170
+ //If the write position is past the end of the chunk or if write position is before the start of the chunk
171
+ while ( microphonePosition > sampleEnd || microphonePosition < sampleStart )
172
172
{
173
173
// Init samples
174
174
samples = new float [ chunkSize ] ;
@@ -204,21 +204,17 @@ private IEnumerator RecordingHandler()
204
204
Log . Debug ( "ExampleStreamingChunks" , "Sending data - time since last transmission: {0} ms" , Mathf . Floor ( ( float ) ( DateTime . Now - now ) . TotalMilliseconds ) ) ;
205
205
now = DateTime . Now ;
206
206
#endif
207
+ sampleStart = chunkSize * chunkNum ;
208
+ sampleEnd = chunkSize * ( chunkNum + 1 ) ;
207
209
}
208
- else
209
- {
210
- // calculate the number of samples remaining until we ready for a block of audio,
211
- // and wait that amount of time it will take to record.
212
- int remaining = sampleEnd - microphonePosition ;
213
- float timeRemaining = ( float ) remaining / ( float ) _recordingHZ ;
214
210
215
- yield return new WaitForSeconds ( timeRemaining ) ;
216
- }
211
+ yield return 0 ;
217
212
}
218
213
219
214
yield break ;
220
215
}
221
216
217
+
222
218
#else
223
219
224
220
private IEnumerator RecordingHandler ( )
@@ -288,9 +284,9 @@ private void OnRecognize(SpeechRecognitionEvent result)
288
284
{
289
285
foreach ( var alt in res . alternatives )
290
286
{
291
- string text = string . Format ( "{0} ({1}, {2:0.00})\n " , alt . transcript , res . final ? "Final" : "Interim" , alt . confidence ) ;
292
- Log . Debug ( "ExampleStreaming" , text ) ;
293
- ResultsField . text = text ;
287
+ string text = string . Format ( "{0} ({1}, {2:0.00})\n " , alt . transcript , res . final ? "Final" : "Interim" , alt . confidence ) ;
288
+ Log . Debug ( "ExampleStreaming" , text ) ;
289
+ ResultsField . text = text ;
294
290
}
295
291
296
292
if ( res . keywords_result != null && res . keywords_result . keyword != null )
@@ -306,7 +302,7 @@ private void OnRecognize(SpeechRecognitionEvent result)
306
302
foreach ( var wordAlternative in res . word_alternatives )
307
303
{
308
304
Log . Debug ( "ExampleSpeechToText" , "Word alternatives found. Start time: {0} | EndTime: {1}" , wordAlternative . start_time , wordAlternative . end_time ) ;
309
- foreach ( var alternative in wordAlternative . alternatives )
305
+ foreach ( var alternative in wordAlternative . alternatives )
310
306
Log . Debug ( "ExampleSpeechToText" , "\t word: {0} | confidence: {1}" , alternative . word , alternative . confidence ) ;
311
307
}
312
308
}
0 commit comments