Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中解码base64音频数据字符串后获得清晰的语音_Php_Ios_Swift_Audio - Fatal编程技术网

如何在php中解码base64音频数据字符串后获得清晰的语音

如何在php中解码base64音频数据字符串后获得清晰的语音,php,ios,swift,audio,Php,Ios,Swift,Audio,我开发了一个演示应用程序,用于将音频文件从ios应用程序上载到服务器 下面是我将音频文件数据转换为base64字符串的swift代码 let url = URL(string: "https://localhost/development/uploadAudio.php") let path:NSArray = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as NSArra

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

下面是我将音频文件数据转换为base64字符串的swift代码

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” 但当我在音频播放器中播放这个文件时,我并没有得到清晰的语音音频文件。 我该怎么做呢