我在unity中使用C#发送API请求识别语音转文字,使用了示例里的声音test.pcm结果输出为:
{"err_msg":"parameters error.","err_no":3300,"sn":""}
我多次对比了示例和文档都没有发现有哪个参数有错误,请知道的朋友指导一下,具体代码如下:
public IEnumerator SpeechRecognitionFunction(string wavStream)
{
WWWForm form = new WWWForm();
form.AddField("format", "pcm");
form.AddField("rate", 8000);
form.AddField("channel", "1");
form.AddField("token", access_token);
form.AddField("cuid", "Baidu_VrWorld12344");
form.AddField("lan", "zh"); // 选择语言 zh中文 ct粤语 en 英文
var filepath = Path.Combine(Application.streamingAssetsPath, "SpeechRecognition/test.pcm");
System.IO.FileStream fs = System.IO.File.OpenRead(filepath);//传文件的路径即可
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
byte[] bt = br.ReadBytes(System.Convert.ToInt32(fs.Length));
string base64String = System.Convert.ToBase64String(bt);
form.headers["Content-Type"] = "application/json";
form.AddField("len", (int)fs.Length);
form.AddField("speech", base64String);
Dictionary dict = new Dictionary ();
WWW www = new WWW(serverURL, form);
yield return www;
fWaitProgress = www.progress;
br.Close();
fs.Close();
if (www.error != null)
{
//POST请求失败
strResult = "error :" + www.error;
}
else
{
//POST请求成功
speechTxt = www.text;
print ("~speechTxt:"+speechTxt);
}
}
s不知是错s:
回复汉尼拔e巴卡:哥哥,怎么解决的啊
回复s不知是错s:请检查一下参数,3300错误都是参数问题导致。
汉尼拔e巴卡:
已经成功解决
回复汉尼拔e巴卡:哥哥,怎么解决的啊
已经成功解决
{"err_msg":"parameters error.","err_no":3300,"sn":""}
App ID: 7886160
API Key: b0CEl0DUXS7NN5G381kTief7
Secret Key: 16bb7c8851aa6826c7094377f06168a2
请提供下sn