Unity接入Nuance语音识别

1 注册链接

https://developer.nuance.com/public/index.php?task=mixregister

2 找到Sandbox Credentials

具体位置在MyCount->Sandbox Credentials

3 找到 Http Interface Applications

里面记录了调用api时需要的数据。

ASR代表语音识别

TTS代表文本转语音

4 接入API


private void GetASR()

{

    string url = StringUtils.GetStringBuilderFromPool().AppendFormat("{0}?{1}={2}&{3}={4}&{5}={6}",

                                        api,

                                       "appId", app_id,

                                       "appKey", app_key,

                                       "id", SystemInfo.deviceUniqueIdentifier).ToString();

    Uri tokenUri = new Uri(url);

    HTTPRequest httpRequestToken = new HTTPRequest(tokenUri,HTTPMethods.Post ,OnRequestASRFinished);

    httpRequestToken.AddHeader(ASRConst.ContentTypeKey, "audio/x-wav;codec=pcm;bit=16;rate=8000");

    httpRequestToken.AddHeader("Accept", "text/plain");

    httpRequestToken.AddHeader("Accept-Language", "cmn-CHN");

    httpRequestToken.AddHeader("Accept", "text/plain");

    httpRequestToken.AddHeader("Accept-Topic", "Dictation");

    httpRequestToken.AddHeader("X-Dictation-NBestListSize", "10");

    byte[] audio = record.AudioClipToBytes();

    httpRequestToken.AddHeader("Content-Length", audio.Length.ToString());

    httpRequestToken.RawData = audio;

    httpRequestToken.Send();

}

对应的字段说明可以参考https://developer.nuance.com/public/Help/HttpInterface/HTTP_web_services_for_NCS_clients_1.0_programmer_s_guide.pdf

你可能感兴趣的:(Unity接入Nuance语音识别)