R Windows 版 + ITRI 文字語音服務: Text to Speech

以下範例程式,使用 ITRI (台灣工研院語音服務) API,讓 R 達成簡單的 Text to Speech 功能

輔助軟體:Windows command line WAV player: sWavPlayer.exe

請至以下網址下載,解壓縮後,放在某個特定資料夾,例如: d:\voice\sWavPlayer.exe

http://www.dcmembers.com/skwire/download/swavplayer/

R : 需安裝 Rtts 與 sound 套件

Code:

library(Rtts)
library(sound)
setWavPlayer("d:/voice/sWavPlayer.exe")

t1 = "今天要去看電影"
t2 = iconv(t1,"CP950","UTF-8")
tmp_file = tempfile(fileext = ".wav")
tts_ITRI(t2,speaker="Theresa",destfile=tmp_file)
play(tmp_file)
unlink(tmp_file)

註:

可選擇的 speaker 有以下名字,預設為 “Bruce”

[1] English & Chinese: “Bruce”, “Theresa”, “Angela”, “MCHEN_Bruce”, “MCHEN_Joddess”;

[2] Only English: “ENG_Bob”, “ENG_Alice”, “ENG_Tracy”.