之前有过需求要是语音识别,而百度也提供了对应的.dll文件,后来用了一下在识别的时候占用了主线程,会卡顿,又看了看大佬的解决方案,自己也总结了一下。
总共分为四大部:1获取Token、2开始录音、3录音结束、4上传百度进行识别。
采用上传Put json的方法,返回得到json,再去解析。
using System;
using System.Collections;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class ToWord : MonoBehaviour
{
private string token = ""; //access_token
private string cuid = "11"; //用户唯一标识
private string format = "pcm"; //语音格式
private int dev_pid = 1536;//语言设置
private int rate = 16000; //采样率
private int channel = 1; //声道数
private string speech; //语音数据,进行base64编码
private int len; //原始语音长度
private const string grant_Type = "client_credentials";//固定值
private const string API_KEY = "你的API Key"; //百度appkey
private const string SECRET_KEY = "你的Secret Key"; //百度Secret Key
private const