php base64 语音,如何在php中解码base64 audiodata字符串后获得清晰的语音

我开发了一个演示应用程序,用于将音频文件从ios应用程序上传到服务器。

Bellow是我的swift代码将audiofile数据转换为base64字符串

let url = URL(string: "https://localhost/development/uploadAudio.php")

let path:NSArray = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as NSArray

let documentDirectory: AnyObject = path.object(at: 0) as AnyObject

var fileName = "audio.mp3"

filePath = documentDirectory.appendingPathComponent(fileName as String)

print(URL(fileURLWithPath: "\(filePath)"))

var fileData = try! Data(contentsOf: URL(fileURLWithPath: filePath))

var data:String = (fileData.base64EncodedString(options: .lineLength64Characters))

let request = NSMutableURLRequest(url:url!);

request.httpMethod = "POST"

let post:NSString = "subjective=\(data)" as NSString

let postData:Data = post.data(using: String.Encoding.utf8.rawValue)!

let postLength:NSString = String(postData.count) as NSString

request.httpBody = postData

request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")

request.setValue("application/json", forHTTPHeaderField: "Accept")

_ = URLSessionConfiguration.default

let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in

let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)

if error != nil{

print("error is : \(error!)")

}

print("Response is : \(responseString!)")

})

task.resume()在PHP中,我在php中获得了这些数据的价值

在波纹管代码中

public function saveRecordedVoice()

{

$audio = $_POST['data'];

$decoded = base64_decode($audio);

$file_location = "assets/records/recorded_audio.mp3";

$success = file_put_contents($file_location, $decoded);

if($success){

echo "File Saved";

}else{

echo "Uh-uh!";

}

}这里我将数据保存在各自的文件夹文件中作为“recorded_audio.mp3”

但是当我在音频播放器中播放此文件时,我没有得到清晰的语音音频文件。

我怎样才能做到这一点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值