文本到语音 - 没有在 .wav 中获取音频连接被拒绝

问题描述

我运行一个 Flask 服务器,每当页面上发生特定操作时都会调用函数

def generate_audio(text,target):
    # create the path
    tmp_dir = os.path.join(os.getcwd(),"app/data/audio")
    if not os.path.exists(tmp_dir):
        os.mkdir(tmp_dir)
    path = os.path.join(tmp_dir,f'{target}-{text}.wav')

    # query the API
    speech_config = SpeechConfig(
        subscription=cfg['speech']['key'],region=cfg['speech']['location'])
    audio_config = AudioOutputConfig(filename=path)
    synthesizer = SpeechSynthesizer(
        speech_config=speech_config,audio_config=audio_config)
    synthesizer.speak_text("A simple test")

在执行结束时,包含音频的文件只是一个空的 0B 文件。我从字面上复制粘贴了快速入门指南,所以我不知道有什么问题。

我所做的尝试是将订阅密钥更改为随机的并且没有出现错误。在 azure 服务网页的日志中也没有出现任何内容

这是取消详情

SpeechSynthesisCancellationDetails(reason=CancellationReason.Error,error_details="Connection Failed (no connection to the remote host). Internal error: 11. Error details: Code: 0. USP state: 2. Received audio size: 0 bytes.")

这是日志

https://pastebin.com/aapsMXYc

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)