azure - 使用文本到语音 (TTS) 天蓝色认知服务时出现 CORS 错误
问题描述
我使用了来自 azure 的 TTS(文本到语音)认知服务,使用的库是 python azure-cognitiveservices-speech == 1.17.0 我最初尝试并将其部署在 Heroku 云中,它按预期工作。
但是,当我在 VM 中部署它时,我收到了 CORS 错误。我的 CORS 设置正确,我尝试允许所有也没有帮助的主机('*')(我的后端是 Django)
speech_key = settings.SPEECH_KEY
service_region = settings.SERVICE_REGION
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_synthesis_voice_name = "ar-SA-Naayf"
filename = './audio.wav'
filename = filename.replace('.wav', '_' + str(random.randint(10, 10000)) + '.wav')
audio_file_path = Path(str(filename)).resolve()
audio_config = AudioOutputConfig(filename=str(audio_file_path))
# Creates a speech synthesizer using the default speaker as audio output.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
# Receives a text from console input.
text = "Hello World"
result = speech_synthesizer.speak_text_async(text).get()
在我用于 CORS 的 prod.py 中
ALLOWED_HOSTS = ['api.abc.com']
在我的 CORS 的 settings.py 中
# Cors Header
# Allowed cors headers
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = ('Authorization', 'Content-Type', 'Cache-Control', 'X-Requested-With')
错误 :
Access to XMLHttpRequest at 'https://api.abc.com/tts/' from origin 'https://api-dev.abc.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我应该研究或更改配置的任何设置?
解决方案
推荐阅读
- r - 从 R 中的绘图中提取 Y 值
- kdb - KDB - 从服务器中清除函数、变量、表而不退出或重新启动服务
- python - 如何使用上一个/当前/下一个从列表中获取唯一值?
- html - Django 管理员 - 无法更改
- node.js - req.headers.cookie 未定义
- function - 柏树 | 有没有办法让“it”测试从最后一个“it”测试结束的地方开始?
- python - 遍历列表,如果在其他列表中找不到,则不返回
- jax-rs - 无法使用 JAX-RS Invocation Builder 调用带有表单参数的 API,返回 400 状态代码
- python - 如何在 Django 中创建模型后将模型分配给所有用户?
- javascript - 为什么这个简单的 JS 视频播放器不起作用?