php-pulseaudio/examples/record-app.php

36 lines
868 B
PHP
Raw Permalink Normal View History

2017-02-13 21:50:11 +00:00
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\PulseAudio\PulseAudio;
$pulse = new PulseAudio();
// Find the client
$inputs = $pulse->getSinkInputs();
foreach ($inputs as $input) {
if ($input->getProperty('application.name') == 'Audacious') {
echo "Found audacious on input #".$input->getIndex()."\n";
record($pulse, $input, "output.wav");
}
}
function record($pulse, $input, $filename)
{
echo "Creating null sink...\n";
$recSink = $pulse->createNullSink();
echo "Creating recorder...\n";
$recorder = $recSink->createRecorder();
$recorder->setFilename($filename);
echo "Moving audacious to the null sink with index #".$recSink->getIndex()."...\n";
$input->moveToSink($recSink);
echo "Recording 5 seconds...\n";
$recorder->start();
sleep(5);
$recorder->stop();
}