Exemple #1
0
        static void test5()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            SipCall      caller = new SipCall(x);
            ApiErrorCode res    = caller.MakeCall("sip:[email protected]", null, null, null, DEFAULT_TIMEOUT);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall err:" + res);
            }

            MrcpSession recog =
                new MrcpSession(x);;

            recog.Allocate(MrcpResource.RECOGNIZER, caller.RemoteOffer(), DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate err:" + res);
            }

            caller.Answer(recog.RemoteOffer(MrcpResource.RECOGNIZER), null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate err:" + res);
            }



            MrcpSession synth = new MrcpSession(x);

            synth.Allocate(MrcpResource.SYNTHESIZER, caller.RemoteOffer(), DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate(SYNTHESIZER) err:" + res);
            }


            Thread.Sleep(1000);
            synth.SimpleSpeak(null, "Please choose red pill, or blue pill", true);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Speak err:" + res);
            }


            String pillgrammar = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!-- the default grammar language is US English -->
<grammar xmlns=""http://www.w3.org/2001/06/grammar""
         xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
         xml:lang=""en-US"" version=""1.0"" root=""pill"">
  <rule id=""pill"">
    <one-of>
      <item>red</item>
      <item>blue</item>
    </one-of> 
  </rule> 
</grammar>";

            Dictionary <String, Object> p =
                new Dictionary <String, Object>();

            p["cancel_if_queue"]       = true;
            p["content_id"]            = "<*****@*****.**>";
            p["content_type"]          = "application/srgs+xml";
            p["no_input_timeout"]      = 20000;
            p["confidence_threshhold"] = 0.9;
            p["start_input_timers"]    = true;



            String answer;

            res = recog.Recognize(
                p,
                pillgrammar,
                DEFAULT_TIMEOUT * 10000,
                true,
                out answer);


            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Speak err:" + res);
            }


            Console.Out.WriteLine(answer);

            caller.WaitTillHangup();
        }