文字轉換語音 REST APIText-to-speech REST API

語音服務可讓您將文字轉換成合成的語音, 並使用一組 REST api 取得區域的支援語音清單The Speech Services allow you to convert text into synthesized speech and get a list of supported voices for a region using a set of REST APIs. 每個可用的端點都會與某個區域相關聯。Each available endpoint is associated with a region. 您打算使用的端點/區域必須要有訂用帳戶金鑰。A subscription key for the endpoint/region you plan to use is required.

文字轉語音 API 支援類神經和標準文字轉語音,且各支援依地區設定所識別的特定語言和方言。The text-to-speech REST API supports neural and standard text-to-speech voices, each of which supports a specific language and dialect, identified by locale.

  • 如語音的完整清單,請參閱 語言支援For a complete list of voices, see language support.
  • 如需區域可用性的詳細資訊,請參閱區域For information about regional availability, see regions.

重要

標準、自訂和神經語音的成本各不相同。Costs vary for standard, custom, and neural voices. 如需詳細資訊,請參閱定價For more information, see Pricing.

使用此 API 之前, 請先瞭解:Before using this API, understand:

  • 文字轉語音 REST API 需要授權標頭。The text-to-speech REST API requires an Authorization header. 這表示需要完成權杖交換,才能存取服務。This means that you need to complete a token exchange to access the service. 如需詳細資訊,請參閱驗證For more information, see Authentication.

驗證Authentication

每個要求都需要一個 authorization 標頭。Each request requires an authorization header. 下表會列出各項服務支援的標頭:This table illustrates which headers are supported for each service:

支援的授權標頭Supported authorization headers 語音轉換文字Speech-to-text 文字轉換語音Text-to-speech
Ocp-Apim-Subscription-KeyOcp-Apim-Subscription-Key Yes No
Authorization:BearerAuthorization: Bearer Yes Yes

當使用 Ocp-Apim-Subscription-Key 標頭,只需要提供您的訂用帳戶金鑰。When using the Ocp-Apim-Subscription-Key header, you're only required to provide your subscription key. 例如:For example:

'Ocp-Apim-Subscription-Key': 'YOUR_SUBSCRIPTION_KEY'

使用 Authorization: Bearer 標頭時,需要對 issueToken 端點提出要求。When using the Authorization: Bearer header, you're required to make a request to the issueToken endpoint. 在此要求中,要以訂用帳戶金鑰交換有效期間 10 分鐘的存取權杖。In this request, you exchange your subscription key for an access token that's valid for 10 minutes. 在接下來的幾節中, 您將瞭解如何取得權杖, 並使用權杖。In the next few sections you'll learn how to get a token, and use a token.

如何取得存取權杖How to get an access token

若要取得存取權杖,您必須使用 Ocp-Apim-Subscription-Key 和您的訂用帳戶金鑰,對 issueToken 端點提出要求。To get an access token, you'll need to make a request to the issueToken endpoint using the Ocp-Apim-Subscription-Key and your subscription key.

以下為支援的區域與端點:These regions and endpoints are supported:

區域Region 權杖服務端點Token service endpoint
澳洲東部Australia East https://australiaeast.api.cognitive.microsoft.com/sts/v1.0/issueToken
加拿大中部Canada Central https://canadacentral.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國中部Central US https://centralus.api.cognitive.microsoft.com/sts/v1.0/issueToken
東亞East Asia https://eastasia.api.cognitive.microsoft.com/sts/v1.0/issueToken
East USEast US https://eastus.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國東部 2East US 2 https://eastus2.api.cognitive.microsoft.com/sts/v1.0/issueToken
法國中部France Central https://francecentral.api.cognitive.microsoft.com/sts/v1.0/issueToken
印度中部India Central https://centralindia.api.cognitive.microsoft.com/sts/v1.0/issueToken
日本東部Japan East https://japaneast.api.cognitive.microsoft.com/sts/v1.0/issueToken
南韓中部Korea Central https://koreacentral.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國中北部North Central US https://northcentralus.api.cognitive.microsoft.com/sts/v1.0/issueToken
北歐North Europe https://northeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國中南部South Central US https://southcentralus.api.cognitive.microsoft.com/sts/v1.0/issueToken
東南亞Southeast Asia https://southeastasia.api.cognitive.microsoft.com/sts/v1.0/issueToken
英國南部UK South https://uksouth.api.cognitive.microsoft.com/sts/v1.0/issueToken
西歐West Europe https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國西部West US https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken
美國西部 2West US 2 https://westus2.api.cognitive.microsoft.com/sts/v1.0/issueToken

