【问题标题】:Azure Text to Speech started returning "400 Bad Request" all the suddenAzure Text to Speech 突然开始返回“400 Bad Request”
【发布时间】:2019-09-26 21:28:47
【问题描述】:

几个月来,我以这种格式成功使用了 Azure Text-to-Speech API:

<speak version='1.0' xmlns='w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>My text</voice></speak>

但是突然这个请求开始返回:

HTTP/1.1 400 错误请求

几个月来我们一直在成功使用同一个请求(当然使用不同的短语),但就在几周前,同一个请求开始返回此错误。我没有得到任何额外的信息,所以我不知道去哪里找。 Azure 文档说:

必需的参数缺失、为空或为空。或者,传递的值 无论是必需参数还是可选参数都是无效的。一个常见的问题 是一个太长的标题。

我还尝试通过添加性别和语言并将单引号替换为双引号来使请求更具体,但没有用:

<speak version="1.0" xmlns="w3.org/2001/10/synthesis" xml:lang="fi-FI" xml:gender="Female"><voice name="Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)">Text.</voice></speak>

API 有什么变化吗?或者我的请求中缺少什么?

【问题讨论】:

    标签: azure azure-cognitive-services


    【解决方案1】:

    当我发送以下有效负载时,我得到了正确内容的 200 OK:

    <speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>This is my test</voice></speak>
    

    这是我发送这个的 C# 代码:

    // Generate request
    string body = $@"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='{voiceLang}'><voice name='{voiceName}'>{text}</voice></speak>";
    
    using (var client = new HttpClient())
    {
        using (var request = new HttpRequestMessage())
        {
            // Set the HTTP method
            request.Method = HttpMethod.Post;
            // Construct the URI
            request.RequestUri = new Uri(ttsHostUri);
            // Set the content type header
            request.Content = new StringContent(body, Encoding.UTF8, "application/ssml+xml");
            // Set additional header, such as Authorization and User-Agent
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            request.Headers.Add("Connection", "Keep-Alive");
            // Update your resource name
            request.Headers.Add("User-Agent", "YOUR_RESOURCE_NAME");
            request.Headers.Add("X-Microsoft-OutputFormat", "riff-24khz-16bit-mono-pcm");
            // Create a request
            using (var response = await client.SendAsync(request).ConfigureAwait(false))
            {
                response.EnsureSuccessStatusCode();
    
                // Asynchronously read the response
                using (var dataStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                {
                    // ... Process your audio here
                }
            }
        }
    }
    

    我可以在我们的有效负载上看到的唯一区别是 xmlns 值,其中我有一个完整的 url(带有 http://),而你的却没有。

    错误可能出在其他地方:您确定在查询端点时正在对自己进行身份验证吗?

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多