2011-01-21 5 views
2

Comment puis-je convertir la synthèse vocale en PHP, en générant éventuellement un fichier MP3 et en l'envoyant à l'utilisateur?Comment faire pour convertir le texte en parole en PHP

Merci.

+2

Vous aurez probablement besoin d'exécuter une sorte de logiciel sur votre serveur auquel PHP fait des appels. Je ne pense pas que ce soit faisable avec du PHP pur. – Sam152

+0

@ Sam152: Il suffit d'enregistrer un fichier, donc techniquement c'est possible en PHP pur ('file_put_contents()', 'pack()'). Cependant, il serait complètement inutile. ;) – Crozin

Répondre

1

probablement suivant est le code tel que mentionné dans le lien ci-dessus:

<?php 
//create a random number filename so that simultaneous users don't overwrite each other 
$filename = 'test.txt'; 
$text = 'This text will be converted to audio recording'; 
$outputfile = basename($filename, ".txt"); 
$outputfile = $outputfile . '.wav'; 

if (!$handle = fopen($filename, "w")) 
{ 
    //we cannot open the file handle! 
    return false; 
} 
// Write $text to our opened file. 
if (fwrite($handle, $text) === FALSE) 
{ 
    //couldn't write the file...Check permissions 
    return false; 
} 

fclose($handle); 

//initialise and execute the festival C engine 
//make sure that your environment is set to find the festival binaries! 
$cmd = "text2wave $filename -o $outputfile"; 
//execute the command 
exec($cmd); 

unlink($filename); 
echo "Recording is successful. \nRecording File: " . $outputfile; 
//finally return the uptput file path and filename 
return $outputfile; 

?> 
0

si vous utilisez Mac OS, vous pouvez simplement utiliser la pomme tts

shell_exec("say -o test.aiff this is a test"); 
Questions connexes