DELPHI实现百度开放平台

时间:2022-04-16 10:47:56

学习百度语音

百度语音开发平台
http://yuyin.baidu.com/

百度开发者账号
13600514494,短信登录

应用账号
词语听写
App ID: 7799366

API Key: U27QualnUfDPfRoksgjTM64i

Secret Key: d6625d0954799afb4bfc6c5faef50391

--获取tok
http://yuyin.baidu.com/docs/tts/135#获取 Access Token
https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=U27QualnxxxxRoksgjTM64i&client_secret=d662xxxx54799afb4bfc6c5faef50391

--语音
http://yuyin.baidu.com/docs/tts/136

http://tsn.baidu.com/text2audio?tex=测试&lan=zh&cuid=18-03-73-E9-8E-95&ctp=1&tok=24.dde01e15xxxxf3f7a97456b4bb06c1d7.2592000.1459131273.282335-7799366

-----
如何使用delphi的rest控件
http://blog.csdn.net/sunylat/article/details/46399987

RESTRequest1.Execute;以后,RESTResponse1会返回Content是文本的,RawBytes是内存块

procedure TForm2.Button1Click(Sender: TObject);
var
//  JO, JData: TJSONObject;
  code: string;
  temp: string;

  fileName: string;

  b: TBytesStream;
begin
  //RESTClient1.BaseURL := 'http://ip.taobao.com//service/getIpInfo.php?ip=202.103.24.68';
  RESTClient1.BaseURL := 'http://tsn.baidu.com/text2audio?tex='+Edit1.Text+'&lan=zh&cuid=18-03-73-E9-8E-95&ctp=1&tok=24.dde01e152fa3f3f7a97456b4bb06c1d7.2592000.1459xxxx73.282335-7799366';
  RESTRequest1.Execute;
// 清理先前数据
  Memo1.Lines.Clear;

  Memo1.Lines.Add('请求时间:' + Formatdatetime('yyyy-mm-dd hh:mm:ss zzz', now)
    + #13#10);

  // 在memo中显示得到数据
  temp := temp + '原始数据:' + #13#10;
//  temp := temp + RESTResponse1.Content + #13#10;

//  Memo1.Lines.Add(temp);

  fileName := TPath.GetHomePath() + TPath.DirectorySeparatorChar + 'aa.wav';
  Memo1.Lines.Add(fileName);
  MediaPlayer1.Clear;
  //先将内存快储存到文件
  try
    b := TBytesStream.Create(RESTResponse1.RawBytes);

    b.SaveToFile(fileName);

  finally
    FreeAndNil(b);
  end;

  MediaPlayer1.FileName :=fileName;
  MediaPlayer1.Play;
//  MediaPlayer1.Clear;
end;