@@ -58,6 +58,7 @@ public class ExampleSpeechToText : MonoBehaviour
58
58
private byte [ ] _oggResourceData ;
59
59
private string _oggResourceMimeType ;
60
60
private bool _isOggLoaded = false ;
61
+ private string _grammarFilePath ;
61
62
62
63
private bool _recognizeTested = false ;
63
64
private bool _recognizeOggTested = false ;
@@ -94,11 +95,20 @@ public class ExampleSpeechToText : MonoBehaviour
94
95
private bool _readyToContinue = false ;
95
96
private float _delayTimeInSeconds = 10f ;
96
97
98
+ private bool _listGrammarsTested = false ;
99
+ private bool _addGrammarTested = false ;
100
+ private bool _getGrammarTested = false ;
101
+ private bool _deleteGrammarTested = false ;
102
+ private string _createdGrammarId ;
103
+ private string _grammarFileContentType = "application/srgs" ;
104
+ private string _grammarName = "unity-integration-test-grammar" ;
105
+
97
106
void Start ( )
98
107
{
99
108
LogSystem . InstallDefaultReactors ( ) ;
100
109
_customCorpusFilePath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/theJabberwocky-utf8.txt" ;
101
110
_customWordsFilePath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/test-stt-words.json" ;
111
+ _grammarFilePath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/confirm.abnf" ;
102
112
_acousticResourceMimeType = Utility . GetMimeType ( Path . GetExtension ( _acousticResourceUrl ) ) ;
103
113
_oggResourceMimeType = Utility . GetMimeType ( Path . GetExtension ( _oggResourceUrl ) ) ;
104
114
Runnable . Run ( CreateService ( ) ) ;
@@ -285,12 +295,6 @@ private IEnumerator Examples()
285
295
while ( ! _isCustomizationReady )
286
296
yield return null ;
287
297
288
- // Upgrade customization - not currently implemented in service
289
- //Log.Debug("ExampleSpeechToText.Examples()", "Attempting to upgrade customization {0}", _createdCustomizationID);
290
- //_speechToText.UpgradeCustomization(HandleUpgradeCustomization, _createdCustomizationID);
291
- //while (!_upgradeCustomizationTested)
292
- // yield return null;
293
-
294
298
// Delete custom word
295
299
Log . Debug ( "ExampleSpeechToText.Examples()" , "Attempting to delete custom word {1} in customization {0}" , _createdCustomizationID , words . words [ 2 ] . word ) ;
296
300
_service . DeleteCustomWord ( HandleDeleteCustomWord , OnFail , _createdCustomizationID , words . words [ 2 ] . word ) ;
@@ -329,6 +333,37 @@ private IEnumerator Examples()
329
333
while ( ! _readyToContinue )
330
334
yield return null ;
331
335
336
+ // List Grammars
337
+ Log . Debug ( "TestSpeechToText.Examples()" , "Attempting to list grammars {0}" , _createdCustomizationID ) ;
338
+ _service . ListGrammars ( OnListGrammars , OnFail , _createdCustomizationID ) ;
339
+ while ( ! _listGrammarsTested )
340
+ yield return null ;
341
+
342
+ // Add Grammar
343
+ Log . Debug ( "TestSpeechToText.Examples()" , "Attempting to add grammar {0}" , _createdCustomizationID ) ;
344
+ string grammarFile = File . ReadAllText ( _grammarFilePath ) ;
345
+ _service . AddGrammar ( OnAddGrammar , OnFail , _createdCustomizationID , _grammarName , grammarFile , _grammarFileContentType ) ;
346
+ while ( ! _addGrammarTested )
347
+ yield return null ;
348
+
349
+ // Get Grammar
350
+ Log . Debug ( "TestSpeechToText.Examples()" , "Attempting to get grammar {0}" , _createdCustomizationID ) ;
351
+ _service . GetGrammar ( OnGetGrammar , OnFail , _createdCustomizationID , _grammarName ) ;
352
+ while ( ! _getGrammarTested )
353
+ yield return null ;
354
+
355
+ // Wait for customization
356
+ _isCustomizationReady = false ;
357
+ Runnable . Run ( CheckCustomizationStatus ( _createdCustomizationID ) ) ;
358
+ while ( ! _isCustomizationReady )
359
+ yield return null ;
360
+
361
+ // Delete Grammar
362
+ Log . Debug ( "TestSpeechToText.Examples()" , "Attempting to delete grammar {0}" , _createdCustomizationID ) ;
363
+ _service . DeleteGrammar ( OnDeleteGrammar , OnFail , _createdCustomizationID , _grammarName ) ;
364
+ while ( ! _deleteGrammarTested )
365
+ yield return null ;
366
+
332
367
_readyToContinue = false ;
333
368
// Delete customization
334
369
Log . Debug ( "ExampleSpeechToText.Examples()" , "Attempting to delete customization {0}" , _createdCustomizationID ) ;
@@ -639,6 +674,30 @@ private void HandleDeleteAcousticCustomization(bool success, Dictionary<string,
639
674
DeleteAcousticCustomization ( ) ;
640
675
}
641
676
677
+ private void OnListGrammars ( Grammars response , Dictionary < string , object > customData )
678
+ {
679
+ Log . Debug ( "ExampleSpeechToText.OnListGrammars()" , "{0}" , customData [ "json" ] . ToString ( ) ) ;
680
+ _listGrammarsTested = true ;
681
+ }
682
+
683
+ private void OnAddGrammar ( object response , Dictionary < string , object > customData )
684
+ {
685
+ Log . Debug ( "ExampleSpeechToText.OnAddGrammar()" , "Success!" ) ;
686
+ _addGrammarTested = true ;
687
+ }
688
+
689
+ private void OnGetGrammar ( Grammar response , Dictionary < string , object > customData )
690
+ {
691
+ Log . Debug ( "ExampleSpeechToText.OnGetGrammar()" , "{0}" , customData [ "json" ] . ToString ( ) ) ;
692
+ _getGrammarTested = true ;
693
+ }
694
+
695
+ private void OnDeleteGrammar ( object response , Dictionary < string , object > customData )
696
+ {
697
+ Log . Debug ( "ExampleSpeechToText.OnDeleteGrammar()" , "Success!" ) ;
698
+ _deleteGrammarTested = true ;
699
+ }
700
+
642
701
private IEnumerator CheckCustomizationStatus ( string customizationID , float delay = 0.1f )
643
702
{
644
703
Log . Debug ( "ExampleSpeechToText.CheckCustomizationStatus()" , "Checking customization status in {0} seconds..." , delay . ToString ( ) ) ;
0 commit comments