php - 将base64转换为php音频文件中的声音文件

标签 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代码base64创建者:
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");

    };

最佳答案

试试这个 :

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

关于php - 将base64转换为php音频文件中的声音文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41651980/

相关文章:

php - mysql语句获取给定行id在有序结果集中的排名

c - 如何在 C 中将图像转换为 base64?

php - MySQL 仅针对特定日期的无效日期时间格式

javascript - 如何从php中的数据库完整路径名中获取每个用户的图像

php - php/apache 中的多线程

java - 如何使用 android studio 让 1 个按钮在每次按下按钮时播放随机声音

actionscript-3 - 了解soundMixer.computeSpectrum

html - 奇怪的WebRTC SinkID问题

html - 将 Gif 图像转换为 Base64,同时保留循环计数

html - JS 树 : Change Icon using CSS not accepting the base64 image code