代码如下:
public IEnumerator SpeechRecognitionFunction(string wavStream)
{
WWWForm form = new WWWForm();
Dictionary headers_m = form.headers;
Debug.Log(headers_m["Content-Type"]);
headers_m["Content-Type"] = "application/json";
Debug.Log(headers_m["Content-Type"]);
form.AddField("format", "wav");
form.AddField("rate", 16000);
form.AddField("channel", 1);
form.AddField("cuid", cuid);
form.AddField("token", "24.2ec95bb2717f4432cb8f8c8097903fb8.2592000.1480566308.282335-8811480");
form.AddField("lan", "en");
string filepath = Application.persistentDataPath + "/123.wav";
FileStream fs = new FileStream(filepath, FileMode.Open);
byte[] voice = new byte[fs.Length];
fs.Read(voice, 0, voice.Length);
fs.Close();
fs.Dispose();
string base64String = Convert.ToBase64String(voice);
form.AddField("len", voice.Length);
form.AddField("speech", base64String);
byte[] rawData = form.data;
Debug.Log(rawData.Length);
//WWW www = new WWW(wavStream, form);
WWW www_m = new WWW(wavStream, rawData, headers_m);
yield return www_m;
result_2 = www_m.text;
result_m = www_m.text;
}
之前看社区返回值是3300其中Sn为空的话说明Content-Type的问题,然而修改成"application/json"后依然返回3300,求助到底是怎么回事
需要把整个参数体进行json打包,然后header里面写application/json.
呃...Up