使用以下範例建立您的存取權杖要求。Use these samples to create your access token request.

HTTP 範例HTTP sample

這個範例是可取得權杖的簡單 HTTP 要求。This example is a simple HTTP request to get a token. 使用您的語音服務訂用帳戶金鑰來取代 YOUR_SUBSCRIPTION_KEYReplace YOUR_SUBSCRIPTION_KEY with your Speech Service subscription key. 如果您的訂用帳戶不在美國西部區域,請以您區域的主機名稱取代 HostIf your subscription isn't in the West US region, replace the Host header with your region's host name.

POST /sts/v1.0/issueToken HTTP/1.1
Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY
Host: westus.api.cognitive.microsoft.com
Content-type: application/x-www-form-urlencoded
Content-Length: 0

回應的本文包含採用 JSON Web 權杖 (JWT) 格式的存取權杖。The body of the response contains the access token in JSON Web Token (JWT) format.

PowerShell 範例PowerShell sample

這個範例是簡單的 PowerShell 指令碼,用來取得存取權杖。This example is a simple PowerShell script to get an access token. 使用您的語音服務訂用帳戶金鑰來取代 YOUR_SUBSCRIPTION_KEYReplace YOUR_SUBSCRIPTION_KEY with your Speech Service subscription key. 請務必使用符合您訂用帳戶區域的正確端點。Make sure to use the correct endpoint for the region that matches your subscription. 此範例目前設為「美國西部」。This example is currently set to West US.

$FetchTokenHeader = @{
  'Content-type'='application/x-www-form-urlencoded';
  'Content-Length'= '0';
  'Ocp-Apim-Subscription-Key' = 'YOUR_SUBSCRIPTION_KEY'
}

$OAuthToken = Invoke-RestMethod -Method POST -Uri https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken
 -Headers $FetchTokenHeader

# show the token received
$OAuthToken

cURL 範例cURL sample

cURL 是 Linux (以及適用於 Linux 的 Windows 子系統) 中可用的命令列工具。cURL is a command-line tool available in Linux (and in the Windows Subsystem for Linux). 此 cURL 命令說明如何取得存取權杖。This cURL command illustrates how to get an access token. 使用您的語音服務訂用帳戶金鑰來取代 YOUR_SUBSCRIPTION_KEYReplace YOUR_SUBSCRIPTION_KEY with your Speech Service subscription key. 請務必使用符合您訂用帳戶區域的正確端點。Make sure to use the correct endpoint for the region that matches your subscription. 此範例目前設為「美國西部」。This example is currently set to West US.

curl -v -X POST
 "https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken" \
 -H "Content-type: application/x-www-form-urlencoded" \
 -H "Content-Length: 0" \
 -H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY"

C# 範例C# sample

此 C# 類別說明了如何取得存取權杖。This C# class illustrates how to get an access token. 在您具現化類別時,請傳遞您的語音服務訂用帳戶金鑰。Pass your Speech Service subscription key when you instantiate the class. 如果您的訂用帳戶不在美國西部區域,請變更 FetchTokenUri 的值以符合您訂用帳戶的區域。If your subscription isn't in the West US region, change the value of FetchTokenUri to match the region for your subscription.

public class Authentication
{
    public static readonly string FetchTokenUri =
        "https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken";
    private string subscriptionKey;
    private string token;

    public Authentication(string subscriptionKey)
    {
        this.subscriptionKey = subscriptionKey;
        this.token = FetchTokenAsync(FetchTokenUri, subscriptionKey).Result;
    }

