Зачем это нужно: при воспроизведении голоса Алисы через сетевые сервисы (dnla, chromecast, google home) предыдущее сообщение прерывается новым. Для создания очереди я создал класс GoogleHome И 2 скрипта
sayaddqueue (добавление в очередь)
Код: Выделить всё
$nf=$params['file'];
$queue=gg('GoogleHome.queue');
if (strlen($queue)<5) {sg('GoogleHome.queue','');}
if ($nf<>"http://192.168.1.39/cms/cached/voice/dingdong.mp3")
{sg('GoogleHome.queue',gg('GoogleHome.queue').";".$nf);}
Код: Выделить всё
require_once('/var/www/lib/getID3/getid3/getid3.php');
if (gg('GoogleHome.runscript')<>1) {
//while (!empty(gg('GoogleHome.queue')))
{
sg('GoogleHome.runscript',1);
setTimeout('googlehomerun',"sg('GoogleHome.runscript',0);",1200);
$queue=gg('GoogleHome.queue');
$files=explode(';',$queue);
$fn=$files[0];
$ready=gg('GoogleHome.ready');
for ($i = 1; $i <= 10; $i++)
{
sleep(1);
if (gg('GoogleHome.ready')==1) {break;};
sg('GoogleHome.waitready',gg('GoogleHome.ready'));
}
$getID3 = new getID3;
$rfn='/var/www/cms/cached/voice/'.basename($fn);
$ThisFileInfo = $getID3->analyze($rfn);
getid3_lib::CopyTagsToComments($ThisFileInfo);
$filelength=@$ThisFileInfo['playtime_seconds'];
sg('GoogleHome.phraselength',$filelength);
echo $fn.":".$filelength."<br>";
sg('GoogleHome.ready',0);
setTimeout('googlehomeready',"sg('GoogleHome.ready',1);",$filelength+5);
$cmd='curl -X GET http://192.168.1.39:8091/google-home-notifier?text='.urlencode($fn);
echo $cmd."<br>";
$answ=shell_exec($cmd);
$queue=gg('GoogleHome.queue');
echo $answ."<br>";
echo "queue:". $queue."<br><br>";
//$newqueue=$queue;
$newqueue=mb_substr($queue,strlen($fn)+1);
echo "newqueue:". $newqueue."<br>";
//$newqueue=ltrim($queue,$rfn);
sg('GoogleHome.queue',$newqueue);
}
sg('GoogleHome.runscript',0);
clearTimeOut('googlehomerun');
}
else {echo "Скрипт уже запущен!!!!";}
Код: Выделить всё
$url='http://192.168.1.39/cms/cached/voice/'.basename($filename); runScript('sayaddqueue', array('file' => $url));