FreeSWITCH 支持調用第三方TTS命令,本身已經搭好了框架,只需要配置即可用。
下面寫一下步驟,以免忘記,也希望給你帶來幫助。
第一步:編譯模塊mod_tts_commandline,並加載。
編輯源碼下 modules.conf 文件,把 asr_tts/mod_tts_commandline 這一行的注釋去掉。
然后 ./configure, make, makeinstall
重啟FreeSWITCH
在CLI界面看到
freeswitch@internal> module_exists mod_tts_commandline true
表示模塊 mod_tts_commandline 加載成功。
第二步:修改配置文件
修改 freeswitch/conf/autoload_configs/tts_commandline.conf.xml
1 <configuration name="tts_commandline.conf" description="TextToSpeech Commandline configuration"> 2 <settings> 3 <!-- 4 Some variables will be replaced : 5 ${text}: input text (quoted) 6 ${rate}: sample rate (example: 8000) 7 ${voice}: voice_name passed to TTS(quoted) 8 ${file}: output file (quoted, including .wav extension) 9 10 Example commands can be found at: 11 http://wiki.freeswitch.org/wiki/Mod_tts_commandline#Example_commands 12 --> 13 <!--param name="command" value="echo ${text} | text2wave -f ${rate} > ${file}"/--> 14 <param name="command" value="sh /tmp/tts_test.sh ${text} ${file}"/> ----這一行是我加的,/tmp/tts_test.sh是轉換的腳本
15 </settings> 16 </configuration>
<param name="command" value="sh /tmp/tts_test.sh ${text} ${file}"/>
----這一行是我加的,/tmp/tts_test.sh是轉換的腳本,核心的TTS命令就寫在這個腳本里面。具體的命令就不寫了,可以支持科大,百度等第三方公司。
2個參數
${text} --- 要轉換的文字,在后面的撥號方案中賦值
${file} --- 轉換后的wav文件名字,全路徑,帶wav后綴,在后面的撥號方案中賦值
第三步:修改撥號方案腳本。
假如你的撥號方案會觸發到lua腳本,然后在lua腳本中加入下面幾行,進行測試:
1 session:answer(); 2 session:setVariable("tts_engine", "tts_commandline"); 3 session:setVariable("tts_voice", "girl"); 4 session:setVariable("file", "/tmp/justtts.wav"); 5 session:execute("speak", "歡迎您使用光大銀行電子銀行業務,查詢余額請按一,修改密碼請按二");
上面的app都比較清晰,不做過多解釋。
第四步:打電話測試
當你聽到聲音 "歡迎您使用光大銀行電子銀行業務,查詢余額請按一,修改密碼請按二" 時,大功告成!
以上只是個人實現,可能還有其他更好的方法,歡迎在下面留言,謝謝。