    public string GetAccessToken()
    {
        return this.token;
    }

    private async Task<string> FetchTokenAsync(string fetchUri, string subscriptionKey)
    {
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
            UriBuilder uriBuilder = new UriBuilder(fetchUri);

            var result = await client.PostAsync(uriBuilder.Uri.AbsoluteUri, null);
            Console.WriteLine("Token Uri: {0}", uriBuilder.Uri.AbsoluteUri);
            return await result.Content.ReadAsStringAsync();
        }
    }
}

Python 範例Python sample

# Request module must be installed.
# Run pip install requests if necessary.
import requests

subscription_key = 'REPLACE_WITH_YOUR_KEY'


def get_token(subscription_key):
    fetch_token_url = 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken'
    headers = {
        'Ocp-Apim-Subscription-Key': subscription_key
    }
    response = requests.post(fetch_token_url, headers=headers)
    access_token = str(response.text)
    print(access_token)

如何使用存取權杖How to use an access token

存取權杖應傳送到服務作為 Authorization: Bearer <TOKEN> 標頭。The access token should be sent to the service as the Authorization: Bearer <TOKEN> header. 每一個存取權杖的有效時間為 10 分鐘。Each access token is valid for 10 minutes. 您可以隨時取得新權杖,但為了盡量降低網路流量和延遲,建議您使用相同的權杖九分鐘。You can get a new token at any time, however, to minimize network traffic and latency, we recommend using the same token for nine minutes.

以下是文字轉語音 REST API 的範例 HTTP 要求:Here's a sample HTTP request to the text-to-speech REST API:

POST /cognitiveservices/v1 HTTP/1.1
Authorization: Bearer YOUR_ACCESS_TOKEN
Host: westus.stt.speech.microsoft.com
Content-type: application/ssml+xml
Content-Length: 199
Connection: Keep-Alive

// Message body here...

取得語音清單Get a list of voices

voices/list端點可讓您取得特定區域/端點的完整語音清單。The voices/list endpoint allows you to get a full list of voices for a specific region/endpoint.

區域與端點Regions and endpoints

區域Region 端點Endpoint
澳大利亞東部Australia East https://australiaeast.tts.speech.microsoft.com/cognitiveservices/voices/list
巴西南部Brazil South https://brazilsouth.tts.speech.microsoft.com/cognitiveservices/voices/list
加拿大中部Canada Central https://canadacentral.tts.speech.microsoft.com/cognitiveservices/voices/list
美國中部Central US https://centralus.tts.speech.microsoft.com/cognitiveservices/voices/list
東亞East Asia https://eastasia.tts.speech.microsoft.com/cognitiveservices/voices/list
East USEast US https://eastus.tts.speech.microsoft.com/cognitiveservices/voices/list
美國東部 2East US 2 https://eastus2.tts.speech.microsoft.com/cognitiveservices/voices/list
法國中部France Central https://francecentral.tts.speech.microsoft.com/cognitiveservices/voices/list
印度中部India Central https://centralindia.tts.speech.microsoft.com/cognitiveservices/voices/list
日本東部Japan East https://japaneast.tts.speech.microsoft.com/cognitiveservices/voices/list
南韓中部Korea Central https://koreacentral.tts.speech.microsoft.com/cognitiveservices/voices/list
美國中北部North Central US https://northcentralus.tts.speech.microsoft.com/cognitiveservices/voices/list
北歐North Europe https://northeurope.tts.speech.microsoft.com/cognitiveservices/voices/list
美國中南部South Central US https://southcentralus.tts.speech.microsoft.com/cognitiveservices/voices/list
東南亞Southeast Asia https://southeastasia.tts.speech.microsoft.com/cognitiveservices/voices/list
英國南部UK South https://uksouth.tts.speech.microsoft.com/cognitiveservices/voices/list
西歐West Europe https://westeurope.tts.speech.microsoft.com/cognitiveservices/voices/list
美國西部West US https://westus.tts.speech.microsoft.com/cognitiveservices/voices/list
美國西部 2West US 2 https://westus2.tts.speech.microsoft.com/cognitiveservices/voices/list

