php小程序上传视频到七牛,百度合成语音文件直接上传到七牛

$file = $_SERVER[‘DOCUMENT_ROOT’].’/data/makevoicebaidutoken.txt’;

$modifytime = filemtime($file);

$resp = file_get_contents($file);

$res = json_decode($resp,true);

if(time()>($modifytime+$res[‘expires_in’]-500)){

$resp = file_get_contents(“https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=Glg9WjlKApIOCzNpna9eZWxR&client_secret=Z68xhe8kGzzcgwLhcEwM8332GBK3inmd”);

file_put_contents($file,$resp);

$res = json_decode($resp,true);

}

$access_token = $res[‘access_token’];

$url = “http://tsn.baidu.com/text2audio?tex=”.urlencode($data[‘voicetext’]).”&lan=zh&cuid=00-01-6C-06-A6-29-“.$this->member_id.”&ctp=1&tok=”.$access_token.”&spd=”.$data[‘spd’].”&pit=”.$data[‘pit’].”&vol=”.$data[‘vol’].”&per=”.$data[‘person’];

if($_POST[‘trystr’]==’trystr’){

$this->ajaxreturn(array(‘type’=>”trystr”,”msg”=>”试听”,’url’=>$url));

}

$name = $this->member_id.’_’.rand(1,10000).’_’.date(“YmdHis”).rand(1,10000).’.mp3′;

/* $audiodir = $_SERVER[‘DOCUMENT_ROOT’].’/mp3/’;

$audiofile = $audiodir.$name;

chmod($audiodir,0777);

$resps = file_get_contents($url);

chmod($audiofile,0777);

file_put_contents($audiofile,$resps,true);*/

//直接上传到七牛

// $url = “http://”.$_SERVER[‘HTTP_HOST’].’/mp3/’.$name;

$access_key = Config::AK;

$secret_key = Config::SK;

$fetch = urlsafe_base64_encode($url);

$to = urlsafe_base64_encode(Config::BUCKET_AUDIO_NAME.’:’.$name); //格式为 news2v:123.jpg

$url = ‘http://iovip.qbox.me/fetch/’. $fetch .’/to/’ . $to;

$access_token = generate_access_token($access_key, $secret_key, $url);

$header[] = ‘Content-Type: application/json’;

$header[] = ‘Authorization: QBox ‘. $access_token;

$curl = curl_init(‘iovip.qbox.me/fetch/’.$fetch.’/to/’.$to);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HEADER,1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_TIMEOUT,60);

$con = curl_exec($curl);

$res =  APP_AUDIO.’/’.$name;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值