Skip to content

Instantly share code, notes, and snippets.


nickstewart95/sample.php Secret

Created Jan 3, 2021
What would you like to do?
public function textToSpeech($text)
$file = md5($text) . '.mp3';
$file_path = __DIR__ . '/audio/' . $file;
if (!file_exists($file_path)) {
$textToSpeechClient = new TextToSpeechClient([
'credentials' => ''
$input = (new SynthesisInput())
$voice = (new VoiceSelectionParams())
$audioConfig = (new AudioConfig())
$resp = $textToSpeechClient->synthesizeSpeech($input, $voice, $audioConfig);
file_put_contents($file_path, $resp->getAudioContent());
return $file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment