我想问一下如何根据输入的文本添加按钮来下载音频。如果没有可能这样做,任何建议?附上了我提出的代码。
<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>
端点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/起草了一个标本,作为路线图。