echo "Convertion is finish </br>"; echo $real . "ciao.flac"; echo "</br>"; print_r(error_get_last()); include 'GoogleSpeechToText.php'; // Your API Key goes here. echo " include work"; $speech = new GoogleSpeechToText("AIzaSyDNsTkS0Jm6NQRFbaHKBHsaRO6BXNcjOtw"); echo "File flac is ready for to be converted in text </br>"; //CAMBIARE QUANDO STA SUL SERVER //$file = realpath( '/home/a2124875/public_html/quick.flac'); $file = $real . "ciao.flac"; echo $file; $bitRate = 44100; // The bit rate of the file $result = $speech->process($file, $bitRate, 'it-IT'); print_r(error_get_last()); /* $result = $speech->process($file, $bitRate, 'it-IT'); if(!empty($result)){ echo "</br> The result: </br>"; $array=$result[0]['alternative']; foreach($array as $value){ if(!empty($value['confidence'])) echo $value['transcript'];
<?php include 'GoogleSpeechToText.php'; // Your API Key goes here. $apiKey = 'AIzaSyCbBqke_xLXiUFZd8rPuJiGJA5mnhqPeSM'; $speech = new GoogleSpeechToText($apiKey); $file = realpath('./uploads/output.flac'); // Full path to the file. $bitRate = 44100; // The bit rate of the file. $result = $speech->process($file, $bitRate, 'en-US'); var_dump($result);
include 'GoogleSpeechToText.php'; $data = array(); if (isset($_GET['files'])) { $error = false; $files = array(); $uploaddir = './uploads/'; foreach ($_FILES as $file) { $newFile = $uploaddir . basename($file['name']); if (move_uploaded_file($file['tmp_name'], $newFile)) { $files[] = $uploaddir . $file['name']; $path_parts = pathinfo($newFile); $newFileName = $path_parts['filename']; $newFileName = $newFileName . '.flac'; $command = "~/bin/ffmpeg -i " . $newFile . " ./uploads/" . $newFileName; shell_exec($command); $apiKey = 'AIzaSyCbBqke_xLXiUFZd8rPuJiGJA5mnhqPeSM'; $speech = new GoogleSpeechToText($apiKey); $file = realpath('./uploads/' . $newFileName); // Full path to the file. $bitRate = 44100; // The bit rate of the file. $output = $speech->process($file, $bitRate, 'en-US'); } else { $error = true; } } $data = $error ? array('error' => 'There was an error uploading your files') : array('command' => $output); } else { $data = array('success' => 'Form was submitted', 'formData' => $_POST); } echo json_encode($data);