程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php調用Google translate_tts api實現代碼

php調用Google translate_tts api實現代碼

編輯:關於PHP編程

今天用google翻譯時,發現個好東西:Google translate_tts,調用這個api就可以聽到英文發音,
省掉了自己上傳音頻文件的麻煩。
我用php寫了個調用的方法,可以把音頻文件保存在本地。
如下:
復制代碼 代碼如下:
$newfname = '1.wmv';
$reqBaseURL = 'http://translate.google.com/translate_tts?tl=en&q=how%20do%20you%20do';
$remote_file = fopen($reqBaseURL, "rb");
if ($remote_file){
 $newf = fopen($newfname, "wb");
 if ($newf){
  while(!feof($remote_file)){
   fwrite($newf, fread($remote_file, 1024 * 8),1024 * 8);
  }
 }
}
if ($remote_file) {
 fclose($remote_file);
}
if ($newf) {
 fclose($newf);
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved