Запишите аудио и экспортируйте его в папку: WebAudioRecorder. js API - PullRequest
0 голосов
/ 06 мая 2020
• 1000 js:
var recorder, gumStream;
function toggleRecording() {
   if (recorder && recorder.state == "recording") {
  recorder.stop();
  gumStream.getAudioTracks()[0].stop();
  } else {
      navigator.mediaDevices.getUserMedia({
      audio: true
  }).then(function(stream) {
      gumStream = stream;
      recorder = new MediaRecorder(stream);
      recorder.ondataavailable = function(e) {
          var url = URL.createObjectURL(e.data);
          var preview = document.createElement('audio');
          preview.controls = true;
          preview.src = url;
          document.body.appendChild(preview);
          console.log(preview);
          var filename = new Date().toISOString();
          var fd=new FormData();
          fd.append("audio",e.data,filename);
          $.ajax({
              type: 'POST',
              url: 'http://localhost/audio/uploads',
              data: e.data,
              processData: false,
              contentType: false
          }).done(function(data) {
                 $("#save").submit();
          });

      };
      recorder.start();
  });
}
}

и вот моя html часть:

image

вот моя загрузка. php код:

<?php
if(isset($_POST['save_audio'])){
$dir="http://localhost/audio/uploads";
$audio_path=$dir.basename($_FILES['audio']['name']);
if(move_uploaded_file($_FILES['audio']['tmp_name'],$audio_path)){
  echo 'upload successfully';
}
}
?>

и вот что я получаю в консоли:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /audio/uploads</title>
 </head>
 <body>
<h1>Index of /audio/uploads</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="/audio/">Parent Directory</a>       </td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>

Можете ли вы помочь мне понять, как сохранить звук в локальную папку?

...