views:

311

answers:

0

I have converted this code in c# which has already written in VB.Net. It is perfectly working fine in VB but my task is to convert and run in c#. Please assist me where I am lacking.

public void Form1_Load(System.Object eventSender, System.EventArgs eventArgs)
 {
  //   Set up error handler
  try
  {

   //   Initialize globals
   indent = 0;
   fRecoEnabled = false;
   fGrammarLoaded = false;

   //   Create the Shared Reco Context by default
   RC = new SpeechLib.SpSharedRecoContext();
   RC.AudioLevel += new SpeechLib._ISpeechRecoContextEvents_AudioLevelEventHandler(RC_AudioLevel);
   //RC.Bookmark += @;;
   RC.EndStream += new SpeechLib._ISpeechRecoContextEvents_EndStreamEventHandler(RC_EndStream);
   RC.EnginePrivate += new SpeechLib._ISpeechRecoContextEvents_EnginePrivateEventHandler(RC_EnginePrivate);
   RC.FalseRecognition += new SpeechLib._ISpeechRecoContextEvents_FalseRecognitionEventHandler(RC_FalseRecognition);
   RC.Hypothesis += new SpeechLib._ISpeechRecoContextEvents_HypothesisEventHandler(RC_Hypothesis);
   RC.Interference += new SpeechLib._ISpeechRecoContextEvents_InterferenceEventHandler(RC_Interference);
   RC.PhraseStart += new SpeechLib._ISpeechRecoContextEvents_PhraseStartEventHandler(RC_PhraseStart);
   RC.PropertyNumberChange += new SpeechLib._ISpeechRecoContextEvents_PropertyNumberChangeEventHandler(RC_PropertyNumberChange);
   RC.PropertyStringChange += new SpeechLib._ISpeechRecoContextEvents_PropertyStringChangeEventHandler(RC_PropertyStringChange);
   RC.Recognition += new SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler(RC_Recognition);
   RC.RecognitionForOtherContext += new SpeechLib._ISpeechRecoContextEvents_RecognitionForOtherContextEventHandler(RC_RecognitionForOtherContext);
   RC.RecognizerStateChange += new SpeechLib._ISpeechRecoContextEvents_RecognizerStateChangeEventHandler(RC_RecognizerStateChange);
   RC.RequestUI += new SpeechLib._ISpeechRecoContextEvents_RequestUIEventHandler(RC_RequestUI);
   RC.SoundEnd += new SpeechLib._ISpeechRecoContextEvents_SoundEndEventHandler(RC_SoundEnd);
   RC.SoundStart += new SpeechLib._ISpeechRecoContextEvents_SoundStartEventHandler(RC_SoundStart);
   RC.StartStream += new SpeechLib._ISpeechRecoContextEvents_StartStreamEventHandler(RC_StartStream);

   //   Load Speech Recognition Engines combo box
   SpeechLib.ISpeechObjectToken Token;

            foreach (SpeechLib.ISpeechObjectToken tempLoopVar_Token in RC.Recognizer.GetRecognizers("", "").GetEnumerator)
            {
                Token = tempLoopVar_Token;
                SREngines.Items.Add(Token.GetDescription(0));
            }

            //ISpeechObjectToken tempLoopVar_Token =RC.Recognizer.GetRecognizers("","").GetEnumerator(); //Getting the Enumerator
            //tempLoopVar_Token.Reset(); //Position at the Beginning
            //While(tempLoopVar_Token.MoveNext()) //Till not finished do print
            //{
            //Token = tempLoopVar_Token;
            //SREngines.Items.Add(Token.GetDescription(0));}
            //}

   SREngines.SelectedIndex = 0;

   //   Disable combo box for Shared Engine. Also disable other UI that's not initially needed.
   SREngines.Enabled = false;
   ActivateMic.Enabled = false;
   PlayAudio.Enabled = false;

   //   Call the InitEventInterestCheckBoxes subroutine which uses the SR engine
   //   default event interests to initialize the event interest checkboxes.
   InitEventInterestCheckBoxes();

   //   Create grammar objects
   LoadGrammarObj();

   //   Attempt to load the default .xml file and set the RuleId State to Inactive until
   //   the user starts recognition.
   LoadDefaultCnCGrammar();

   return;

  }
  catch
  {
   goto Err_SAPILoad;
  }

Err_SAPILoad: Interaction.MsgBox("Error loading SAPI objects! Please make sure SAPI5.1 is correctly installed.", MsgBoxStyle.Critical, null); Exit_Renamed_Click(Exit_Renamed, new System.EventArgs()); return; }

Orginal code in VB which is working fine.

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    '   Set up error handler
    On Error GoTo Err_SAPILoad

    '   Initialize globals
    indent = 0
    fRecoEnabled = False
    fGrammarLoaded = False

    '   Create the Shared Reco Context by default
    RC = New SpeechLib.SpSharedRecoContext

    '   Load Speech Recognition Engines combo box
    Dim Token As SpeechLib.ISpeechObjectToken
    For Each Token In RC.Recognizer.GetRecognizers
        SREngines.Items.Add(Token.GetDescription())
    Next Token
    SREngines.SelectedIndex = 0

    '   Disable combo box for Shared Engine. Also disable other UI that's not initially needed.
    SREngines.Enabled = False
    ActivateMic.Enabled = False
    PlayAudio.Enabled = False

    '   Call the InitEventInterestCheckBoxes subroutine which uses the SR engine
    '   default event interests to initialize the event interest checkboxes.
    InitEventInterestCheckBoxes()

    '   Create grammar objects
    LoadGrammarObj()

    '   Attempt to load the default .xml file and set the RuleId State to Inactive until
    '   the user starts recognition.
    LoadDefaultCnCGrammar()

    Exit Sub

Err_SAPILoad: MsgBox("Error loading SAPI objects! Please make sure SAPI5.1 is correctly installed.", MsgBoxStyle.Critical) Exit_Renamed_Click(Exit_Renamed, New System.EventArgs()) Exit Sub End Sub