PHP七牛云音频拼接
PHP使用七牛云拼接音频(avconcat)获取音频元信息(avinfo)
完整代码 拿来即用,输出结果自行判断
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);}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
