我尝试构建一个函数来读取彼此之间具有定义延迟的数字。
{
...
play : function (digits, delay = 500) {
if (digits && digits.length > 0) {
responsiveVoice.speak(digits[0], "Czech Female", {
rate: 0.7,
onend: () => setTimeout(() => {
this.play(digits.splice(1), delay);
}, delay)
});
}
}
digits
是一个数字数组和数字delay
之间的毫秒延迟。
该功能可以正常工作一段时间,但随机失败,控制台中出现以下错误:
从源“http://”访问“https://texttospeech.responsivevoice.org/v1/text:synthesize?text=0&lang=cs&engine=g1&name=&pitch=0.5&rate=0.35&volume=1&key=XXXXXXXX&gender=female”的 XMLHttpRequest localhost:8080' 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。无法加载 ResponsiveVoice 音频。将您的浏览器连接到 API 端点时出现问题。获取https://texttospeech.responsivevoice.org/v1/text:synthesize?text=0&lang=cs&engine=g1&name=&pitch=0.5&rate=0.35&volume=1&key=XXXXXXXX&gender=female net::ERR_FAILED
谁能给我一个提示有什么问题?