je suis débutant-autodidacte pour essayer de résoudre ce problème:
Mon objectif initial est de récupérer un mp3 créé en ligne pour faire du TTS (text to speech).
La solution d'origine était celle de Google http://translate.google.com/translate_t ... jour&tl=fr. Dont voici l'utilisation en PhP:
protected function TTSToMp3($words,$lang)
{
// Directory
$folder = "audio/".$lang;
// Replace the non-alphanumeric characters
// The spaces in the sentence are replaced with the Plus symbol
$words = urlencode($words);
// Name of the MP3 file generated using the MD5 hash
$file = md5($words);
// If folder doesn't exists, create it
if (!file_exists($folder))
mkdir($folder, 0755, true);
// Save the MP3 file in this folder with the .mp3 extension
$file = $folder."/TTS-".$file.".mp3";
// If the MP3 file exists, do not create a new request
if (!file_exists($file))
{
// Google Translate API cannot handle strings > 100 characters
$words = $this->CutString($words,100);
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0');
$mp3 = "";
for ($i = 0; $i < count($words); $i++)
$mp3[$i] = file_get_contents('http://translate.google.com/translate_tts?q='.$words[$i].'&tl='.$lang);
file_put_contents($file, $mp3);
}
return $file;
}
Seulement voilà que depuis peu, Google demande un Captcha pour cette fonction, devenant inexploitable ... je pense.Au détour d'un autre forum sur le TTS, il y a une parade en ajoutant "client=t" dans le code, soit:
http://translate.google.com/translate_t ... jour&tl=fr
En tapant ce lien dans une barre d'adresse, la lecture du fichier est automatique et ne propose pas de l'enregistrer.
Et en faisant la modif dans le code Php, ça ne marche pas non plus. La commande "file_get_contents" ne doit plus être la bonne?
En grattant encore, une commande cURL fonctionnerait (on retrouve notre "client=t"):
Code : Tout sélectionner
curl 'http://translate.google.com/translate_tts?ie=UTF-8&q=Hello&tl=en&client=t' -H ''Referer: http://translate.google.com/' -H 'User-Agent: stagefright/1.2 (Linux;Android 5.0)' > google_tts.mp3HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MAMI; rv:11.0) like Gecko
SYSTEM = Linux localhost 3.10.33 #17 SMP PREEMPT Mon Jan 12 11:47:03 CST 2015 armv7l
Tout ceci est trop complexe pour moi.
L'objectif étant simplement d'enregistrer le fichier mp3 contenant le texte parlé.
Pouvez-vous m'aider?
Merci