要求標頭Request headers

下表列出文字轉換語音要求的必要和選擇性標頭。This table lists required and optional headers for text-to-speech requests.

標頭Header 描述Description 必要/選用Required / Optional
Authorization 前面加入 Bearer 這個字的授權權杖。An authorization token preceded by the word Bearer. 如需詳細資訊,請參閱驗證For more information, see Authentication. 必要項Required

要求本文Request body

對於GET此端點的要求, 不需要主體。A body isn't required for GET requests to this endpoint.

範例要求Sample request

此要求只需要授權標頭。This request only requires an authorization header.

GET /cognitiveservices/voices/list HTTP/1.1

Host: westus.tts.speech.microsoft.com
Authorization: Bearer [Base64 access_token]

範例回應Sample response

此回應已被截斷, 以說明回應的結構。This response has been truncated to illustrate the structure of a response.

注意

語音可用性因地區/端點而異。Voice availability varies by region/endpoint.

[
    {
        "Name": "Microsoft Server Speech Text to Speech Voice (ar-EG, Hoda)",
        "ShortName": "ar-EG-Hoda",
        "Gender": "Female",
        "Locale": "ar-EG"
    },
    {
        "Name": "Microsoft Server Speech Text to Speech Voice (ar-SA, Naayf)",
        "ShortName": "ar-SA-Naayf",
        "Gender": "Male",
        "Locale": "ar-SA"
    },
    {
        "Name": "Microsoft Server Speech Text to Speech Voice (bg-BG, Ivan)",
        "ShortName": "bg-BG-Ivan",
        "Gender": "Male",
        "Locale": "bg-BG"
    },
    {
        "Name": "Microsoft Server Speech Text to Speech Voice (ca-ES, HerenaRUS)",
        "ShortName": "ca-ES-HerenaRUS",
        "Gender": "Female",
        "Locale": "ca-ES"
    },
    {
        "Name": "Microsoft Server Speech Text to Speech Voice (cs-CZ, Jakub)",
        "ShortName": "cs-CZ-Jakub",
        "Gender": "Male",
        "Locale": "cs-CZ"
    },

    ...

]

HTTP 狀態碼HTTP status codes

每個回應的 HTTP 狀態碼會指出成功或常見的錯誤。The HTTP status code for each response indicates success or common errors.

HTTP 狀態碼HTTP status code 描述Description 可能的原因Possible reason
200200 [確定]OK 要求成功。The request was successful.
400400 錯誤的要求Bad Request 必要的參數遺失、為空白或 Null。A required parameter is missing, empty, or null. 或者,傳遞至必要或選用參數的值無效。Or, the value passed to either a required or optional parameter is invalid. 常見的問題是標頭太長。A common issue is a header that is too long.
401401 未授權Unauthorized 要求未經授權。The request is not authorized. 請檢查以確定您的訂用帳戶金鑰或權杖有效,並且位於正確的區域。Check to make sure your subscription key or token is valid and in the correct region.
429429 太多要求Too Many Requests 您已超出訂用帳戶允許的配額或要求率。You have exceeded the quota or rate of requests allowed for your subscription.
502502 不正確的閘道Bad Gateway 網路或伺服器端問題。Network or server-side issue. 也可能表示標頭無效。May also indicate invalid headers.

將文字轉換成語音Convert text-to-speech

端點可讓您使用語音合成標記語言 (SSML)將文字轉換為語音。 v1The v1 endpoint allows you to convert text-to-speech using Speech Synthesis Markup Language (SSML).

區域與端點Regions and endpoints

支援使用 REST API 對以下區域進行文字轉語音。These regions are supported for text-to-speech using the REST API. 請確定選取的是符合您訂用帳戶區域的端點。Make sure that you select the endpoint that matches your subscription region.

標準和類神經的語音Standard and neural voices

您可以使用此表格來判斷區域/端點的標準和類神經語音的可用性:Use this table to determine availability of standard and neural voices by region/endpoint:

