I don’t have a credit card and unable to use the Speech Recognition of google.
So I am unable to use the Standard Asterisk voicemail integration.
I made my own.
It detects voicemail messages and creates a mp3 playlist with all the recordings. I tried to make it one mp3 but that failed. But Google assistant can only play the 1st recording in the playlist. So I use my speaker system.
it uses gtts to make announcements of the voicemail and i have made a script to detect callers names using khard.
run it as a crontab on the asterisk server. and make a mediaplayer play the m3u file as playlist.
#!/usr/bin/php
<?php
$http_path = "/var/www/html/asterisk/";
$http_url = "http://192.168.5.14/asterisk/";
$spool_path = "/var/spool/asterisk/voicemail/default/1000/INBOX/";
$voicemail_count_file ="/opt/voicemail_assistant/count_file.txt";
function khard($number) {
$command = "";
$name=$number;
#make the number general
if (preg_match('/\+\d+/', $number)) {
$number = substr($number, 3);
} else {
$number = substr($number, 1);
}
$handle = popen('export LC_ALL=en_US.UTF-8 && khard -c /opt/khard/config/khard.conf '. $number. ' 2>/dev/null', 'r');
while($read = fread($handle, 2096)) {
$command = $command . $read;
}
pclose($handle);
$pattern = "/\d+\s{2,}([A-Za-z0-9].*)\s{2}\s.cell/";
if(preg_match_all($pattern, $command, $matches)) {
$name = $matches[1][0];
}
return $name;
}
$nFound = 0;
if ($handle = opendir($spool_path)) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
# echo "$entry\n";
$pattern = "/msg(\d{4})\.wav/";
if(preg_match_all($pattern, $entry, $matches)) {
$voicemails[] = $matches[1][0];
$nFound++;
#print_r($matches);
}
}
closedir($handle);
}
$last_count = file_get_contents($voicemail_count_file);
if ($last_count == $nFound ) {
echo "no change found";
exit(0);
}
if ($nFound > 0) {
asort($voicemails);
#print_r($voicemails);
$voicemailCount = 0;
$mp3Count = 0;
unlink($http_path."/playlist.m3u");
foreach ($voicemails as $voicemail) {
$voicemailCount++;
$mp3Count++;
echo "$voicemail\n";
$info = parse_ini_file($spool_path.'/msg'.$voicemail.'.txt');
print_r($info);
$name = khard($info['callerid']);
system("/usr/local/bin/gtts-cli -l nl 'voicemail $voicemailCount van $name' > ".$http_path."/part".$mp3Count.".mp3");
file_put_contents($http_path."/playlist.m3u", $http_url."/part".$mp3Count.".mp3\n", FILE_APPEND | LOCK_EX);
$mp3Count++;
system("ffmpeg -i ".$spool_path."/msg".$voicemail.".wav -ab 32k -filter:a \"volume=3.5\" ".$http_path."/part".$mp3Count.".mp3");
file_put_contents($http_path."/playlist.m3u",$http_url."/part".$mp3Count.".mp3\n", FILE_APPEND | LOCK_EX);
}
} else {
foreach (new DirectoryIterator($http_path) as $fileInfo) {
if(!$fileInfo->isDot()) {
unlink($fileInfo->getPathname());
}
}
system("/usr/local/bin/gtts-cli -l nl 'U heeft geen berichten' > ".$http_path."/part1.mp3");
file_put_contents($http_path."/playlist.m3u", $http_url."/part1.mp3\n", LOCK_EX);
}
echo "## $nFound ##";
file_put_contents($voicemail_count_file,$nFound);
#!/usr/bin/php
<?php
$command = "";
$addressbook ="none";
$number = $argv[1];
$name=$number;
$bFound = false;
#echo strpos($number,"+");
#make the number general
if (preg_match('/\+\d+/', $number)) {
$number = substr($number, 3);
} else {
$number = substr($number, 1);
}
/* Add redirection so we can get stderr. */
$handle = popen('export LC_ALL=en_US.UTF-8 && khard -c /opt/khard/config/khard.conf '. $number. ' 2>/dev/null', 'r');
#echo "'$handle'; " . gettype($handle) . "\n";
while($read = fread($handle, 2096)) {
$command = $command . $read;
}
pclose($handle);
$pattern = "/Address book: (.*)/";
if(preg_match_all($pattern, $command, $matches)) {
$addressbook = $matches[1][0];
$bFound = true;
}
#echo $addressbook;
file_put_contents("/opt/khard/addressbook", $addressbook);
$pattern = "/\d+\s{2,}([A-Za-z0-9].*)\s{2}\s.cell/";
if(preg_match_all($pattern, $command, $matches)) {
$name = $matches[1][0];
#print_r($matches);
}
file_put_contents("/opt/khard/name", $name);
if ($bFound) {
file_put_contents("/opt/khard/name_and_number", $name . " " . $argv[1]);
} else {
file_put_contents("/opt/khard/name_and_number", $name);
}
?>