{"id":389018,"date":"2024-06-29T08:19:27","date_gmt":"2024-06-29T08:19:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=389018"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T08:19:27","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=389018","title":{"rendered":"<span>MikoPBX \u043d\u0430 Aster conf, TTS \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u0435\u0436\u0435\u0433\u043e\u0434\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044f <strong>Asterconf<\/strong>. \u041d\u0430\u043c \u043f\u043e\u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u043d\u0435\u0439 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0440\u044f\u0434 \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 <strong>MikoPBX<\/strong> &#8212; <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439<\/strong> \u0410\u0422\u0421 \u0441 <strong>\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/strong>. <\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0442\u043e\u044f\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0433\u0430\u0440\u0430\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0430. \u0413\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0437 \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435, \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u043e, \u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u0442, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438&#8230; <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e \u0441 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438&#8230; <\/p>\n<hr\/>\n<p><strong>\u0425\u043e\u0447\u0443 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong>, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u0435\u0439\u0441, \u043b\u0438\u0448\u044c <strong>\u043f\u0440\u0438\u043c\u0435\u0440<\/strong> \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 MikoPBX, <strong>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b<\/strong> \u0441 API \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u0443\u044e \u0442\u043e\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0439, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0443\u043c\u043d\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0438\u043c\u0435\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e MikoPBX. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API Yandex:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 YandexSynthesize \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">&lt;?php class YandexSynthesize {     public  const TTS_DIR = '\/storage\/usbdisk1\/mikopbx\/media\/yandex-tts';     public  const API_KEY = '...';     private string $voice = 'alena';      public function __construct()     {         if(!file_exists(self::TTS_DIR)){             Util::mwMkdir(self::TTS_DIR);         }     }      \/**      * \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432 \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u0438\u0441\u043a \u0444\u0430\u0439\u043b \u0441 \u0440\u0435\u0447\u044c\u044e.      *      * @param $text_to_speech - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442      * @param $voice          - \u0433\u043e\u043b\u043e\u0441      *      * @return null|string      *      * https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize      *\/     public function makeSpeechFromText($text_to_speech): ?string     {         $speech_extension        = '.raw';         $result_extension        = '.wav';         $speech_filename         = md5($text_to_speech . $this->voice);         $fullFileName            = self::TTS_DIR .'\/'. $speech_filename . $result_extension;         $fullFileNameFromService = self::TTS_DIR .'\/'. $speech_filename . $speech_extension;          \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0434\u0443\u0440\u0433 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0443\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b.         if (file_exists($fullFileName) &amp;&amp; filesize($fullFileName) > 0) {             return self::TTS_DIR .'\/'. $speech_filename;         }          \/\/ \u0424\u0430\u0439\u043b\u0430 \u043d\u0435\u0442 \u0432 \u043a\u0435\u0448\u0435, \u0431\u0443\u0434\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439.         $post_vars = [             'lang'            => 'ru-RU',             'format'          => 'lpcm',             'speed'           => '1.0',             'sampleRateHertz' => '8000',             'voice'           => $this->voice,             'text'            => urldecode($text_to_speech),         ];          $fp   = fopen($fullFileNameFromService, 'wb');         $curl = curl_init();         curl_setopt($curl, CURLOPT_HTTPHEADER, [\"Authorization: Api-Key \".self::API_KEY]);         curl_setopt($curl, CURLOPT_FILE, $fp);         curl_setopt($curl, CURLOPT_POST, true);         curl_setopt($curl, CURLOPT_TIMEOUT, 4);         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_vars));         curl_setopt($curl, CURLOPT_URL, 'https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize');         curl_exec($curl);         $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);         curl_close($curl);         fclose($fp);          if (200 === $http_code &amp;&amp; file_exists($fullFileNameFromService) &amp;&amp; filesize($fullFileNameFromService) > 0) {             exec(\"sox -r 8000 -e signed-integer -b 16 -c 1 -t raw $fullFileNameFromService $fullFileName\");             if (file_exists($fullFileName)) {                 \/\/ \u0423\u0434\u0430\u043b\u0438\u043c raw \u0444\u0430\u0439\u043b.                 @unlink($fullFileNameFromService);                 \/\/ \u0424\u0430\u0439\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u043d\u0440\u0438\u0440\u043e\u0432\u0430\u043d                 return self::TTS_DIR.'\/'.$speech_filename;             }         } elseif (file_exists($fullFileNameFromService)) {             @unlink($fullFileNameFromService);         }         return null;     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0424\u0430\u0439\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0440\u0435\u0447\u044c<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0445\u044d\u0448 \u0441\u0443\u043c\u043c\u0443, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u0443\u0436\u0435 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0440\u0430\u043d\u0435\u0435, \u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a API \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f <\/p>\n<ul>\n<li>\n<p>PHP 7.4+<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;<strong><em>API_KEY<\/em><\/strong><em>&#187; &#8212; \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 Yandex<\/em><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0438\u043a\u0442\u043e\u0440\u0430 $voice, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u0431\u0440\u0430\u043d \u0433\u043e\u043b\u043e\u0441 &#171;<strong>alena<\/strong>&#171;<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php $agi    = new AGI(); $agi->set_variable('AGIEXITONHANGUP', 'yes'); $agi->set_variable('AGISIGHUP', 'yes'); $agi->set_variable('__ENDCALLONANSWER', 'yes'); $agi->answer();<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u0430\u043d\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u0440\u0438 hangup \u043d\u0430 \u043a\u0430\u043d\u0430\u043b\u0435.<\/p>\n<p>\u041f\u043e\u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $ys = new YandexSynthesize();  $infoMessage = '\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c,  \u044f \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f  \u043f\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u0430\u0440\u0430\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0430';  $filenameInfo  = $ys->makeSpeechFromText($infoMessage);<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0430\u0445. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432:<\/p>\n<pre><code>\/storage\/usbdisk1\/mikopbx\/log\/voting \u251c\u2500\u2500 0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 74952232222 \u2502\u00a0\u00a0 \u2514\u2500\u2500 74952293042 \u2514\u2500\u2500 1     \u2514\u2500\u2500 79257180000 <\/code><\/pre>\n<ul>\n<li>\n<p>\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 &#171;<strong>0<\/strong>&#187; \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0430\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 <strong>\u043f\u0440\u043e\u0442\u0438\u0432<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 &#171;<strong>1<\/strong>&#171;, \u043d\u043e\u043c\u0435\u0440\u0430, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 &#171;<strong>\u0417\u0410<\/strong>&#171;<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php $logDir = '\/storage\/usbdisk1\/mikopbx\/log\/voting'; $ys = new YandexSynthesize(); $res = Processes::mwExec('ls -l '.$logDir.'\/*\/'.$agi->request['agi_callerid']); if($res === 0){     $filenameAlert = $ys->makeSpeechFromText('\u0412\u044b \u0443\u0436\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f:');     $agi->exec('Playback', $filenameAlert);          $yes = shell_exec('ls -l '.$logDir.'\/1\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043b\u0438 '.$yes));      $no  = shell_exec('ls -l '.$logDir.'\/0\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u0440\u043e\u0442\u0438\u0432 '.$no));      $agi->hangup();     exit(0); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0443\u0436\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b \u0441\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430, \u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u044d\u0442\u043e \u0438 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f. <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443, \u0447\u0442\u043e \u0437\u0432\u043e\u043d\u044f\u0449\u0438\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u043e\u0431\u043e\u0442\u043e\u043c. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<pre><code class=\"php\">&lt;?php $a = random_int(1, 4); $b = random_int(1, 5);  $checkRobots = \"\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0412\u044b \u043d\u0435 \u0440\u043e\u0431\u043e\u0442.  \u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.  \u0420\u0435\u0448\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440! $a \u043f\u043b\u044e\u0441 $b\";  $filenameCheck = $ys->makeSpeechFromText($checkRobots);<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0432\u043e\u0434\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $agi->exec('Playback', $filenameInfo); $result  = $agi->getData($filenameCheck, 3000, 1); $selectedNum = $result['result']??''; if (empty($selectedNum) || (int)$selectedNum !== ($a + $b)) {     $filenameAlert = $ys->makeSpeechFromText(\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0435 \u0432\u0435\u0440\u043d\u044b\u0439\");     $agi->exec('Playback', $filenameAlert);     $filenameAlert = $ys->makeSpeechFromText(\"\u0412\u044b \u0432\u0432\u0435\u043b\u0438 \u0446\u0438\u0444\u0440\u0443 \" . $selectedNum);     $agi->exec('Playback', $filenameAlert);     $agi->hangup();     exit(0); }  $filenameAlert = $ys->makeSpeechFromText(\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d \u0432\u0435\u0440\u043d\u043e.\"); $agi->exec('Playback', $filenameAlert);<\/code><\/pre>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php $text = '\u0415\u0441\u043b\u0438 \u0412\u044b \"\u0417\u0410\" \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e,  \u0442\u043e \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u041e\u0414\u0418\u041d, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0442\u0438\u0432, \u0442\u043e \u041d\u041e\u041b\u042c'; $filenameAlert = $ys->makeSpeechFromText($text);  $result = $agi->getData($filenameAlert, 3000, 1); $selectedNum = (int)($result['result']??'0');  $resultDir = $logDir.'\/'.$selectedNum; Util::mwMkdir($resultDir); file_put_contents(\"$resultDir\/{$agi->request['agi_callerid']}\", '1');  $filenameAlert = $ys->makeSpeechFromText('\u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0432\u0430\u0448 \u0433\u043e\u043b\u043e\u0441 \u0443\u0447\u0442\u0435\u043d!'); $agi->exec('Playback', $filenameAlert); $agi->hangup();<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u0430:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">&lt;?php require_once('Globals.php');  use MikoPBX\\Core\\System\\Util; use MikoPBX\\Core\\Asterisk\\AGI; use MikoPBX\\Core\\System\\Processes; class YandexSynthesize {     public  const TTS_DIR = '\/storage\/usbdisk1\/mikopbx\/media\/yandex-tts';     public  const API_KEY = '...';     private string $voice = 'alena';      public function __construct()     {         if(!file_exists(self::TTS_DIR)){             Util::mwMkdir(self::TTS_DIR);         }     }      \/**      * \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432 \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u0438\u0441\u043a \u0444\u0430\u0439\u043b \u0441 \u0440\u0435\u0447\u044c\u044e.      *      * @param $text_to_speech - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442      * @param $voice          - \u0433\u043e\u043b\u043e\u0441      *      * @return null|string      *      * https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize      *\/     public function makeSpeechFromText($text_to_speech): ?string     {         $speech_extension        = '.raw';         $result_extension        = '.wav';         $speech_filename         = md5($text_to_speech . $this->voice);         $fullFileName            = self::TTS_DIR .'\/'. $speech_filename . $result_extension;         $fullFileNameFromService = self::TTS_DIR .'\/'. $speech_filename . $speech_extension;          \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0434\u0443\u0440\u0433 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0443\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b.         if (file_exists($fullFileName) &amp;&amp; filesize($fullFileName) > 0) {             return self::TTS_DIR .'\/'. $speech_filename;         }          \/\/ \u0424\u0430\u0439\u043b\u0430 \u043d\u0435\u0442 \u0432 \u043a\u0435\u0448\u0435, \u0431\u0443\u0434\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439.         $post_vars = [             'lang'            => 'ru-RU',             'format'          => 'lpcm',             'speed'           => '1.0',             'sampleRateHertz' => '8000',             'voice'           => $this->voice,             'text'            => urldecode($text_to_speech),         ];          $fp   = fopen($fullFileNameFromService, 'wb');         $curl = curl_init();         curl_setopt($curl, CURLOPT_HTTPHEADER, [\"Authorization: Api-Key \".self::API_KEY]);         curl_setopt($curl, CURLOPT_FILE, $fp);         curl_setopt($curl, CURLOPT_POST, true);         curl_setopt($curl, CURLOPT_TIMEOUT, 4);         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_vars));         curl_setopt($curl, CURLOPT_URL, 'https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize');         curl_exec($curl);         $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);         curl_close($curl);         fclose($fp);          if (200 === $http_code &amp;&amp; file_exists($fullFileNameFromService) &amp;&amp; filesize($fullFileNameFromService) > 0) {             exec(\"sox -r 8000 -e signed-integer -b 16 -c 1 -t raw $fullFileNameFromService $fullFileName\");             if (file_exists($fullFileName)) {                 \/\/ \u0423\u0434\u0430\u043b\u0438\u043c raw \u0444\u0430\u0439\u043b.                 @unlink($fullFileNameFromService);                 \/\/ \u0424\u0430\u0439\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u043d\u0440\u0438\u0440\u043e\u0432\u0430\u043d                 return self::TTS_DIR.'\/'.$speech_filename;             }         } elseif (file_exists($fullFileNameFromService)) {             @unlink($fullFileNameFromService);         }         return null;     } }  $agi    = new AGI(); $agi->set_variable('AGIEXITONHANGUP', 'yes'); $agi->set_variable('AGISIGHUP', 'yes'); $agi->set_variable('__ENDCALLONANSWER', 'yes'); $agi->answer();  $logDir = '\/storage\/usbdisk1\/mikopbx\/log\/voting'; $ys = new YandexSynthesize(); $cmd = 'ls -l '.$logDir.'\/*\/'.$agi->request['agi_callerid']; $res = Processes::mwExec($cmd); if($res === 0){     $filenameAlert = $ys->makeSpeechFromText('\u0412\u044b \u0443\u0436\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f:');     $agi->exec('Playback', $filenameAlert);      $yes = shell_exec('ls -l '.$logDir.'\/1\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043b\u0438 '.$yes));      $no  = shell_exec('ls -l '.$logDir.'\/0\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u0440\u043e\u0442\u0438\u0432 '.$no));      $agi->hangup();     exit(0); }   $infoMessage = '\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c,  \u044f \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f  \u043f\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u0430\u0440\u0430\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0430. '; $filenameInfo  = $ys->makeSpeechFromText($infoMessage);  $a = random_int(1, 4); $b = random_int(1, 5); $checkRobots = \"\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0412\u044b \u043d\u0435 \u0440\u043e\u0431\u043e\u0442.  \u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.  \u0420\u0435\u0448\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440! $a \u043f\u043b\u044e\u0441 $b\"; $filenameCheck = $ys->makeSpeechFromText($checkRobots);  $agi->exec('Playback', $filenameInfo); $result = $agi->getData($filenameCheck, 3000, 1); $selectedNum = $result['result']??''; if (empty($selectedNum) || (int)$selectedNum !== ($a + $b)) {     $filenameAlert = $ys->makeSpeechFromText(\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0435 \u0432\u0435\u0440\u043d\u044b\u0439\");     $agi->exec('Playback', $filenameAlert);     $filenameAlert = $ys->makeSpeechFromText(\"\u0412\u044b \u0432\u0432\u0435\u043b\u0438 \u0446\u0438\u0444\u0440\u0443 \" . $selectedNum);     $agi->exec('Playback', $filenameAlert);     $agi->hangup();     exit(0); }  $filenameAlert = $ys->makeSpeechFromText(\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d \u0432\u0435\u0440\u043d\u043e.\"); $agi->exec('Playback', $filenameAlert);  $text = '\u0415\u0441\u043b\u0438 \u0412\u044b \"\u0417\u0410\" \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e,  \u0442\u043e \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u041e\u0414\u0418\u041d, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0442\u0438\u0432, \u0442\u043e \u041d\u041e\u041b\u042c'; $filenameAlert = $ys->makeSpeechFromText($text); $result = $agi->getData($filenameAlert, 3000, 1); $selectedNum = (int)($result['result']??'0');  $resultDir = $logDir.'\/'.$selectedNum; Util::mwMkdir($resultDir); file_put_contents(\"$resultDir\/{$agi->request['agi_callerid']}\", '1');  $filenameAlert = $ys->makeSpeechFromText('\u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0432\u0430\u0448 \u0433\u043e\u043b\u043e\u0441 \u0443\u0447\u0442\u0435\u043d!'); $agi->exec('Playback', $filenameAlert); $agi->hangup();<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430 <strong>MikoPBX<\/strong>:<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 dialplan:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/445\/555\/8bf\/4455558bf918e42f415ff92ac2577a69.png\" width=\"2862\" height=\"1104\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/445\/555\/8bf\/4455558bf918e42f415ff92ac2577a69.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u044f &#171;<strong>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435<\/strong>&#171;, &#171;<strong>\u041d\u043e\u043c\u0435\u0440 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong>&#171;, &#171;<strong>\u0442\u0438\u043f \u043a\u043e\u0434\u0430<\/strong>&#171;<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a4e\/bec\/e47\/a4ebece4766c5b88f61c8dbafba5c8b8.png\" width=\"2846\" height=\"1390\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a4e\/bec\/e47\/a4ebece4766c5b88f61c8dbafba5c8b8.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 &#171;\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0439 \u043a\u043e\u0434&#187;  \u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0442\u0435\u043a\u0441\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 &#171;<strong>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c<\/strong>&#171;. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c8a\/8a5\/e39\/c8a8a5e39fef3800232349006e3ae476.png\" width=\"2852\" height=\"1322\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8a\/8a5\/e39\/c8a8a5e39fef3800232349006e3ae476.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dd5\/a64\/ce2\/dd5a64ce2e7d8fea7dd3747c623c32e0.png\" width=\"2850\" height=\"1392\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd5\/a64\/ce2\/dd5a64ce2e7d8fea7dd3747c623c32e0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c:)<\/p>\n<p>\u041d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043d\u0438\u0442\u044c \u0438 \u0441 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u043d\u043e\u043c\u0435\u0440\u0430, \u043d\u0430\u0431\u0440\u0430\u0432 \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043e\u0447\u043d\u044b\u0439 (<strong>2200110<\/strong>).<\/p>\n<h2>\u0412\u0438\u0434\u0435\u043e \u0441 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438<\/h2>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6154ade86ea11f3bbbaf1f77\" data-style=\"\" id=\"6154ade86ea11f3bbbaf1f77\" width=\"\"><\/div>\n<h2>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0437\u043d\u0430\u043d\u0438\u0439<\/h2>\n<ul>\n<li>\n<p>\u0421\u0430\u0439\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 &#8212; <a href=\"https:\/\/www.mikopbx.ru\" rel=\"noopener noreferrer nofollow\">www.mikopbx.ru<\/a><\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f &#8212;<a href=\"https:\/\/wiki.mikopbx.com\" rel=\"noopener noreferrer nofollow\"> wiki.mikopbx.com<\/a><\/p>\n<\/li>\n<li>\n<p>\u0421\u0430\u0439\u0442 AsterConf &#8212; <a href=\"https:\/\/asterconf.ru\" rel=\"noopener noreferrer nofollow\">https:\/\/asterconf.ru<\/a><\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 MikoPbx <a href=\"https:\/\/github.com\/mikopbx\/Core\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mikopbx\/Core<\/a><\/p>\n<\/li>\n<li>\n<p><abbr title=\"wiki.asterisk.org\">https:\/\/wiki.asterisk.org<\/abbr><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/cloud.yandex.ru\/services\/speechkit\" rel=\"noopener noreferrer nofollow\">https:\/\/cloud.yandex.ru\/services\/speechkit<\/a><\/p>\n<\/li>\n<\/ul>\n<h2>\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b &#171;<strong>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f dialplan<\/strong>&#187; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0410\u0422\u0421. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 PHP \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a REST API \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043e\u0442\u0432\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u0430\u043d\u0430\u043b\u0430. <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \ud83d\ude42<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0435 Asterconf, \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c \u0437\u0430 \u0442\u0440\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445, \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043d\u044f, \u0431\u044b\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u043e!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/580676\/\"> https:\/\/habr.com\/ru\/articles\/580676\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u0435\u0436\u0435\u0433\u043e\u0434\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044f <strong>Asterconf<\/strong>. \u041d\u0430\u043c \u043f\u043e\u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u043d\u0435\u0439 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0440\u044f\u0434 \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 <strong>MikoPBX<\/strong> &#8212; <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439<\/strong> \u0410\u0422\u0421 \u0441 <strong>\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/strong>. <\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0442\u043e\u044f\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0433\u0430\u0440\u0430\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0430. \u0413\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0437 \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435, \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u043e, \u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u0442, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438&#8230; <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e \u0441 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438&#8230; <\/p>\n<hr\/>\n<p><strong>\u0425\u043e\u0447\u0443 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong>, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u0435\u0439\u0441, \u043b\u0438\u0448\u044c <strong>\u043f\u0440\u0438\u043c\u0435\u0440<\/strong> \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 MikoPBX, <strong>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b<\/strong> \u0441 API \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u0443\u044e \u0442\u043e\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0439, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0443\u043c\u043d\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438. <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0438\u043c\u0435\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e MikoPBX. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API Yandex:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 YandexSynthesize \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">&lt;?php class YandexSynthesize {     public  const TTS_DIR = '\/storage\/usbdisk1\/mikopbx\/media\/yandex-tts';     public  const API_KEY = '...';     private string $voice = 'alena';      public function __construct()     {         if(!file_exists(self::TTS_DIR)){             Util::mwMkdir(self::TTS_DIR);         }     }      \/**      * \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432 \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u0438\u0441\u043a \u0444\u0430\u0439\u043b \u0441 \u0440\u0435\u0447\u044c\u044e.      *      * @param $text_to_speech - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442      * @param $voice          - \u0433\u043e\u043b\u043e\u0441      *      * @return null|string      *      * https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize      *\/     public function makeSpeechFromText($text_to_speech): ?string     {         $speech_extension        = '.raw';         $result_extension        = '.wav';         $speech_filename         = md5($text_to_speech . $this->voice);         $fullFileName            = self::TTS_DIR .'\/'. $speech_filename . $result_extension;         $fullFileNameFromService = self::TTS_DIR .'\/'. $speech_filename . $speech_extension;          \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0434\u0443\u0440\u0433 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0443\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b.         if (file_exists($fullFileName) &amp;&amp; filesize($fullFileName) > 0) {             return self::TTS_DIR .'\/'. $speech_filename;         }          \/\/ \u0424\u0430\u0439\u043b\u0430 \u043d\u0435\u0442 \u0432 \u043a\u0435\u0448\u0435, \u0431\u0443\u0434\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439.         $post_vars = [             'lang'            => 'ru-RU',             'format'          => 'lpcm',             'speed'           => '1.0',             'sampleRateHertz' => '8000',             'voice'           => $this->voice,             'text'            => urldecode($text_to_speech),         ];          $fp   = fopen($fullFileNameFromService, 'wb');         $curl = curl_init();         curl_setopt($curl, CURLOPT_HTTPHEADER, [\"Authorization: Api-Key \".self::API_KEY]);         curl_setopt($curl, CURLOPT_FILE, $fp);         curl_setopt($curl, CURLOPT_POST, true);         curl_setopt($curl, CURLOPT_TIMEOUT, 4);         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_vars));         curl_setopt($curl, CURLOPT_URL, 'https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize');         curl_exec($curl);         $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);         curl_close($curl);         fclose($fp);          if (200 === $http_code &amp;&amp; file_exists($fullFileNameFromService) &amp;&amp; filesize($fullFileNameFromService) > 0) {             exec(\"sox -r 8000 -e signed-integer -b 16 -c 1 -t raw $fullFileNameFromService $fullFileName\");             if (file_exists($fullFileName)) {                 \/\/ \u0423\u0434\u0430\u043b\u0438\u043c raw \u0444\u0430\u0439\u043b.                 @unlink($fullFileNameFromService);                 \/\/ \u0424\u0430\u0439\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u043d\u0440\u0438\u0440\u043e\u0432\u0430\u043d                 return self::TTS_DIR.'\/'.$speech_filename;             }         } elseif (file_exists($fullFileNameFromService)) {             @unlink($fullFileNameFromService);         }         return null;     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0424\u0430\u0439\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0440\u0435\u0447\u044c<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0445\u044d\u0448 \u0441\u0443\u043c\u043c\u0443, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u0443\u0436\u0435 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0440\u0430\u043d\u0435\u0435, \u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a API \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f <\/p>\n<ul>\n<li>\n<p>PHP 7.4+<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;<strong><em>API_KEY<\/em><\/strong><em>&#187; &#8212; \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0447\u0438 Yandex<\/em><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0438\u043a\u0442\u043e\u0440\u0430 $voice, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b\u0431\u0440\u0430\u043d \u0433\u043e\u043b\u043e\u0441 &#171;<strong>alena<\/strong>&#171;<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php $agi    = new AGI(); $agi->set_variable('AGIEXITONHANGUP', 'yes'); $agi->set_variable('AGISIGHUP', 'yes'); $agi->set_variable('__ENDCALLONANSWER', 'yes'); $agi->answer();<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u0430\u043d\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u0440\u0438 hangup \u043d\u0430 \u043a\u0430\u043d\u0430\u043b\u0435.<\/p>\n<p>\u041f\u043e\u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $ys = new YandexSynthesize();  $infoMessage = '\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c,  \u044f \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f  \u043f\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443 \u0433\u0430\u0440\u0430\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0430';  $filenameInfo  = $ys->makeSpeechFromText($infoMessage);<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0430\u0445. \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432:<\/p>\n<pre><code>\/storage\/usbdisk1\/mikopbx\/log\/voting \u251c\u2500\u2500 0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 74952232222 \u2502\u00a0\u00a0 \u2514\u2500\u2500 74952293042 \u2514\u2500\u2500 1     \u2514\u2500\u2500 79257180000 <\/code><\/pre>\n<ul>\n<li>\n<p>\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 &#171;<strong>0<\/strong>&#187; \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0430\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 <strong>\u043f\u0440\u043e\u0442\u0438\u0432<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 &#171;<strong>1<\/strong>&#171;, \u043d\u043e\u043c\u0435\u0440\u0430, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 &#171;<strong>\u0417\u0410<\/strong>&#171;<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"php\">&lt;?php $logDir = '\/storage\/usbdisk1\/mikopbx\/log\/voting'; $ys = new YandexSynthesize(); $res = Processes::mwExec('ls -l '.$logDir.'\/*\/'.$agi->request['agi_callerid']); if($res === 0){     $filenameAlert = $ys->makeSpeechFromText('\u0412\u044b \u0443\u0436\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f:');     $agi->exec('Playback', $filenameAlert);          $yes = shell_exec('ls -l '.$logDir.'\/1\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043b\u0438 '.$yes));      $no  = shell_exec('ls -l '.$logDir.'\/0\/ | grep -v total | wc -l');     $agi->exec('Playback', $ys->makeSpeechFromText('\u041f\u0440\u043e\u0442\u0438\u0432 '.$no));      $agi->hangup();     exit(0); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0443\u0436\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b \u0441\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430, \u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u044d\u0442\u043e \u0438 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f. <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443, \u0447\u0442\u043e \u0437\u0432\u043e\u043d\u044f\u0449\u0438\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u043e\u0431\u043e\u0442\u043e\u043c. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<pre><code class=\"php\">&lt;?php $a = random_int(1, 4); $b = random_int(1, 5);  $checkRobots = \"\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0412\u044b \u043d\u0435 \u0440\u043e\u0431\u043e\u0442.  \u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.  \u0420\u0435\u0448\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440! $a \u043f\u043b\u044e\u0441 $b\";  $filenameCheck = $ys->makeSpeechFromText($checkRobots);<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0432\u043e\u0434\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php $agi->exec('Playback', $filenameInfo); $result  = $agi->getData($filenameCheck, 3000, 1); $selectedNum = $result['result']??''; if (empty($selectedNum) || (int)$selectedNum !== ($a + $b)) {     $filenameAlert = $ys->makeSpeechFromText(\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0435 \u0432\u0435\u0440\u043d\u044b\u0439\");     $agi->exec('Playback', $filenameAlert);     $filenameAlert = $ys->makeSpeechFromText(\"\u0412\u044b \u0432\u0432\u0435\u043b\u0438 \u0446\u0438\u0444\u0440\u0443 \" . $selectedNum);     $agi->exec('Playback', $filenameAlert);     $agi->hangup();     exit(0); }  $filenameAlert = $ys->makeSpeechFromText(\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d \u0432\u0435\u0440\u043d\u043e.\"); $agi->exec('Playback', $filenameAlert);<\/code><\/pre>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php $text = '\u0415\u0441\u043b\u0438 \u0412\u044b \"\u0417\u0410\" \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e,  \u0442\u043e \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u041e\u0414\u0418\u041d, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0442\u0438\u0432, \u0442\u043e \u041d\u041e\u041b\u042c'; $filenameAlert = $ys->makeSpeechFromText($text);  $result = $agi->getData($filenameAlert, 3000, 1); $selectedNum = (int)($result['result']??'0');  $resultDir = $logDir.'\/'.$selectedNum; Util::mwMkdir($resultDir); file_put_contents(\"$resultDir\/{$agi->request['agi_callerid']}\", '1');  $filenameAlert = $ys->makeSpeechFromText('\u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0432\u0430\u0448 \u0433\u043e\u043b\u043e\u0441 \u0443\u0447\u0442\u0435\u043d!'); $agi->exec('Playback', $filenameAlert); $agi->hangup();<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u0430:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">&lt;?php require_once('Globals.php');  use MikoPBX\\Core\\System\\Util; use MikoPBX\\Core\\Asterisk\\AGI; use MikoPBX\\Core\\System\\Processes; class YandexSynthesize {     public  const TTS_DIR = '\/storage\/usbdisk1\/mikopbx\/media\/yandex-tts';     public  const API_KEY = '...';     private string $voice = 'alena';      public function __construct()     {         if(!file_exists(self::TTS_DIR)){             Util::mwMkdir(self::TTS_DIR);         }     }      \/**      * \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432 \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u0438\u0441\u043a \u0444\u0430\u0439\u043b \u0441 \u0440\u0435\u0447\u044c\u044e.      *      * @param $text_to_speech - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442      * @param $voice          - \u0433\u043e\u043b\u043e\u0441      *      * @return null|string      *      * https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize      *\/     public function makeSpeechFromText($text_to_speech): ?string     {         $speech_extension        = '.raw';         $result_extension        = '.wav';         $speech_filename         = md5($text_to_speech . $this->voice);         $fullFileName            = self::TTS_DIR .'\/'. $speech_filename . $result_extension;         $fullFileNameFromService = self::TTS_DIR .'\/'. $speech_filename . $speech_extension;          \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0434\u0443\u0440\u0433 \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0443\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b.         if (file_exists($fullFileName) &amp;&amp; filesize($fullFileName) > 0) {             return self::TTS_DIR .'\/'. $speech_filename;         }          \/\/ \u0424\u0430\u0439\u043b\u0430 \u043d\u0435\u0442 \u0432 \u043a\u0435\u0448\u0435, \u0431\u0443\u0434\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439.         $post_vars = [             'lang'            => 'ru-RU',             'format'          => 'lpcm',             'speed'           => '1.0',             'sampleRateHertz' => '8000',             'voice'           => $this->voice,             'text'            => urldecode($text_to_speech),         ];          $fp   = fopen($fullFileNameFromService, 'wb');         $curl = curl_init();         curl_setopt($curl, CURLOPT_HTTPHEADER, [\"Authorization: Api-Key \".self::API_KEY]);         curl_setopt($curl, CURLOPT_FILE, $fp);         curl_setopt($curl, CURLOPT_POST, true);         curl_setopt($curl, CURLOPT_TIMEOUT, 4);         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_vars));         curl_setopt($curl, CURLOPT_URL, 'https:\/\/tts.api.cloud.yandex.net\/speech\/v1\/tts:synthesize');         curl_exec($curl);         $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);         curl_close($curl);         fclose($fp);          if (200 === $http_code &amp;&amp; file_exists($fullFileNameFromService) &amp;&amp; filesize($fullFileNameFromService) > 0) {             exec(\"sox -r 8000 -e signed-integer -b 16 -c 1 -t raw $fullFileNameFromService $fullFileName\");<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-389018","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389018"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/389018\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}