Last active
June 25, 2018 18:21
-
-
Save Mihonarium/f9c8f475ae5aa2e48ea78be00af42b69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'bot_functions.php'; | |
function downloadAudioFile($audiolink) | |
{ | |
$ext = 'mp3'; | |
$saveFile = 'tmp/'.md5(microtime(true)).'.'.$ext; | |
file_put_contents("$saveFile", fopen("$audiolink", 'r')); | |
return $saveFile; | |
} | |
function genAudioFile($mes, $lang, $speaker, $speachKitKey, $emotion, $speed) | |
{ | |
$genling = "https://tts.voicetech.yandex.net/generate?text=".urlencode($mes)."&format=mp3&lang={$lang}&speaker={$speaker}&key={$speachKitKey}&emotion={$emotion}&speed={$speed}"; | |
$genFile = downloadAudioFile($genling, $mes); | |
return $genFile; | |
} | |
$confirmation_token = ''; | |
$token = ''; | |
$yandexVoiceToken = ""; | |
$data = json_decode(file_get_contents('php://input')); | |
if(($data->type) == 'confirmation') | |
{ | |
echo $confirmation_token; | |
return; | |
} | |
echo_ok(); | |
if(($data->type) != 'message_new') | |
return; | |
$user_id = $data->object->user_id; | |
vk_start_typing($user_id, $token); | |
$mes = $data->object->body; | |
message_send($user_id, '', $token, uploadVoiceMessage(genAudioFile($mes, 'ru', 'ermil', $yandexVoiceToken, 'neutral', '1.0'), $token, $user_id)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment