DELPHI實現百度開放平臺

學習百度語音php

百度語音開發平臺
http://yuyin.baidu.com/api

百度開發者帳號
13600514494,短信登陸學習


應用帳號
詞語聽寫
App ID: 7799366測試

API Key: U27QualnUfDPfRoksgjTM64iui

Secret Key: d6625d0954799afb4bfc6c5faef50391.net


--獲取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=d662xxxx54799afb4bfc6c5faef50391rest


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

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


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

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;

相關文章
相關標籤/搜索