Skip to content

Instantly share code, notes, and snippets.

@Mihonarium
Last active June 25, 2018 18:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mihonarium/f9c8f475ae5aa2e48ea78be00af42b69 to your computer and use it in GitHub Desktop.
Save Mihonarium/f9c8f475ae5aa2e48ea78be00af42b69 to your computer and use it in GitHub Desktop.
<?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