How to use .net to develop the speech recognition function of Wechat public platform
This article mainly introduces how to use .net to develop Wechat public platform voice recognition function, the article is very detailed, has a certain reference value, interested friends must read it!
Voice recognition is an advanced function and can only be realized after Wechat's real name verification. The authentication fee is 300 yuan / year. If you, as a developer, can apply for a test account, it is also possible. First create a Wechat message class, this analogy has an additional attribute.
Class wxmessage {public string FromUserName {get; set;} public string ToUserName {get; set;} public string MsgType {get; set;} public string EventName {get; set;} public string Content {get; set;} public string Recognition {get; set;} public string EventKey {get; set;}}
Speech recognition is a built-in feature of Wechat, which is very powerful and does not require us to do too much:
Protected void Page_Load (object sender, EventArgs e) {wxmessage wx = GetWxMessage (); string res = ""; if (! string.IsNullOrEmpty (wx.EventName) & & wx.EventName.Trim () = "subscribe") {/ / the welcome word string content = "; content =" /: rose welcomes Beijing Yongjie Youxin Technology Co., Ltd. /: rose\ nreply "Hello" directly. Res = sendTextMessage (wx, content);} else {if (wx.MsgType = = "text" & & wx.Content = = "Hello") {res = sendTextMessage (wx, "Hello, welcome to the public Wechat platform of Beijing Yongjie Youxin Technology Co., Ltd.") } else if (wx.MsgType = = "voice") / / recognize that the message type is speech {res = sendTextMessage (wx, wx.Recognition); / / wx.Recognition is the result of speech recognition. We quote it directly and OK it with text feedback} else {res = sendTextMessage (wx, "Hello, failed to recognize the message!") } Response.Write (res);} private wxmessage GetWxMessage () {wxmessage wx = new wxmessage (); StreamReader str = new StreamReader (Request.InputStream, System.Text.Encoding.UTF8); XmlDocument xml = new XmlDocument (); xml.Load (str); wx.ToUserName = xml.SelectSingleNode ("xml"). SelectSingleNode ("ToUserName"). InnerText; wx.FromUserName = xml.SelectSingleNode ("xml"). SelectSingleNode ("FromUserName"). InnerText Wx.MsgType = xml.SelectSingleNode ("xml"). SelectSingleNode ("MsgType"). InnerText; if (wx.MsgType.Trim () = = "text") {wx.Content = xml.SelectSingleNode ("xml"). SelectSingleNode ("Content"). InnerText;} if (wx.MsgType.Trim () = = "event") {wx.EventName = xml.SelectSingleNode ("xml"). SelectSingleNode ("Event"). InnerText } if (wx.MsgType.Trim () = = "voice") / / if it is a voice message, assign the recognition result to the corresponding attribute Recognition {wx.Recognition = xml.SelectSingleNode ("xml"). SelectSingleNode ("Recognition"). InnerText;} return wx of the entity class. } / send text messages / content / private string sendTextMessage (wxmessage wx, string content) {string res = string.Format (@ ", wx.FromUserName, wx.ToUserName, DateTime.Now, content); return res } the above is all the contents of the article "how to use .net to develop the speech recognition function of Wechat public platform". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!