将音频文件附加到自动电子邮件

时间:2020-08-16 21:11:34

标签: javascript audio mailto

在过去的两个月里,我一直在学习html和js,所以我对这一切还是陌生的。

我的一个朋友是一名声乐教练,并用clickfunnels.com创建了一个网站。他希望合并一个录音机,以便用户可以唱歌和录制一个30秒的音频文件,以便以后可以访问以提供声音。免费签名评估。

clickfunnels网站仅接受html,css和js,因此我编辑了从另一个朋友那里获得的一些代码,并在他的网站上实现了录音机。现在唯一的问题是我不知道如何将此音频文件发送到朋友的计算机上。我尝试了mailto:链接,但是找不到附加音频文件的方法。另一个问题是,这需要用户手动发送电子邮件。

那么,有没有一种方法可以将音频文件附加到自动发送出去的电子邮件中,而无需用户自己发送?有更好的解决方案吗?

谢谢

PS,我忘了提到clickfunnles网站不允许将音频文件上传到他们的服务器,这就是为什么我正在研究通过电子邮件发送音频文件的可能性。

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Recorder</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
  <h1>Voice Recorder</h1>
  <div id="controls">
    <button id="recordButton">Record</button>
    <button id="stopButton" disabled>Stop</button>
  </div>
  <ol id="recordingsList"></ol>

  <script type="text/javascript">

    URL = window.URL || window.webkitURL;

    var gumStream;
    var rec;
    var input;

    var AudioContext = window.AudioContext || window.webkitAudioContext;
    var audioContext

    var recordButton = document.getElementById("recordButton");
    var stopButton = document.getElementById("stopButton");

    recordButton.addEventListener("click", startRecording);
    stopButton.addEventListener("click", stopRecording);

    function startRecording() {
      console.log("recordButton clicked");

      var constraints = {
        audio: true,
        video: false
      }

      recordButton.disabled = true;
      stopButton.disabled = false;

      navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
        console.log("getUserMedia() success, stream created, initializing Recorder.js ...");

        audioContext = new AudioContext();

        gumStream = stream;

        input = audioContext.createMediaStreamSource(stream);

        rec = new Recorder(input, {
          numChannels: 1
        })

        rec.record()

        console.log("Recording started");

      }).catch(function(err) {
        recordButton.disabled = false;
        stopButton.disabled = true;
      });
    }

    function stopRecording() {
      console.log("stopButton clicked");

      stopButton.disabled = true;
      recordButton.disabled = false;

      rec.stop();

      gumStream.getAudioTracks()[0].stop();

      rec.exportWAV(createDownloadLink);
    }

    function createDownloadLink(blob) {

      var url = URL.createObjectURL(blob);
      var au = document.createElement('audio');
      var li = document.createElement('li');
      var link = document.createElement('a');

      var filename = new Date().toISOString();

      au.controls = true;
      au.src = url;

      link.href = url;
      link.download = filename + ".wav";
      link.innerHTML = "Save to disk";

      li.appendChild(au);

      li.appendChild(document.createTextNode(filename + ".wav "))

      li.appendChild(link);

      var upload = document.createElement('a');
      upload.href = "#";
      upload.innerHTML = "Upload";
      upload.addEventListener("click", function(event) {
        var xhr = new XMLHttpRequest();
        xhr.onload = function(e) {
          if (this.readyState === 4) {
            console.log("Server returned: ", e.target.responseText);
          }
        };
        var fd = new FormData();
        fd.append("audio_data", blob, filename);
        xhr.open("POST", "upload.php", true);
        xhr.send(fd);
      })
      li.appendChild(document.createTextNode(" "))
      li.appendChild(upload)

      recordingsList.appendChild(li);
    }
  </script>

  <script src="https://cdn.rawgit.com/mattdiamond/Recorderjs/08e7abd9/dist/recorder.js"></script>

</body>

</html>

0 个答案:

没有答案