PHP七牛云音频拼接

101 阅读1分钟
    public function audioSplicing()
    {
        // 这里是字符串
        $content = '';
        $sound_duration = 0;
        $content = explode(',',$content);
        $config = [
            'accessKey' => 'oRCqsxUSL9ix10Z***',
            'secretKey' => 'VINTNq3r***',
            'bucket' => 'huyanluanyuapp',
            'cdnurl' => 'http://huyanluanyuapp.qiniu.***.cn'
        ];
        if(count($content) > 1){
            // 构建鉴权对象
            $auth = new Qiniu\Auth($config['accessKey'], $config['secretKey']);
            $obj = new \Qiniu\Processing\PersistentFop($auth);
            $image_key = ltrim(str_replace($config['cdnurl'],'',$content[0]), '/'); // 这里是第一段音频的地址不带域名
            $fops = 'avconcat/1/format/mp3';
            foreach ($content as $key => $audio){
                $sound_avinfo = json_decode(file_get_contents($audio. '?avinfo'), true); // 获取音频元信息
                $sound_duration += $sound_avinfo['format']['duration'];
                if($key > 0){
                    $fops .= '/'.\Qiniu\base64_urlSafeEncode($audio);// 拼接(转码)的全路径
                }
            }
            $fops .= '|saveas/'.\Qiniu\entry($config['bucket'], $image_key);
            list($id, $err) = $obj->execute($config['bucket'],$image_key,$fops,null,null,1);
        }else{
            $sound_avinfo = json_decode(file_get_contents($content[0] . '?avinfo'), true); // 获取音频元信息
            $sound_duration += $sound_avinfo['format']['duration'];
        }
        $content = str_replace($config['cdnurl'],'',$content[0]).'?v='.mt_rand(100000,999999);
    }