SpeechResult的Twilio语音识别问题

时间:2018-10-05 04:22:05

标签: c# twilio speech-recognition

我有这个项目,我需要在Twilio中拨打我的一个电话,说点什么,在用户用他的声音播放音频后,我已经“拥有”了代码,但是SpeechResult和UnstableSpeechResults总是为空。这是我的代码:

[HttpPost]
    public ActionResult ReceiveCall()
    {
        var response = new VoiceResponse();

        var gather = new Gather(input: new List<Gather.InputEnum> { Gather.InputEnum.Speech }, 
            action: new Uri("http://eb4cdc87.ngrok.io/Voice/GatherProcess"), 
            speechTimeout: "5",
            method: HttpMethod.Post,
            partialResultCallback: new Uri("http://eb4cdc87.ngrok.io/Voice/WriteVoice") , 
            partialResultCallbackMethod: HttpMethod.Post);
        gather.Say("Say Something to record and after press pound");
        gather.Pause(5);
        gather.Play(new Uri("https://corn-collie-1715.twil.io/assets/demo.mp3"));
        response.Append(gather);

        return TwiML(response);
    }

    [HttpPost]
    public void GatherProcess()
    {
        var response = new VoiceResponse();
        var gather = new Gather(input: new List<Gather.InputEnum> { Gather.InputEnum.Speech, Gather.InputEnum.Dtmf });//(input: "speech dtmf", timeout: 3, numDigits: 1);  
        gather.Say("You say this: " + Request.QueryString["SpeechResult"].ToString());
        gather.Pause(5);
        gather.Play(new Uri("https://corn-collie-1715.twil.io/assets/demo.mp3"));
        response.Append(gather);

    }

    [HttpPost]
    public void WriteVoice()
    {
        var speech = Request.QueryString["UnstableSpeechResult"].ToString();
        if (!String.IsNullOrEmpty(speech))
        {
            System.IO.File.AppendAllText(Server.MapPath(Path.Combine("~/Content/", "Voice.txt")), "You entered: " + speech + "\n");
        }


    }

我真的很需要帮助,我知道我缺少什么,但是我不知道这是什么,我从twilio开始,所以我没有太多经验。

谢谢

1 个答案:

答案 0 :(得分:0)

终于可以了!

解决方案是使用Request [“ SpeechResult”]而不是Request.QueryString [“ SpeechResult”]。

谢谢