顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2014年5月13日 星期二

PHP 文字轉語音(Text To Speech,TTS) Google Translation 下載成mp3檔案

      今天終於解決困擾我整個下午的程式問題,語音轉文字(TTS)問題,問題如標題所說,我想把這個網址(http://translate.google.com/translate_tts?tl=zh_TW&q=你好 )存成mp3檔案,但你如果是使用這個網址(http://translate.google.com/translate_tts?tl=en&q=hello), 透過php 的file_get_contents(url網址)函數下載是可行,而使用繁體中文就不行(會出現錯誤的語音),一開始想說是編碼上出了錯誤,但是不管我怎麼試(轉UTF-8、big5、UTF-16)都還是不行,最後我終於爬到我要的資料~原因出在少了一個query參數ie=utf-8。
程式碼如下:
<?php
 //http get query參數設定 tl設定國家語言(ex:en、zh_TW)  q設定要語音的 內容
$qs = http_build_query(array("ie" => "utf-8","tl" => 'zh_TW', "q" => '你好'));
$ctx = stream_context_create(array("http"=>array("method"=>"GET","header"=>"Referer: \r\n")));
$soundfile = file_get_contents("http://translate.google.com/translate_tts?".$qs, false, $ctx);
  //設定檔頭為影音檔
header("Content-type: audio/mpeg");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
 
echo($soundfile);
?>

2013年3月19日 星期二

Yii Framework初學

英文官網
http://www.yiiframework.com/
中文官網(簡體)
http://www.yiichina.com/

可惜沒有繁體網頁~~

Yii Framework 是一個不錯的PHP MVC架構的框架~
以下是簡體教程~
http://www.yiichina.com/forum/topic/4786/

2012年12月27日 星期四

PHP update


1.    Stop WAMP server.
2.    Go to windows.php.net and download the the latests ZIPPED package for php5.3.4.
Make sure it is the VC6 Thread Safe build. DO NOT DOWNLOAD THE INSTALLER.
3.  Create a folder php5.3.4 into wamp/bin/php
4.  Extract the downloaded zip to the newly created php5.3.4 folder
5.  Copy the files:
-  php.ini
-  phpForApache.ini
-   wampserver.conf
from your existing php5.3 (eg.   wamp/bin/php/php5.3.3) folder to the new php5.3.4 folder.
6.  Open the files:
-   php.ini
-  phpForApache.ini
and search/replace the string 5.3.3 with 5.3.4
7.   Go to wamp/bin/apache/apache/apache2.2.11/bin and delete the file called php.ini
8.   Restart WAMP server.
9.   Choose php version 5.3.0
10.   Restart WAMP server.
11.   Now choose php version 5.3.4 .
12.   Check if PEAR path is correct in php.ini , and modify accordingly.
13.   Restart WAMP server.
14.   Enjoy.
This entry was posted in Best Practice,

http://www.wretch.cc/blog/magurayu/22873352  HTTP TRACE / TRACK Methods Allowed 解決辦法