你的位置:首页 > 软件开发 > ASP.net > 微软牛津计划

微软牛津计划

发布时间:2016-03-28 17:02:16
官方演示地址:https://www.azure.cn/projectoxford/demo/speech#recognition参考资料:https://msdn.microsoft.com/en-us/library/mt422983.aspx 1、需要先从官方申请订阅k ...

官方演示地址:

https://www.azure.cn/projectoxford/demo/speech#recognition

参考资料:https://msdn.microsoft.com/en-us/library/mt422983.aspx

 

1、需要先从官方申请订阅key,

https://www.azure.cn/projectoxford/subscription

注册后会申请到主密钥,从密钥2个,都需要记住。

 

 

2、语音转文本核心代码rest api:https://oxfordportal.blob.core.get='_blank'>windows.net/speech/doc/recognition/Program.cs

/**Copyright (c) Microsoft CorporationAll rights reserved. MIT LicensePermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**/using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Net;using System.IO;using System.Runtime.Serialization.Json;using System.Runtime.Serialization;using System.Web;using System.ServiceModel.Channels;using System.ServiceModel;using System.Threading;namespace SpeechSample{  [DataContract]  public class AccessTokenInfo  {    [DataMember]    public string access_token { get; set; }    [DataMember]    public string token_type { get; set; }    [DataMember]    public string expires_in { get; set; }    [DataMember]    public string scope { get; set; }  }  /*   * This class demonstrates how to get a valid O-auth token.   */  public class Authentication  {    public static readonly string AccessUri = "https://oxford-speech.cloudapp.net/token/issueToken";    private string clientId;    private string clientSecret;    private string request;    private AccessTokenInfo token;    private Timer accessTokenRenewer;    //Access token expires every 10 minutes. Renew it every 9 minutes only.    private const int RefreshTokenDuration = 9;    public Authentication(string clientId, string clientSecret)    {      this.clientId = clientId;      this.clientSecret = clientSecret;      /*       * If clientid or client secret has special characters, encode before sending request       */      this.request = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope={2}",                     HttpUtility.UrlEncode(clientId),                     HttpUtility.UrlEncode(clientSecret),                     HttpUtility.UrlEncode("https://speech.platform.bing.com"));      this.token = HttpPost(AccessUri, this.request);      // renew the token every specfied minutes      accessTokenRenewer = new Timer(new TimerCallback(OnTokenExpiredCallback),                      this,                      TimeSpan.FromMinutes(RefreshTokenDuration),                      TimeSpan.FromMilliseconds(-1));    }    public AccessTokenInfo GetAccessToken()    {      return this.token;    }    private void RenewAccessToken()    {      AccessTokenInfo newAccessToken = HttpPost(AccessUri, this.request);      //swap the new token with old one      //Note: the swap is thread unsafe      this.token = newAccessToken;      Console.WriteLine(string.Format("Renewed token for user: {0} is: {1}",               this.clientId,               this.token.access_token));    }    private void OnTokenExpiredCallback(object stateInfo)    {      try      {        RenewAccessToken();      }      catch (Exception ex)      {        Console.WriteLine(string.Format("Failed renewing access token. Details: {0}", ex.Message));      }      finally      {        try        {          accessTokenRenewer.Change(TimeSpan.FromMinutes(RefreshTokenDuration), TimeSpan.FromMilliseconds(-1));        }        catch (Exception ex)        {          Console.WriteLine(string.Format("Failed to reschedule the timer to renew access token. Details: {0}", ex.Message));        }      }    }    private AccessTokenInfo HttpPost(string accessUri, string requestDetails)    {      //Prepare OAuth request       WebRequest webRequest = WebRequest.Create(accessUri);      webRequest.ContentType = "application/x-www-form-urlencoded";      webRequest.Method = "POST";      byte[] bytes = Encoding.ASCII.GetBytes(requestDetails);      webRequest.ContentLength = bytes.Length;      using (Stream outputStream = webRequest.GetRequestStream())      {        outputStream.Write(bytes, 0, bytes.Length);      }      using (WebResponse webResponse = webRequest.GetResponse())      {        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AccessTokenInfo));        //Get deserialized object from JSON stream        AccessTokenInfo token = (AccessTokenInfo)serializer.ReadObject(webResponse.GetResponseStream());        return token;      }    }  }  /*   * This sample program shows how to send an speech recognition request to the   * Microsoft Speech service.      */  class Program  {    static void Main(string[] args)    {

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:微软牛津计划

关键词:微软

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。