将base64转换为声音文件,php音调声音沙沙作响

时间:2017-01-14 15:59:33

标签: php audio base64

我将php中的Base64字符串转换为mp3声音文件但生成的文件wav已损坏

转换音之前是沙沙声

例如转换的语音文件:

http://vocaroo.com/i/s1Dlol5Wu3Zo

php代码:

<?php 



if(isset($_POST['audio'])){

$data = str_replace('data:audio/wav;base64,', '', $_POST['audio']); 

 $data = base64_decode($data);

$track_name =   get_random_string(mt_rand(6,10)) . ".mp3";

$upl_dir    =    "../up/" . $track_name;

if( !file_put_contents($upl_dir, $data) ){

    $response['status']     =   1;

    $response['message']    =   "File could not be uploaded. Try again >later.";

echo $data;

echo "E1";

}

echo $data;

}

我在转换之前测试声音并且是对的。

Base64代码:

https://ufile.io/174101

js code base64 creator:

function base641()
    {

         Fr.voice.export(function(url){
    // console.log("Here is the base64 URL : " + url);
       base = url;
       ejem2 = 1;
     // alert("Check the web console for the URL");
     // $("<a href='"+ url +"' target='_blank'></a>")[0].click();

    }, "base64");

    };

1 个答案:

答案 0 :(得分:1)

试试这个:

file_put_contents('audio.mp3', base64_decode($data));