Exemplo n.º 1
0
        }//信息来源是腾讯才会返回true

        private void task_voicemanager()
        {
            try
            {
                string path = @"C:\Users\Administrator\Desktop\ElearnOralResult\" + WechatRequest.FromUserName;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                WeChatHttpHelper.GetToken();
                var bytelist = WeChatHttpHelper.DownloadMedia(WechatRequest.MediaId);
                using (FileStream fs = new FileStream(path + @"\0.amr", FileMode.Create, FileAccess.Write))
                {
                    foreach (var abyte in bytelist)
                    {
                        fs.WriteByte(abyte);
                    }
                    fs.Flush();
                }
                ISEServerAgent.ConvertVideo(path + @"\0.amr");
                using (FileStream fs = new FileStream(path + @"\0.wav", FileMode.Open, FileAccess.Read))
                    using (ISEServerAgent agent = new ISEServerAgent())
                    {
                        agent.Login(System.Web.Configuration.WebConfigurationManager.AppSettings["iflytekKey"]);
                        if (agent.errorCode != (int)ErrorCode.MSP_SUCCESS)
                        {
                            WechatRequest.Save_log("\r\n" + agent.errorCode);
                            return;
                        }
                        agent.TextPut("[content]\r\nIt was two weeks before the Spring Festival.\r\n");
                        agent.AudioWrite(fs);
                        agent.GetAndSaveRemark(path + "\\result.txt");
                    }
            }
            catch (Exception e)
            {
                WechatRequest.Save_log(e.ToString());
            }
        }