Telegram - ?

5

, E-commerce. , :

  1. ;
  2. DTMF AGI ;
  3. , SQL , . ;
  4. , - API Yandex.SpeechKit (TTS text to speech);
  5. Yandex, (.wav, 8k) ;
  6. ;

. ? :)


API - Yandex.SpeechKit

1 . , Yandex. SpeechKit Cloud . .

https://developer.tech.yandex.ru :

  API   Yandex.SpeechKit Cloud
  • - . , Asterisk + TTS;
  • - SpeechKit Cloud;
 API   Yandex.SpeechKit Cloud

, . AGI .


SQL , . , , IP Asterisk (+ ). , ( SSH):

use asteriskcdrdb;
CREATE TABLE zakazy(name varchar(20),phone varchar(20),nomerzakaza varchar(20),status varchar(20));
INSERT INTO zakazy (name, phone, nomerzakaza, status) VALUES ("", "79257777777", 300388, "");
INSERT INTO zakazy (name, phone, nomerzakaza, status) VALUES ("", "79251111111", 476656, "");
INSERT INTO zakazy (name, phone, nomerzakaza, status) VALUES ("", "79252222222", 0089822, "");

. , SELECT :

CREATE USER '_mysql'@'localhost' IDENTIFIED BY '_mysql';
GRANT SELECT ON asteriskcdrdb.zakazy TO '_mysql';

AGI. , //:


AGI -

:

#!/usr/bin/php -q
<?php
error_reporting(0);
require('phpagi.php');
$agi = new AGI();
$result = $agi->get_data('custom/generate', 6000, 10); // DTMF  ;
$number= $result['result']; //      ;
$hostname = "localhost"; //   localhost.     IP  ,       (  pg_hba.conf   );
$username = "_mysql"; // ,     ;
$password = "_mysql"; // ,     ;
$dbName = "asteriskcdrdb"; 
mysql_connect($hostname,$username,$password) OR DIE("    ");
mysql_select_db($dbName) or die(mysql_error());
$query = "SELECT * FROM zakazy WHERE `nomerzakaza`='$number';"; //       ;
$res=mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
$status = $row['status'];
$name = $row['name']; //   ,   SQL   ;
};
$str = ' '.$name.'!          '.$status.'       ,  !'; //  ,   ;
$qs = http_build_query(array("format" => "wav","lang" => "ru-RU","speaker" => "jane","key" => "_","emotion" => "good", "text" => $str)); // ,      API .     , ,  (   )   .  "_"  ,   API Yandex. SpeechKit Cloud;
$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); //    (   file1.wav);
shell_exec('sox -t raw -r 48k -e signed-integer -b 16 -c 1 file1.wav -t wav -r 8k -c 1 /var/lib/asterisk/sounds/ru/custom/output1.wav'); //        Asterisk -      /var/lib/asterisk/sounds/ru/custom/;
shell_exec('chown asterisk:asterisk /var/lib/asterisk/sounds/ru/custom/output1.wav');
shell_exec('chmod 775 /var/lib/asterisk/sounds/ru/custom/output1.wav'); //    ;
$agi->exec('Playback',"custom/output1");  //   AGI      ;
shell_exec('rm -f /var/lib/asterisk/sounds/ru/custom/output1.wav'); 
shell_exec('rm -f file1.wav'); //   ;
?>
AGI
, .php

tts.php /var/lib/asterisk/agi-bin :

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

, , /etc/asterisk/extensions_custom.conf :

[tts_menu]
exten => s,1,Answer()
exten => s,2,AGI(tts.php)

. FreePBX. Custom Destinations. AdminCustom Destinations Add Destination:

 Custom Destination  SpeechKit

Submit Apply Config. IVR 4 . IVR IVR Entries :

 TTS  IVR FreePBX

. , , :)


?


: