FreeSwitch中tts_commandline详解

概述

mod_tts_commandline模块,本身没有TTS能力,而是通过调用TTS引擎的命令生成语音文件,tts命令可以配置,最终实现自动TTS语音播放的功能。

tts_commandline通过命令来执行TTS功能,生成一个声音文件,进而播放。

一、工作原理

     mod_tts_commandline模块提供{text},{rate},{voice},{file} 这4个tts相关变量,然后允许你通过这4个变量,去调用第三方tts(调用方式可以是脚本也可以是命令等方式),最终是在tmp目录下生成一个音频文件,freeswitch再通过speak把这个音频文件播放出来。

     从这个流程可以看出,mod_tts_commandline模块调用tts不是直接通过流式的方式得到语音流在freeswitch中播放,而是通过调用tts得到一个音频文件,然后拿着音频文件在freeswitch中播放,相比mrcp来说,耗时会明显有增加,

二、编译安装

   mod_tts_commandline模块在编译freeswitch的时候,默认是不安装的。

(1)编辑源码下 modules.conf 文件

   把 asr_tts/mod_tts_commandline  这一行的注释去掉

asr_tts/mod_tts_commandline

 (2)编译安装命令

./configure

 make

 makeinstall

   

(3)生成如下文件

  • /usr/local/freeswitch/mod/mod_tts_commandline.so
  • /usr/local/freeswitch/mod/mod_tts_commandline.la

(4)重启FreeSWITCH,在CLI界面检查模块是否存在

freeswitch@internal> module_exists mod_tts_commandline

true

  如果为true,说明编译安装成功,表示模块 mod_tts_commandline 加载成功。

三、启动自动装载

     修改配置文件 /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml

    <!-- ASR /TTS -->
    <load module="mod_tts_commandline"/> 

四、配置第三方TTS引擎

1,对接本地text2wave服务

    修改 freeswitch/conf/autoload_configs/tts_commandline.conf.xml

<param name="command" value="echo ${text} | text2wave -f ${rate} > ${file}"/>

   表示tts_commandline引擎在使用text2wave实现语音转换,但是text2wave不支持中文。

  拨号方案验证

<extension name="sbc_out" continue="false">

   <condition field="destination_number" expression="^119(\d+)$">
      <action application="answer" />
      <action application="speak" data="tts_commandline|pico|This is an example of using tts commandline"/>
      <action application="hangup"/>
  </condition>

</extension>

 2、  对接http协议的tts服务

   修改 freeswitch/conf/autoload_configs/tts_commandline.conf.xml

<configuration name="tts_commandline.conf" description="TextToSpeech Commandline configuration">
    <settings>
        <!--
        Some variables will be replaced :
        ${text}: input text (quoted)
        ${rate}: sample rate (example: 8000)
        ${voice}: voice_name passed to TTS(quoted)
        ${file}: output file (quoted, including .wav extension)
        -->

        <!--注掉老text2wave配置-->
        <!--param name="command" value="echo ${text} | text2wave -f ${rate} > ${file}"/-->
        <!--增加tts_test转换脚本-->
        <param name="command" value="/bin/bash /tmp/tts_test.sh ${text} ${file}"/>
     </settings> 
</configuration>

 脚本内容:

#! /bin/bash

content=$1
file=$2
echo $content
echo $file
#wget http://192.168.1.7:8091/?text='just a test' -O /tmp/tts1.wav
wget http://192.168.1.7:8091/?text="$content" -O $file

通过wget命令,使用http协议下载语音文件。

tts机器地址: 192.168.1.7,如果是内部服务器,都在同一个内外,可以不使用wget命令,而是用系统自带的ftp等命令,同步更快。

如果语音合成服务和FS实在同一台机器上,就省去了网络传输的耗时,本地服务直接生成到指定目录即可。

五、验证效果

1,配置拨号方案

<extension name="ttsTest">
<condition field="destination_number" expression="^78921$">
  <!--拨号盘验证-->
  <action application="speak" data="tts_commandline|gril|今天天气不错"/>

  <!--脚本验证-->
  <action application="lua" data="tts_command.lua"/>
</condition>
</extension>

2,lua脚本

session:answer()
session:setVariable("tts_engine", "tts_commandline")
session:setVariable("tts_voice", "girl")
--session:execute("speak", "just test!")
session:execute("speak", "今天天气不错!")

session:answer();
session:setVariable("tts_engine", "tts_commandline");
session:setVariable("tts_voice", "girl");
--指定输出文件路径,绝对路径
session:setVariable("file", "/tmp/justtts.wav");
session:execute("speak", "欢迎您使用光大银行电子银行业务!");

  • 15
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

常生果

喜欢我,请支持我

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值