AMI Script // Text-to-speech help


Theoretically the GUI backup/restore. but I think I saw a post here about some file location issues.

For most curl is the CLI, not difficult, but not quite as straight forward as the likes of flite, text2wave, etc.


How can I add a 1-sec delay after the call is connected & before the audio is played?

	fputs($socket, "Application: Playback\r\n");
	fputs($socket, "Data: ".$playMyFile."\r\n");

Any thought?

(Lorne Gaetz) #23

You are going to have to do what I said way back in post #2, ORIGINATE your call to a local extension context and put the wait in the dialplan before the Flite line.


Or add silence to the beginning of the recording.

Depending on the TTS engine, an SSML tag or simply a few commas can insert a delay in the generated recording - or TTS agnostically prepend recorded silence to the playback file.


I had 3 approaches in mind in order of simplicity.

  1. Add AMI code in my PHP script – assuming there is a code that can add a delay before playing the audio file.
  2. Play a 1-sec blank audio file followed by the actual message audio.
  3. Include a 1 sec silence in each audio recording.

I’m assuming (1) is not possible.

I’ll tried my hand at the 2nd option.

fputs($socket, "Application: Playback\r\n");
fputs($socket, "Data: ".$play1secNoSoundFile."\r\n");
fputs($socket, "Application: Playback\r\n");
fputs($socket, "Data: ".$playMyFile."\r\n");

Not sure why the above did not work. I’m hoping to get the above to work.



Asterisk should concatenate the files for you:

fputs($socket, "Application: Playback\r\n");
fputs($socket, "Data: " . $play1secNoSoundFile . "&" . $playMyFile . "\r\n");

Asterisk’s sound files include silence files, the below should work:

fputs($socket, "Data: silence/1" . "&" . $playMyFile . "\r\n");

Alternatively, you could use sox to concatenate into one combined file beforehand.


This is exactly the solution I was looking for - simple, elegant, least effort & does exactly what I need. You’re my man @jerrm.

Thanks a ton & happy weekend!!

(system) closed #28

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.