區域Region 端點Endpoint 標準的語音Standard Voices 類神經的語音Neural Voices
澳洲東部Australia East https://australiaeast.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
加拿大中部Canada Central https://canadacentral.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
美國中部Central US https://centralus.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
東亞East Asia https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
East USEast US https://eastus.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
美國東部 2East US 2 https://eastus2.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
法國中部France Central https://francecentral.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
印度中部India Central https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
日本東部Japan East https://japaneast.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
南韓中部Korea Central https://koreacentral.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
美國中北部North Central US https://northcentralus.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
北歐North Europe https://northeurope.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
美國中南部South Central US https://southcentralus.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
東南亞Southeast Asia https://southeastasia.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
英國南部UK South https://uksouth.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
西歐West Europe https://westeurope.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes
美國西部West US https://westus.tts.speech.microsoft.com/cognitiveservices/v1 Yes No
美國西部 2West US 2 https://westus2.tts.speech.microsoft.com/cognitiveservices/v1 Yes Yes

自訂語音Custom voices

如果您已建立自訂的語音字型,請使用您已建立的端點。If you've created a custom voice font, use the endpoint that you've created. 您也可以使用下面列出的端點取代{deploymentId}與您的語音模型的部署 ID。You can also use the endpoints listed below, replacing the {deploymentId} with the deployment ID for your voice model.

區域Region 端點Endpoint
澳洲東部Australia East https://australiaeast.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
加拿大中部Canada Central https://canadacentral.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國中部Central US https://centralus.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
東亞East Asia https://eastasia.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
East USEast US https://eastus.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國東部 2East US 2 https://eastus2.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
法國中部France Central https://francecentral.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
印度中部India Central https://centralindia.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
日本東部Japan East https://japaneast.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
南韓中部Korea Central https://koreacentral.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國中北部North Central US https://northcentralus.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
北歐North Europe https://northeurope.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國中南部South Central US https://southcentralus.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
東南亞Southeast Asia https://southeastasia.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
英國南部UK South https://uksouth.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
西歐West Europe https://westeurope.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國西部West US https://westus.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}
美國西部 2West US 2 https://westus2.voice.speech.microsoft.com/cognitiveservices/v1?deploymentId={deploymentId}

要求標頭Request headers

下表列出文字轉換語音要求的必要和選擇性標頭。This table lists required and optional headers for text-to-speech requests.

標頭Header 描述Description 必要/選用Required / Optional
Authorization 前面加入 Bearer 這個字的授權權杖。An authorization token preceded by the word Bearer. 如需詳細資訊,請參閱驗證For more information, see Authentication. 必要項Required
Content-Type 指定所提供文字的內容類型。Specifies the content type for the provided text. 接受的值為 application/ssml+xmlAccepted value: application/ssml+xml. 必要項Required
X-Microsoft-OutputFormat 指定音訊輸出格式。Specifies the audio output format. 如需接受值的完整清單,請參閱音訊輸出For a complete list of accepted values, see audio outputs. 必要項Required
User-Agent 應用程式名稱。The application name. 提供的值必須少於255個字元。The value provided must be less than 255 characters. 必要項Required

音訊輸出Audio outputs

此清單列出了每個要求中系統做為 X-Microsoft-OutputFormat 標頭的傳送的支援音訊格式。This is a list of supported audio formats that are sent in each request as the X-Microsoft-OutputFormat header. 每個格式皆包含位元速率和編碼類型。Each incorporates a bitrate and encoding type. 語音服務支援 24 kHz、16 kHz 和 8 kHz 音訊輸出。The Speech Services supports 24 kHz, 16 kHz, and 8 kHz audio outputs.

raw-16khz-16bit-mono-pcm raw-8khz-8bit-mono-mulaw
riff-8khz-8bit-mono-alaw riff-8khz-8bit-mono-mulaw
riff-16khz-16bit-mono-pcm audio-16khz-128kbitrate-mono-mp3
audio-16khz-64kbitrate-mono-mp3 audio-16khz-32kbitrate-mono-mp3
raw-24khz-16bit-mono-pcm riff-24khz-16bit-mono-pcm
audio-24khz-160kbitrate-mono-mp3 audio-24khz-96kbitrate-mono-mp3
audio-24khz-48kbitrate-mono-mp3

