首页 > 解决方案 > 如何下载语言环境 TTS

问题描述

我想问你如何根据输入的文本添加一个按钮来下载音频。如果没有这样做的可能性,有什么建议吗?附上我先进的代码。

<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>

标签: javascriptdownloadgoogle-apitext-to-speech

解决方案


端点http://responsivevoice.org/responsivevoice/getvoice.php应满足您的要求。例如,URLhttps://code.responsivevoice.org/getvoice.php?t=hello%20world&tl=en-US分配了音频hello world

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

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

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


推荐阅读