Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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
如何从JavaScript blob保存与python兼容的音频文件_Javascript_Python_Django_Audio_Ffmpeg - Fatal编程技术网

如何从JavaScript blob保存与python兼容的音频文件

如何从JavaScript blob保存与python兼容的音频文件,javascript,python,django,audio,ffmpeg,Javascript,Python,Django,Audio,Ffmpeg,我正在尝试将音频块保存到后端。 这是一个音频块 const blob = new Blob(chunks, { 'type' : 'audio/wav; codecs=0' }); 这里是上传功能 function uploadAudio( blob ) { var reader = new FileReader(); reader.onload = function(event){ var fd = {}; fd["data"] = event.

我正在尝试将音频块保存到后端。 这是一个音频块

 const blob = new Blob(chunks, { 'type' : 'audio/wav; codecs=0' });
这里是上传功能

function uploadAudio( blob ) {
  var reader = new FileReader();
  reader.onload = function(event){
    var fd = {};
    fd["data"] = event.target.result;
    $.ajax({
     // contentType:"application/x-www-form-urlencoded; charset=UTF-8",
      type: 'POST',
      url: 'testing/',
      data: fd,
      dataType: 'text'
    }).done(function(data) {
        console.log(data);
        document.getElementById("response").innerHTML=data;
       // alert(data);
    });
  };
下面是保存文件的函数

def upload_audio(request):
    print('upload_audio')
    if request.is_ajax():
        
        req=request.POST.get('data')
        d=req.split(",")[1]
        print("Yes, AJAX!")
        #print(request.body)
        f = open('./file.wav', 'wb')
        
        f.write(base64.b64decode(d))
        #f.write(request.body)
        f.close()
    return HttpResponse('audio received')
当我试图用python阅读它以转换为文本时。我犯了以下错误

ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
Traceback (most recent call last):
  File "script.py", line 8, in <module>
    ffmpeg.run(stream)
  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 320, in run
    overwrite_output=overwrite_output,
  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 285, in run_async
    args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 1017, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
我试图转换文件

import ffmpeg
stream = ffmpeg.input('file.wav')
stream = ffmpeg.output(stream, 'filen.wav')
ffmpeg.run(stream)
我犯了以下错误

ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format
Traceback (most recent call last):
  File "script.py", line 8, in <module>
    ffmpeg.run(stream)
  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 320, in run
    overwrite_output=overwrite_output,
  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 285, in run_async
    args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 1017, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
回溯(最近一次呼叫最后一次):
文件“script.py”,第8行,在
ffmpeg.run(流)
文件“C:\Anaconda3\envs\VA\lib\site packages\ffmpeg\\u run.py”,第320行,运行中
覆盖输出=覆盖输出,
文件“C:\Anaconda3\envs\VA\lib\site packages\ffmpeg\\u run.py”,第285行,运行异步
args,stdin=stdin\u流,stdout=stdout\u流,stderr=stderr\u流
文件“C:\Anaconda3\envs\VA\lib\subprocess.py”,第729行,在\uuu init中__
恢复信号,启动新会话)
文件“C:\Anaconda3\envs\VA\lib\subprocess.py”,第1017行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件