Advertisement
Guest User

Untitled

a guest
Oct 24th, 2015
1,334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <?php
  2. class mp3
  3.  
  4.     {
  5.     var $str;
  6.     var $time;
  7.     var $frames;
  8.  
  9.     // Create a new mp3
  10.  
  11.     function mp3($path = "")
  12.         {
  13.         if ($path != "")
  14.             {
  15.             $this->str = file_get_contents($path);
  16.             }
  17.         }
  18.  
  19.     // Put an mp3 behind the first mp3
  20.  
  21.     function mergeBehind($mp3)
  22.         {
  23.         $this->str.= $mp3->str;
  24.         }
  25.  
  26.     // Calculate where's the end of the sound file
  27.  
  28.     function getIdvEnd()
  29.         {
  30.         $strlen = strlen($this->str);
  31.         $str = substr($this->str, ($strlen - 128));
  32.         $str1 = substr($str, 0, 3);
  33.         if (strtolower($str1) == strtolower('TAG'))
  34.             {
  35.             return $str;
  36.             }
  37.           else
  38.             {
  39.             return false;
  40.             }
  41.         }
  42.  
  43.     // Calculate where's the beginning of the sound file
  44.  
  45.     function getStart()
  46.         {
  47.         $strlen = strlen($this->str);
  48.         for ($i = 0; $i < $strlen; $i++)
  49.             {
  50.             $v = substr($this->str, $i, 1);
  51.             $value = ord($v);
  52.             if ($value == 255)
  53.                 {
  54.                 return $i;
  55.                 }
  56.             }
  57.         }
  58.  
  59.     // Remove the ID3 tags
  60.  
  61.     function striptags()
  62.         {
  63.  
  64.         // Remove start stuff...
  65.  
  66.         $newStr = '';
  67.         $s = $start = $this->getStart();
  68.         if ($s === false)
  69.             {
  70.             return false;
  71.             }
  72.           else
  73.             {
  74.             $this->str = substr($this->str, $start);
  75.             }
  76.  
  77.         // Remove end tag stuff
  78.  
  79.         $end = $this->getIdvEnd();
  80.         if ($end !== false)
  81.             {
  82.             $this->str = substr($this->str, 0, (strlen($this->str) - 129));
  83.             }
  84.         }
  85.  
  86.     // Display an error
  87.  
  88.     function error($msg)
  89.         {
  90.  
  91.         // Fatal error
  92.  
  93.         die('<strong>audio file error: </strong>' . $msg);
  94.         }
  95.  
  96.     // Send the new mp3 to the browser
  97.  
  98.     function output($path)
  99.         {
  100.  
  101.         // Output mp3
  102.         // Send to standard output
  103.  
  104.         if (ob_get_contents()) $this->error('Some data has already been output, can\'t send mp3 file');
  105.         if (php_sapi_name() != 'cli')
  106.             {
  107.  
  108.             // We send to a browser
  109.  
  110.             header('Content-Type: audio/mpeg3');
  111.             if (headers_sent()) $this->error('Some data has already been output to browser, can\'t send mp3 file');
  112.             header('Content-Length: ' . strlen($this->str));
  113.             header('Content-Disposition: attachment; filename="' . $path . '"');
  114.             }
  115.  
  116.         echo $this->str;
  117.         return '';
  118.         }
  119.     }
  120.  
  121. // First File: (Google speech)
  122.  
  123. $mp3 = new mp3('1.mp3');
  124. $mp3->striptags();
  125.  
  126. // Second file
  127.  
  128. $second = new mp3("2.mp3");
  129. $mp3->mergeBehind($second);
  130. $mp3->striptags();
  131. $mp3->output('word.mp3'); //Output file (current a blank file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement