示例#1
0
 private function createIntermediaries()
 {
     //generate intermediary file
     $ts = time() . rand(0, 1000);
     $soxClass = "Media\\Driver\\Drivers\\SoxShell";
     if (!$soxClass::installed()) {
         throw new \Exception("Sox needs to be installed");
     }
     //Convert everything to 48k, so we upscale and downscale
     //This is on purpose.
     //Transform into a wav file
     foreach ($this->getDrivers() as $driver) {
         if ($this->extension == "wav" && $driver == "AsteriskShell") {
             continue;
             //just dont allow it
         }
         $class = "Media\\Driver\\Drivers\\" . $driver;
         if ($class::installed() && $class::isCodecSupported($this->extension, "in")) {
             $d = new $class($this->track, $this->extension, $this->mime, 48000, 1, 16);
             $d->convert($this->tempDir . "/temp." . $ts . ".wav", "wav", "audio/x-wav");
             $intermediary['wav']['path'] = $this->tempDir . "/temp." . $ts . ".wav";
             $intermediary['wav']['extension'] = "wav";
             $intermediary['wav']['mime'] = "audio/x-wav";
             break;
         }
     }
     if (!isset($intermediary['wav']['path']) || !file_exists($intermediary['wav']['path'])) {
         throw new \Exception(sprintf(_("Unable to find an intermediary converter for %s"), $this->track));
     }
     //Asterisk 11 should support sln48 but it doesnt, it says it does but then complains
     //It might be a bug, regardless this is fixed in 13 people should just use it
     $ver = \FreePBX::Config()->get("ASTVERSION");
     if (version_compare_freepbx($ver, "13.0", "ge") && \Media\Driver\Drivers\AsteriskShell::isCodecSupported("sln48", "in")) {
         $type = "sln48";
         $samplerate = 48000;
     } elseif (\Media\Driver\Drivers\AsteriskShell::isCodecSupported("sln16", "in")) {
         $type = "sln16";
         $samplerate = 16000;
     } else {
         $type = "wav16";
         $samplerate = 16000;
     }
     $nt = \notifications::create();
     if (version_compare_freepbx($ver, "13.0", "ge") && !\Media\Driver\Drivers\AsteriskShell::isCodecSupported("sln48", "in")) {
         //something is wacky here
         $nt->add_warning("FRAMEWORK", "UNSUPPORTED_SLN48", _("The file format sln48 is not supported on your system"), _("The file format sln48 is not supported by Asterisk when it should be. Audio conversion quality will be limited to 16k instead of 48k"));
     } else {
         $nt->delete("FRAMEWORK", "UNSUPPORTED_SLN48");
     }
     //Now transform into a raw audio file
     $d = new $soxClass($intermediary['wav']['path'], $intermediary['wav']['extension'], $intermediary['wav']['mime'], $samplerate, 1, 16);
     $d->convert($this->tempDir . "/temp." . $ts . "." . $type, $type, "audio/x-raw");
     $intermediary['sln']['path'] = $this->tempDir . "/temp." . $ts . "." . $type;
     $intermediary['sln']['extension'] = $type;
     $intermediary['sln']['mime'] = "audio/x-raw";
     if (empty($intermediary)) {
         throw new \Exception("No Driver found for " . $this->extension);
     }
     if (!file_exists($intermediary['wav']['path']) || !file_exists($intermediary['sln']['path'])) {
         throw new \Exception("Intermediary files could not be created");
     }
     return $intermediary;
 }
示例#2
0
 /**
  * Get all supported formats
  * @return array Array of supported audio formats
  */
 public static function getSupportedFormats()
 {
     $formats = array("out" => array(), "in" => array());
     if (Driver\Drivers\AsteriskShell::installed()) {
         $formats = Driver\Drivers\AsteriskShell::supportedCodecs($formats);
     }
     if (Driver\Drivers\SoxShell::installed()) {
         $formats = Driver\Drivers\SoxShell::supportedCodecs($formats);
     }
     if (Driver\Drivers\Mpg123Shell::installed()) {
         $formats = Driver\Drivers\Mpg123Shell::supportedCodecs($formats);
     }
     if (Driver\Drivers\FfmpegShell::installed()) {
         $formats = Driver\Drivers\FfmpegShell::supportedCodecs($formats);
     }
     if (Driver\Drivers\LameShell::installed()) {
         $formats = Driver\Drivers\LameShell::supportedCodecs($formats);
     }
     return $formats;
 }
示例#3
0
 /**
  * Get all supported formats
  * @return array Array of supported audio formats
  */
 public static function getSupportedFormats($driver = null)
 {
     $formats = array("out" => array(), "in" => array());
     if (empty($driver)) {
         if (Driver\Drivers\AsteriskShell::installed()) {
             $formats = Driver\Drivers\AsteriskShell::supportedCodecs($formats);
         }
         if (Driver\Drivers\SoxShell::installed()) {
             $formats = Driver\Drivers\SoxShell::supportedCodecs($formats);
         }
         if (Driver\Drivers\Mpg123Shell::installed()) {
             $formats = Driver\Drivers\Mpg123Shell::supportedCodecs($formats);
         }
         if (Driver\Drivers\FfmpegShell::installed()) {
             $formats = Driver\Drivers\FfmpegShell::supportedCodecs($formats);
         }
         if (Driver\Drivers\LameShell::installed()) {
             $formats = Driver\Drivers\LameShell::supportedCodecs($formats);
         }
     } else {
         $class = 'Media\\Driver\\Drivers\\' . $driver;
         if (class_exists($class) && $class::installed()) {
             $formats = $class::supportedCodecs($formats);
         } elseif (!class_exists($class)) {
             throw new \Exception("Driver not avalible");
         } else {
             //not installed...
         }
     }
     return $formats;
 }