@ששא
אני משתמש עם זה כך:
tts("/wav/www/html/, "text", "filename");
function tts($dir, $text, $filename){
// API key for the Google Cloud project
$apiKey = 'AIzaSyBOJXXXXXXXXXXXXXXXX';
// URL of the Google TTS API
$url = 'https://texttospeech.googleapis.com/v1/text:synthesize?key=' . $apiKey;
$language = 'he-IL';
// Request payload
$payload = json_encode([
'input' => [
'text' => $text
],
'voice' => [
'languageCode' => $language,
'ssmlGender' => 'MALE',
'name' => 'he-IL-Standard-D'
],
'audioConfig' => [
//wav = LINEAR16
//mp3 = MP3
//ogg = OGG_OPUS
//u-law = MULAW
//A-law = ALAW
'audioEncoding' => 'MP3',
]
]);
// Set up CURL
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Content-Length: ' . strlen($payload)
]
]);
// Send the request and get the response
$response = curl_exec($curl);
// Check for CURL errors
if (curl_errno($curl)) {
$error = curl_error($curl);
curl_close($curl);
die('CURL Error: ' . $error);
}
// Check the response code
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
curl_close($curl);
die('HTTP Error: ' . $httpCode);
}
// Close CURL
curl_close($curl);
// Decode the response JSON
$data = json_decode($response, true);
// Get the audio content
$audioContent = $data['audioContent'];
$fp = fopen($dir.$filename.'.mp3', 'w');
fwrite($fp, base64_decode($audioContent));
fclose($fp);
}
עובד לי תקין.
לא הצלחתי לשחק עם עוצמת הקול וכדו'.
אם אתה מצליח, תעדכן.