File string

From FreeSWITCH Wiki
Jump to: navigation, search



file_string is a useful way of specifying multiple sound files to be played or written sequentially. It is a convenience feature.

file_string is implemented by mod_dptools


The idea behind file_string is simple: when you have multiple sound files to play sequentially, especially when there are many of them, it is convenient to be able to specify all of those files before initiating the playback. In write mode if writing fails, next try are made to the next file in the list

There are two methods of using file_string:

  • high level, core most functions that use switch_ivr_playback()
  • low level, code that uses direct file handles

You can set up to 128 files in the list.


The high level method works like this:

  <!-- Delimiter is set by a var which also enables the parser -->
  <action application="set" data="playback_delimiter=!"/>
  <action application="set" data="playback_sleep_val=500"/>
  <action application="playback" data="/ram/sr8k.wav!/ram/swimp.wav"/> 

The low level method works this way:

  <!-- Delimiter is always ! char -->
  <action application="playback" data="file_string:///ram/sr8k.wav!/ram/swimp.wav"/> 

You may also use this for on hold music:

 <action application="set" data="hold_music=file_string://sounds/holdmusic1.wav!sounds/yourcallisimportant.wav" />

You can also use it for play_and_get_digits:

 <action application="play_and_get_digits" data="7 7 3 30000 # file_string://${sound_prefix}/voicemail/8000/vm-hello.wav!${sound_prefix}/conference/8000/conf-pin.wav /invalid.wav ivrsel \d+"/>

Record session failover. If writing fails, it tries the next file:

 <action application="record_session" data="file_string://${record_dir}/${record_filename}!${backup_record_dir}/${record_filename}"/>

Note that you have to specify the full path, as sound path expansion is done in switch_ivr_play_file, which is above the level that the file_string:// protocol operates at.

Execution Parameters

There is a "timeout=" parameter expressed in milliseconds that limits the duration of the file played. This is useful for testing new moh, prompts, etc. audio levels It also allows for more flexible concatenated audio files.

Timeout Example

In this example, an extension is made that plays all listed files as follows:

  1. Announce a number to easily identify the file in the list.
  2. Play the file for 15 seconds. This is long enough to hear the song and take notes if needed.

An answer is required to prevent the call from timing out so any number of files can be played in a single call.

   <extension name="testsounds">
     <condition field="destination_number" expression="^8787$">
       <action application="answer"/>
       <action application="say" data="en number pronounced 1"/>
       <action application="playback" data="{timeout=15000}file_string://${sound_dir}/music/8000/music1.wav"/>
       <action application="say" data="en number pronounced 2"/>
       <action application="playback" data="{timeout=15000}file_string://${sound_dir}/music/8000/music2.wav"/>
       <action application="say" data="en number pronounced 3"/>
       <action application="playback" data="{timeout=15000}file_string://${sound_dir}/music/8000/music3.wav"/>
       <action application="hangup"/>

Without the timeout, you would have to listen to entire files.