<?php
include ('options.php');
function englishToRussian($text) {
$conversion = [
'q' => 'к', 'w' => 'в', 'e' => 'и', 'r' => 'р', 't' => 'т',
'y' => 'й', 'u' => 'у', 'i' => 'и', 'o' => 'о', 'p' => 'п',
'a' => 'а', 's' => 'с', 'd' => 'д',
'f' => 'ф', 'g' => 'г', 'h' => 'х', 'j' => 'ж', 'k' => 'к',
'l' => 'л', 'z' => 'з', 'x' => 'кс',
'c' => 'с', 'v' => 'в', 'b' => 'б', 'n' => 'н', 'm' => 'м',
// Добавьте больше символов по мере необходимости.
];
return strtr($text, $conversion);
}
$speaker = $_POST['speaker'];
$text = $_POST['text'];
$text = englishToRussian($text);
$text = str_replace("Патрик", "П+атрик", $text);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://192.168.0.103:3000/generate_voice");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data['sample_rate'] = intval(24000);
$data['text'] = $text;
$data['speaker'] = $speaker;
$data['format'] = "wav";
$data = json_encode($data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);
$resp = json_decode($resp);
$audio = base64_decode(($resp)->results[0]->audio);
$permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$filename = substr(str_shuffle($permitted_chars), 0, 16) . '.wav';
file_put_contents("media/$filename", $audio);
echo "http://localhost/media/$filename";
?>