1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Livewire;
- use Livewire\Component;
- use Google\Cloud\TextToSpeech\V1\AudioConfig;
- use Google\Cloud\TextToSpeech\V1\AudioEncoding;
- use Google\Cloud\TextToSpeech\V1\SynthesisInput;
- use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
- use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
- use Symfony\Component\Process\Process;
- use Symfony\Component\Process\Exception\ProcessFailedException;
- use Illuminate\Support\Facades\Storage;
- use Livewire\Attributes\On;
- class GenMessage extends Component
- {
- public $name;
- public $text;
- public $mail;
- public $start;
- public $end;
- public function render()
- {
- return view('livewire.gen-message');
- }
- public function generate(){
- $id = uniqid();
- $start = date("d/m/y H:i",strtotime($this->start));
- $end = date("d/m/y H:i",strtotime($this->end));
- $textToSpeechClient = new TextToSpeechClient([
- 'credentials' => json_decode(file_get_contents('/home/alexis/tts/tts3cx-364517-c2071a1937ae.json'), true)
- ]);
- $input = new SynthesisInput();
- $input->setText(strtolower($this->text));
- $voice = new VoiceSelectionParams();
- $voice->setLanguageCode('fr-FR');
- $voice->setName('fr-FR-Neural2-B');
- $audioConfig = new AudioConfig();
- $audioConfig->setAudioEncoding(AudioEncoding::LINEAR16);
- $resp = $textToSpeechClient->synthesizeSpeech($input, $voice, $audioConfig);
- $filename = preg_replace('/\s+/', '', $this->name).$id;
- Storage::disk('public')->put($filename.'.mp3',$resp->getAudioContent());
- shell_exec("ffmpeg -i storage/".$filename.".mp3 -ar 8000 -ac 1 -y storage/".$filename.".wav && rm storage/".$filename.".mp3");
- // $process = new Process(['ffmpeg','-i','storage/app/'.$filename.'.mp3', '-ar', '8000','-ac','1','-y', 'storage/app/'.$filename.'.wav']);
- // $process->run();
- if(null != session('audio')){
- session()->pull('audio');
- }
- session([
- 'audio' => $filename.'.wav',
- 'name' => $this->name,
- 'mail' => $this->mail,
- 'dates' => "Du ".$start.' jusqu\'au '.$end,
- 'text' => $this->text
- ]);
- $this->dispatch('msg-gen');
- }
- }
|