Board logo

主題: [教學][Mac OS X]好用又有趣的指令"say" [打印本頁]

發表人: NeoBetas    時間: 2008-9-24 10:54 PM     主題: [教學][Mac OS X]好用又有趣的指令"say"

OS X 中有個指令叫 "say",他可以讓使用者在終端機下命令電腦唸出指定的英文內容,例如你輸入
"say Hello",他就會唸"Hello"。可是,如果你要他唸一段文章,裡面含有各種標點符號,他就會出現錯誤給你看:

CODE:
[Copy to clipboard]
say Porphyrias are a group of inherited or acquired disorders of certain enzymes in the heme biosynthetic pathway (also called porphyrin pathway). They are broadly classified as hepatic porphyrias or erythropoietic porphyrias, based on the site of the overproduction and mainly accumulation of the porphyrins (or their chemical precursors). They manifest with either skin problems or with neurological complications (or occasionally both).


Mac OS X 從 10.3(如果我沒記錯的話)開始,便強化了這個功能,加入了更多參數讓使用者"玩"這個指令。他多了下面這些指令參數:

CODE:
[Copy to clipboard]
say [-v voice] [-o out] [-f in | message]
所以,我們有兩個辦法可以解決上面的問題。

第一種,改用這個指令:

CODE:
[Copy to clipboard]
say "Porphyrias are a group of inherited or acquired disorders of certain enzymes in the heme biosynthetic pathway (also called porphyrin pathway). They are broadly classified as hepatic porphyrias or erythropoietic porphyrias, based on the site of the overproduction and mainly accumulation of the porphyrins (or their chemical precursors). They manifest with either skin problems or with neurological complications (or occasionally both)."
加上引號後他就可以正常的唸。當然,如果只能這樣玩就太遜了,他還可以唸 .txt 文字檔,然後直接輸出成聲音檔!

我們把剛剛那段文字存成 read.txt,放在桌面上(注意,只能是純文字檔,使用 rtf 之類的他還是會照唸,但是他會連你的格式語法代碼一起唸...),使用以下指令:

CODE:
[Copy to clipboard]
say -o ~/Desktop/say.aiff -f ~/Desktop/read.txt
你會發現他停住了!這可不是當機喔,使用 top 指令察看的話會發現他正在耗用大量的 CPU 資源,等一下下桌面上就會出現"say.aiff"這個聲音檔,打開來,會發現是剛剛那段文字的朗讀錄音。而且文章就算要唸十幾分鐘,他還是可以在兩三分中內產生出整個朗讀檔。

我沒有試過產生 MP3 或 AAC ,有興趣的人自己試試吧!我是用 iTunes 再轉成別的格式的。
發表人: froce    時間: 2008-10-20 11:24 PM

linux下是用espeak這個指令...不過不能直接轉其他格式...只能用wav...


引用:
NeoBetas寫到:
OS X 中有個指令叫 "say",他可以讓使用者在終端機下命令電腦唸出指定的英文內容,例如你輸入
"say Hello",他就會唸"Hello"。可是,如果你要他唸一段文章,裡面含有各種標點符號,他就會出現錯誤給你看:

這個是一定的...常用終端機的人就知道為什麼了...
(其實有空格就會有問題了...你會發現他只念第一個字...)

CODE:
[Copy to clipboard]
say Porphyrias\ are\ a\ group\ of\ inherited\ or\ acquired\ disorders\ of\ certain\ enzymes\ in\ the\ heme\ biosynthetic\ pathway\ \(also\ called\ porphyrin\ pathway\)\.
可以試試看這個...
不過應該沒有人會想這樣玩...XD

[froce 在  2008-10-21 12:00 AM 作了最後編輯]




歡迎光臨 TWed2k (http://twed2k.org/) Powered by Discuz! 4.1.0