【发布时间】:2022-01-22 08:59:38
【问题描述】:
我发现了 Azure 认知语音 TTS 服务的问题; 自 2022 年 1 月起,Azure 认知语音 TTS API 无法在 Windows 8/8.1/Server 2012/Server2012R2 上运行。
我使用 Microsoft Cognitive Services Speech SDK 制作了一个程序,它在 Windows 8/8.1/Server2012/Server2012R2 以及 Windows 10/Server 2019 上运行良好。
我确认至少在 2021 年 11 月 30 日之前有日志可以正常工作。 但是,它今天不起作用。
所以,我用 Microsoft.CognitiveServices.Speech.csharp nuget 包做了一个简单的示例。
我的示例代码如下;
public static async Task SynthesisToAudioFileAsync(string text, string outputFileName)
{
var config = SpeechConfig.FromSubscription("xxxxx", "westus2");
config.SpeechSynthesisLanguage = "ko-KR";
config.SetSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3);
config.SpeechSynthesisVoiceName = "ko-KR-SunHiNeural";
using (var fileOutput = AudioConfig.FromWavFileOutput(outputFileName))
{
using (var synthesizer = new SpeechSynthesizer(config, fileOutput))
{
var result = await synthesizer.SpeakTextAsync(text);
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to [{outputFileName}]");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
else
{
Console.Write(result.Reason.ToString());
}
}
}
}
它在 Windows 10/Server2019 上运行良好,没有错误。 但是,它不适用于 Windows 8、/8.1/Server 2012/Server2012R2。 当然,我完全执行了 windows update。
错误信息如下;
CANCELED: Reason=Error
CANCELED: ErrorCode=ConnectionFailure
CANCELED: ErrorDetails=[Connection failed (no connection to the remote host). In
ternal error: 11. Error details: Code: 0. USP state: 2. Received audio size: 0 b
ytes.]
CANCELED: Did you update the subscription info?
我怀疑它可能是 TLS 1.2 问题并尝试如下;
-
我将 Microsoft.CognitiveServices.Speech.csharp nuget 包更改为多个版本 - 1.14、1.13 和 1.19(最新版本),但它不起作用。
-
根据许多谷歌搜索结果,我尝试在 Windows 8.1/Server2012 上启用 TLS 1.2; https://github.com/MicrosoftDocs/memdocs/blob/main/memdocs/configmgr/core/plan-design/security/includes/update-net-framework-to-support-tls-1-2.md https://hide.me/en/knowledgebase/how-to-enable-tls-1-1-tls-1-2-in-windows-7-and-8/ https://docs.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client
和其他许多帖子。
但是,它不起作用。
- 我下载了 Cognitive-Speech-TTS 示例 (Cognitive-Speech-TTS-master.zip) 并在旧文件夹中运行 C# 示例。 https://github.com/Azure-Samples/Cognitive-Speech-TTS
它不使用 Azure SDK 并在底层实现 https REST API。所以我可以查看和更改代码。
它也适用于 Windows 10,但不适用于 Windows 81./Server2012,如下错误消息;
Starting TTSSample request code execution.
Unhandled Exception: System.AggregateException: One or more errors occurred. --->
System.Net.Http.HttpRequestException: An error occurred while sending the request. --->
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
我确认令牌 API (https://westus2.api.cognitive.microsoft.com/sts/v1.0/issueToken) 调用良好,但未调用语音 API (https://westus2.tts.speech.microsoft.com/cognitiveservices/v1) 并显示错误消息。
根据错误信息,似乎是 TLS 1.2 问题。
所以,我添加到以下行;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
在 Windows 10 以及 Windows 8.1/Server2012 上,错误消息变为如下所示
Starting Authtentication
Unhandled Exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. --->
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
这是预期的行为,因为我强制使用 TLS 1.1。 然而,错误发生在认证步骤,与上面的结果相反——上面的测试通过了认证。
因此,我的 Windows 81./server2012 上可能启用了 TLS 1.2,因为根据上述测试结果,令牌 Uri 可能需要 TLS 1.2。
我厌倦了认知服务-语音-sdk-master 中的语音识别 C# 示例。
https://github.com/Azure-Samples/cognitive-services-speech-sdk
它在 Windows 81./Server2012 和 Windows 10 上运行良好。
MS 文档说 Azure 认知服务需要 TLS 1.2。
如果 TLS 1.2 在我的 Windows 8.1/Server2012 上不可用,则所有 Azure 认知服务 API 都必须失败。
但是,只有 TTS API 失败。
此外,它至少一直工作到 2021-11 年。
我已经尝试了几乎所有我能做的事情,但都失败了。
最后我怀疑 Azure Cognitive TTS 系统在 2021 年底可能会有一些变化,它可能会导致与 Windows 8/8.1/Server2012/Server2012R2 的 TLS 连接相关的问题。
事实上,这个问题是在我客户的机器上报告的,由于许多原因,将 Windows 操作系统升级到 Windows10/Server2019 不是一个选项。 所以,我必须在 Windows 8/8.1/Server2012/Server2012R2 上找到解决方法。
您能告诉我如何解决这个问题吗?
最好的问候。
附言
我使用 WireShark 捕获了 Cognitive-Speech-TTS C# 示例的网络数据包,并确认使用了 TLS 1.2。
第一次握手以检索令牌 (westus2.api.cognitive.microsoft.com - 20.51.8.244) 成功,但与 Azure 认知 TTS 服务 (westus2.tts.speech.microsoft.com - 20.51.12.193) 的第二次握手失败以下消息;
TLSv1.2 Record Layer: Handshake Protocol: Client Hello
TLSv1.2 Record Layer: Alert (Level: Fatal, Description: Handshake Failure).
我在 Windows 10 上进行了测试,所有 TLS 1.2 握手都使用相同的测试控制台程序成功。
我添加了以下代码以忽略证书验证,但它不起作用;
ServicePointManager.ServerCertificateValidationCallback += (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) =>
{
return true;
};
【问题讨论】:
-
我会使用像 wireshark 这样的嗅探器来查看正在使用的 TLS 版本。最好的解决方案是使用 Net 4.7.2 或更高版本,它默认在操作系统而不是 Net 中使用 TLS。旧版本的 Net 不支持 TLS 的所有加密模式。然后确保服务器已更新为使用 TLS 1.2 或 1.3(SSL、TLS 1.0、TLS 1.1 已过时)。使用 TLS,有一个证书块从服务器发送到客户端,其中包含可用于连接的证书列表。客户端然后在存储中查找证书名称。如果找不到证书,您将失败。
-
@jdweng 我已阅读您所说的帖子并尝试将目标 .NET Framework 更改为 4.8 并删除分配 ServicePointManager.SecurityProtocol 以使用操作系统默认 TLS 版本,并添加证书处理程序以忽略证书验证但它也没有用。我也有可疑的证书问题,但证书问题会产生不同的错误消息,其中包含“证书”文本。我在其他项目中遇到了同样的错误消息,它是由 TLS 版本问题引起的,并已通过设置 ServicePointManager.SecurityProtocol 解决。
-
@jdweng 我已将帖子关联到 Azure 证书 - stackoverflow.com/questions/65582772/… 如果是证书问题,Azure 认知语音识别 API 肯定会失败,但它确实有效。此外,Azure TTS API 一直工作到 2021 年底。我将调查证书问题和其他 TLS 问题,但我认为这可能是由 Azure 服务器引起的,而不是客户端。感谢您的回复,我会尝试使用wireshark。
-
我使用 WireShark 捕获网络数据包并确认使用了 TLS 1.2。检索令牌的第一次握手成功,但与 Azure 认知 TTS 服务的第二次握手失败并显示消息 - TLSv1.2 记录层:警报(级别:致命,说明:握手失败)。我在 Windows 10 上进行了测试,所有 TLS 1.2 握手都使用相同的测试控制台程序成功。
标签: c# azure azure-cognitive-services