注意

如果您選取的語音和輸出格式具有不同的位元速率,則會視需要重新進行音訊取樣。If your selected voice and output format have different bit rates, the audio is resampled as necessary. 不過, 24 kHz 語音不支援audio-16khz-16kbps-mono-sirenriff-16khz-16kbps-mono-siren輸出格式。However, 24 kHz voices do not support audio-16khz-16kbps-mono-siren and riff-16khz-16kbps-mono-siren output formats.

要求本文Request body

每個 POST 要求的本文都會以語音合成標記語言 (SSML) 形式傳送。The body of each POST request is sent as Speech Synthesis Markup Language (SSML). SSML 可讓您選擇文字轉換語音服務所傳回合成語音的語音和語言。SSML allows you to choose the voice and language of the synthesized speech returned by the text-to-speech service. 如需支援的完整語音清單,請參閱語言支援For a complete list of supported voices, see language support.

注意

如果使用自訂語音,可以純文字 (ASCII 或 UTF-8) 形式傳送要求本文。If using a custom voice, the body of a request can be sent as plain text (ASCII or UTF-8).

範例要求Sample request

此 HTTP 要求使用 SSML 指定語音與語言。This HTTP request uses SSML to specify the voice and language. 本文不能超過 1,000 個字元。The body cannot exceed 1,000 characters.

POST /cognitiveservices/v1 HTTP/1.1

X-Microsoft-OutputFormat: raw-16khz-16bit-mono-pcm
Content-Type: application/ssml+xml
Host: westus.tts.speech.microsoft.com
Content-Length: 225
Authorization: Bearer [Base64 access_token]

<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female'
    name='en-US-JessaRUS'>
        Microsoft Speech Service Text-to-Speech API
</voice></speak>

如需特定語言的範例, 請參閱快速入門:See our quickstarts for language-specific examples:

HTTP 狀態碼HTTP status codes

每個回應的 HTTP 狀態碼會指出成功或常見的錯誤。The HTTP status code for each response indicates success or common errors.

HTTP 狀態碼HTTP status code 描述Description 可能的原因Possible reason
200200 [確定]OK 要求成功;回應主體是音訊檔案。The request was successful; the response body is an audio file.
400400 錯誤的要求Bad Request 必要的參數遺失、為空白或 Null。A required parameter is missing, empty, or null. 或者,傳遞至必要或選用參數的值無效。Or, the value passed to either a required or optional parameter is invalid. 常見的問題是標頭太長。A common issue is a header that is too long.
401401 未授權Unauthorized 要求未經授權。The request is not authorized. 請檢查以確定您的訂用帳戶金鑰或權杖有效,並且位於正確的區域。Check to make sure your subscription key or token is valid and in the correct region.
413413 要求實體太大Request Entity Too Large SSML 輸入的長度大於 1024 個字元。The SSML input is longer than 1024 characters.
415415 不支援的媒體類型Unsupported Media Type 可能是提供了錯誤Content-Type的。It's possible that the wrong Content-Type was provided. Content-Type應設定為application/ssml+xmlContent-Type should be set to application/ssml+xml.
429429 太多要求Too Many Requests 您已超出訂用帳戶允許的配額或要求率。You have exceeded the quota or rate of requests allowed for your subscription.
502502 不正確的閘道Bad Gateway 網路或伺服器端問題。Network or server-side issue. 也可能表示標頭無效。May also indicate invalid headers.

如果 HTTP 狀態為 200 OK,則回應主體會包含所要求格式的音訊檔案。If the HTTP status is 200 OK, the body of the response contains an audio file in the requested format. 會在將此檔案傳輸、儲存到緩衝區或儲存到檔案時播放。This file can be played as it's transferred, saved to a buffer, or saved to a file.

後續步驟Next steps