javascript - 如何下载语言环境 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>
解决方案
端点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/上起草了一份样本,作为路线图。
推荐阅读
- docker - zlib can't be found by make
- postgresql - question about PostgreSql update with subquery in concurrent scenarios
- python - 有没有什么简单的方法可以过滤出日出后日落前的时间序列天气数据?
- qt - 如何在 qml 的 3d 彩色立方体中选择颜色?
- python - BeautifulSoup:获取未出现在 html 中的表?
- sql - 如何使用 DB2 sql 检查不在两个表中的记录以获取另一个第三个表中的日期?
- firebase - 谷歌云(firebase)可调用函数401:http调用时出现“未经授权”错误
- javascript - Object.defineproperty() 与 Object.defineproperties()
- c++ - 已解决:来自 opencv 的 RGBD.hpp 文件的未定义参考错误
- python - 重采样日期以计算每个驾驶员每 1 分钟的平均速度,而不是计算平均(速度)< 23 公里/小时