如何下载Locale TTS

问题描述 投票:0回答:1

我想问一下如何根据输入的文本添加按钮来下载音频。如果没有可能这样做,任何建议?附上了我提出的代码。

<script src="http://code.jquery.com/jquery-1.12.1.js"></script>
<script src="http://code.responsivevoice.org/responsivevoice.js"></script>
<div class="col-md-4">
  <div class="form-group{{ $errors->has('dia_final') ? ' has-error' : '' }}">
    <label>Mensaje</label>
    <div class="input-group">
      <input type="text" name="text">
      <a href="#" class="say">Escuchar Texto!</a>
    </div>
    <audio src="" hidden class=speech></audio>
    <script>
      $("a.say").on('click', function(e) {
        e.preventDefault();
        var text = $("input[name=text]").val();
        responsiveVoice.speak(text, "Spanish Female");
        text = encodeURIComponent(text);
        var url = "http://"
      })
    </script>
  </div>
</div>
</div>
javascript download google-api text-to-speech
1个回答
0
投票

端点http://responsivevoice.org/responsivevoice/getvoice.php将满足您的要求。例如,URL https://code.responsivevoice.org/getvoice.php?t=hello%20world&tl=en-US分配音频问候世界。

通过纯客户端脚本实现一键下载的普通解决方案是使用AJAX获取音频文件,将其转换为对象URL并使用锚元素来触发下载。

但是,由于端点是在没有CORS头的情况下提供的,因此需要使用等效于https://cors-anywhere.herokuapp.com/的服务。

我在https://jsfiddle.net/u2chbxq7/起草了一个标本,作为路线图。

© www.soinside.com 2019 - 2024. All rights reserved.