<?php
// Imports the Cloud Client Library
use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
class TTSSwedisch extends TTSService {
public $googleCloudTTS;
function getSoundFromGoogle($word){
$word = strtolower($word);
if(false && !file_get_contents("http://bot.bayadic.com/bot/bayadicbot/bots/trgerman/sounds/".$word.".mp3")){
if(!file_exists("sounds")){
mkdir("sounds", 0777, true);
}
$client = new TextToSpeechClient();
$synthesisInputText = (new SynthesisInput())
->setText($word);
$voice = (new VoiceSelectionParams())
->setLanguageCode('sv')
->setSsmlGender(SsmlVoiceGender::FEMALE);
$effectsProfileId = "telephony-class-application";
$audioConfig = (new AudioConfig())
->setAudioEncoding(AudioEncoding::MP3)
->setEffectsProfileId(array($effectsProfileId));
$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
$audioContent = $response->getAudioContent();
file_put_contents("sounds/".$word.'.mp3', $audioContent);
// echo 'Audio content written to "output.mp3"' . PHP_EOL;
}
else {
}
return "https://bot.bayadic.com/botdev/bayadicbot/bots/trswedish/sounds/" . strtolower($word).".mp3";
}
}
?>