32 lines
1.0 KiB
PHP
Executable File
32 lines
1.0 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: audio/mpeg');
|
|
header('Cache-Control: no-cache');
|
|
|
|
$text = $_POST['text'] ?? $_GET['text'] ?? '';
|
|
if (empty($text)) { http_response_code(400); exit; }
|
|
|
|
// Nettoyer le texte
|
|
$text = strip_tags($text);
|
|
$text = preg_replace('/[\x{1F300}-\x{1F9FF}]/u', '', $text);
|
|
$text = preg_replace('/\[.*?\]/', '', $text); // Enlever [thinking]
|
|
$text = substr($text, 0, 1000);
|
|
|
|
// Voix française naturelle Microsoft
|
|
$voice = $_POST["voice"] ?? $_GET["voice"] ?? "fr-FR-DeniseNeural";
|
|
$allowedVoices = ["fr-FR-DeniseNeural", "fr-FR-EloiseNeural", "fr-FR-HenriNeural", "fr-FR-VivienneMultilingualNeural", "fr-FR-RemyMultilingualNeural"];
|
|
if (!in_array($voice, $allowedVoices)) $voice = "fr-FR-DeniseNeural";
|
|
|
|
$tempFile = "/tmp/tts_" . md5($text) . ".mp3";
|
|
|
|
if (!file_exists($tempFile)) {
|
|
$cmd = "edge-tts --voice '$voice' --text " . escapeshellarg($text) . " --write-media '$tempFile' 2>/dev/null";
|
|
exec($cmd);
|
|
}
|
|
|
|
if (file_exists($tempFile)) {
|
|
readfile($tempFile);
|
|
} else {
|
|
http_response_code(500);
|
|
}
|
|
|