<?php
$db_values=array();
$filename=$argv[1];
// echo "$filename path <br><br>";
$vm_prop=file($filename);
foreach($vm_prop as $key=>$value) {
//echo" $key => $value<br>";
$db_values[]=$value;
}
//print_r($db_values);
function clean($var) {
$var=stristr($var, '=');
$var=str_replace ("=" ,"",$var);
$var=trim($var);
return $var;
}
/*email part */
$exten=clean($db_values[4]);
if(!empty($exten)){
$email=shell_exec("cat /etc/asterisk/voicemail.conf | grep ${exten}");
stristr($email, '@'); // As of PHP 5.3.0, outputs US
$username=stristr($email, '@',true);
$id=explode(',',$email);
//echo $id[2];
$domain=explode(',',$username);
//echo $domain[2];
}
else {
echo "FALSE";
}
/*end email extraction */
$email=$id[2];
$extension=clean($db_values[4]);
$caller=clean($db_values[11]);
$time=clean($db_values[12]);
$duration=clean($db_values[17]);
$file=str_replace (".txt" ,".wav",$argv[1]);
$message=" Hello $extension you got a new voicemail from $caller at $time with a duration $duration \n";
$subject="New Voicemail from $caller";
//system("echo \"$message\" | mail -a $file -s \"$caller\" ambiorixg12@gmail.com");
/*google transcription */
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Speech\SpeechClient;
# Your Google Cloud Platform project ID
$projectId = 'voice-184406';
putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/html/google/voice.json');
# Instantiates a client
$speech = new SpeechClient([
'projectId' => $projectId,
'languageCode' => 'en-US',
]);
# The name of the audio file to transcribe
//$fileName = __DIR__ . '/resources/audio.raw';
$fileName = "$file";
# The audio file's encoding and sample rate
$options = [
'encoding' => 'LINEAR16',
'sampleRateHertz' => 8000,
];
# Detects speech in the audio file
$results = $speech->recognize(fopen($fileName, 'r'), $options);
foreach ($results as $result) {
echo 'Transcription: ' . $result->alternatives()[0]['transcript'] . PHP_EOL;
}
$message.="\n";
$message.=$result->alternatives()[0]['transcript'] . PHP_EOL;
system("echo \"$message\" | mail -a $file -s \"$caller\" ambiorixg12@gmail.com");
?>
php vm_info.php /var/spool/asterisk/voicemail/default/200/INBOX/msg0031.txt