调用百度接口进行识别:Asr.cs
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
namespace Wit.BaiduAip.Speech
{
[Serializable]
public class AsrResponse
{
public int err_no;
public string err_msg;
public string sn;
public string[] result;
}
public class Asr : Base
{
private const string UrlAsr = "https://vop.baidu.com/server_api";
public Asr(string apiKey, string secretKey) : base(apiKey, secretKey)
{
}
public IEnumerator Recognize(byte[] data, Action<AsrResponse> callback)
{
yield return PreAction ();
if (tokenFetchStatus == Base.TokenFetchStatus.Failed) {
Debug.LogError("Token fetched failed, please check your APIKey and SecretKey");
yield break;
}
var uri = string.Format("{0}?lan=zh&cuid={1}&token={2}", UrlAsr, SystemInfo.deviceUniqueIdentifier, Token);
var form = new WWWForm();
form.AddBinaryData("audio", data);
var www = UnityWebRequest.Post(uri, form);
www.SetRequestHeader("Content-Type", "audio/pcm;rate=16000");
yield return www.SendWebRequest();
if (string.IsNullOrEmpty(www.error))
{
&nbs