Export (0) Print
Expand All

GetLanguagesForSpeak Method

Retrieves the languages available for speech synthesis.

Request
Request URI
http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForSpeak

URI parameters
Parameter Description

appId

Required. A string containing "Bearer" + " " + access token.


Response
Return value
A string array containing the language codes supported for speech synthesis by the Translator Services.

Ff512400.alert_note(en-us,MSDN.10).gif Note

Bing App ID is deprecated and is no longer supported.   Please obtain an access token to use the Microsoft Translator API. For details, go here.


Example

Obtain an Access Token on the server-side

                                               
[System.Web.Services.WebMethod]
public static AdmAccessToken GetAccessToken()
{
    AdmAccessToken admToken;
    string headerValue;
    //Get Client Id and Client Secret from https://datamarket.azure.com/developer/applications/
    AdmAuthentication admAuth = new AdmAuthentication("clientid", "clientsecret");

    admToken = admAuth.GetAccessToken();
    // Create a header with the access_token property of the returned token
    headerValue = "Bearer" + " " + HttpUtility.UrlEncode(admToken.access_token);

    return admToken;
} 
                                            
Invoke the AJAX method on the client-side

                                               
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var languageCodes = "[\"de\", \"fr\", \"it\"]";
        function getLanguagesForSpeak() {
            PageMethods.GetAccessToken(OnSucceeded, OnFailed);

        }
        function OnSucceeded(result, usercontext, methodName) {

            window.mycallback = function (response) {
                var array = response;
                var languageNames = "";
                for (var i = 0; i < array.length; i++) {
                    languageNames = languageNames + array[i] + "<br />";
                }
                document.getElementById('<%= lblResult.ClientID %>').innerHTML = languageNames;

            }

            var s = document.createElement("script");
            s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForSpeak?oncomplete=mycallback&appId=Bearer " + encodeURIComponent(result.access_token);
            document.getElementsByTagName("head")[0].appendChild(s);
        }
        function OnFailed(error, userContext, methodName) {
            alert("Error");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <asp:Button ID="buttonLangSpeak" runat="server" Text="Get Language names" OnClientClick="getLanguagesForSpeak();return false;" />
        <br />
        <asp:Label ID="lblResult" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
                                            
Show:
© 2015 Microsoft