#, #FreePBX Asterisk, # ? Telegram!

(BioDamage)

, Asterisk. IVR . . :

  1. ;
  2. , - , Asterisk;

. API - . ( API - Yandex.SpeechKit):

:)


!

/var/lib/asterisk/tts/ . , , MD5 . :

mkdir /var/lib/asterisk/tts/
chown asterisk:asterisk /var/lib/asterisk/tts/
chmod 775 /var/lib/asterisk/tts/

IP Asterisk, . .

AGI . , :

#!/usr/bin/php -q
<?php
error_reporting(0); //  , ,   c  

require('phpagi.php'); 
$agi = new AGI();
$str = $agi->request['agi_arg_1']; //   ,   
$str = iconv('cp1251', 'utf-8', $str); //    
$md5 = md5($str); // md5 -    $str
$prefix = '/var/lib/asterisk/sounds/ru/custom/'; //   .      
$filename = $prefix.$md5; //  (   md5 )
$format = 'wav'; //     
$quality = 'hi'; // 

$speaker = 'oksana'; // .       : jane, oksana, alyss  omazh   : zahar  ermil.
$emotion = 'evil'; //   , good  , , evil  , neutral   (  ).   :)
$speed = '0.9'; //      () ,     ,    
$key = '_'; // ,    .

if (!file_exists($filename.'.wav')) {

$qs = http_build_query(array("format" => $format,"quality" => $quality,"lang" => "ru-RU","speaker" => $speaker,"speed" => $speed,"key" => $key,"emotion" => $emotion, "text" => $str)); //  
$ctx = stream_context_create(array("http"=>array("method"=>"GET","header"=>"Referer: \r\n")));
$soundfile = file_get_contents("https://tts.voicetech.yandex.net/generate?".$qs, false, $ctx); // 
$file = fopen("file1.wav", "w"); //    
fwrite($file, $soundfile); //    
fclose($file); // 
shell_exec('sox -t raw -r 48k -e signed-integer -b 16 -c 1 file1.wav -t wav -r 8k -c 1 '.$filename.'.wav'); //    Asterisk      
shell_exec('chown asterisk:asterisk '.$filename.'.wav');
shell_exec('chmod 775 '.$filename.'.wav'); //    ;
shell_exec('rm -f file1.wav'); //   ,       API; 
shell_exec('echo '.$str.' > /var/lib/asterisk/tts/'.$md5.'.txt'); //   ;-)      .
}
$agi->exec('Playback',"custom/$md5"); //  .
?>
, .php

texttospeech.php /var/lib/asterisk/agi-bin. , :

dos2unix /var/lib/asterisk/agi-bin/texttospeech.php 
chown asterisk:asterisk /var/lib/asterisk/agi-bin/texttospeech.php 
chmod 775 /var/lib/asterisk/agi-bin/texttospeech.php

, . , , , .

:

  1. AGI ;
  2. , . API;
  3. API ;
  4. ;
  5. Asterisk ;
  6. ;
  7. ;

?

. /etc/asterisk/extensions_custom.conf :

[text_to_speech]
exten => s,1,Answer()
exten => s,2,AGI(texttospeech.php,"!   .     ,    !")

FreePBX. FreePBX. Custom Destinations. AdminCustom Destinations Add Destination:

Custom Destination FreePBX

. , 13 . IVR IVR Entries :

    Asterisk

, . :) , , /etc/asterisk/extensions_custom.conf.


?


: