delphi调用百度语音识别REST API
delphi调用百度语音识别REST API
-20160616
-感谢 魔术猫 和 DelphiTeacher 兄的帮助解决了返回中文乱码的问题!
-注:语音的录音格式目前只支持评测8k/16k采样率16bit位深的单声道语音
压缩格式支持:pcm(不压缩)、wav、opus、speex、amr、x-flac
var sUrl, sLan, cuid, apiKey, secretKey, token, sR: string;
response: TStringStream; Stream: TFileStream;
begin
//
sR := '';
sLan := 'zh';//en zh //x-flac
idHttp.Request.ContentType := 'audio/amr;rate=16000';
cuid := '392681';
apiKey:= 'vAH45xSaEVxluk5ruwUm4R1Y';
secretKey := 'ogecx9OiBaovyLcYWk1iOTcE9bBWEjAs';
//下面这个token有效期1个月,过期后需要自己到http://yuyin.baidu.com/asr免费注册申请
token := '25.e1bd734e752b559f3c710cd5cfa9c8ff.315360000.1781361290.282335-392681';
Stream := TFileStream.Create('e:\test0.amr', fmShareDenyNone);
Stream.Position := 0;
sUrl := 'http://vop.baidu.com/server_api?lan='+sLan+'&cuid=fireboxsoftsmartai&token='+token;
response := TStringStream.create('', tencoding.utf8);
idHttp.Post(sUrl, stream, response);
ShowMessage(response.DataString);
end;
百度API网址https://cloud.baidu.com/doc/SPEECH/s/Sk38lxokz