[Freeswitch-dev] Cepstral locks up

Tom Parrott tomp at tomp.co.uk
Fri Nov 11 20:10:23 MSK 2011


Hi,

I am happy to, although I'm sure it can be improved as this is my first
lua script. Although its in production now and working like a charm. :)

First, I created a phrase macro for requesting TTS, and then call the LUA
script from there:

  <!--Provides a phase to speak custom text-->
  <macro name="tts">
    <input pattern="(.*)">
      <match>
        <action function="execute" data="lua(tts_cache.lua '$1')"/>
        <action function="play-file" data="${tts_file}" />
      </match>
    </input>
  </macro>

Then this is the tts_cache.lua script:

-- This script generates a wav file of the sentence passed in to it.
-- It uses the Cepstral swift command to perform text-to-speech conversion.
-- If the wav file already exists for this sentence, then it is not
generated.
-- Author: Thomas Parrott <thomas.parrott at infinity-tracking.com>
api         = freeswitch.API();
msg         = argv[1];
msgMd5      = api:execute( "md5", msg );
filename    = '/var/lib/tts_cache/' .. msgMd5 .. '.wav';
cmd         = '/opt/swift/bin/swift';

-- Set a channel variable so that we know which file to play back.
session:setVariable( 'tts_file', filename );

-- Check whether the file already exists.
file, errMsg = io.open( filename, "r" )
if not file then
api:execute( 'system', cmd .. ' -o "' .. filename .. '" "' .. msg .. '"' );
end

If I can have a branch into contrib I'll post it up there.

Thanks
Tom

> On 11/11/2011 01:00 AM, Tom Parrott wrote:
> [snip]
>> Let me know if you would like to see the script.
>
> Good to see you found a solution. If you don't mind sharing your script
> with the Community perhaps you could ask one of the developers to put it
> somewhere in contrib/ or give you access to your own branch in contrib/.
>
> Regards,
> Patrick
>
>
>





Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-dev mailing list