Speak Method
Returns a string which is a URL to a wave or mp3 stream of the passed-in text being spoken in the desired language.
| Request URI |
|---|
| http://api.microsofttranslator.com/V2/Ajax.svc/Speak |
| Parameter | Description |
|---|---|
|
appId |
Required. A string containing "Bearer" + " " + access token. |
|
text |
Required. A string containing a sentence or sentences of the specified language to be spoken for the wave stream. The size of the text to speak must not exceed 2000 characters. |
|
language |
Required. A string representing the supported language code to speak the text in. The code must be present in the list of codes returned from the method GetLanguagesForSpeak. |
|
format |
Optional. A string specifying the content-type ID. Currently, “audio/wav” and “audio/mp3” are available. The default value is "audio/wav". |
|
options |
Optional. A string specifying the quality of the audio signals. Currently, “MaxQuality” and “MinSize” are available. With “MaxQuality”, you can get the voice(s) with the highest quality, and with “MinSize”, you can get the voices with the smallest size. If no value is provided, we default to “MinSize”. |
| Return value |
|---|
| Returns a string which is a URL to a wave or mp3 stream of the passed-in text being spoken in the desired language. |
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;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var language = "en";
var format = "audio/mp3";
var option = "MinSize"
var text = "Use pixels to express.";
function speak() {
PageMethods.GetAccessToken(OnSucceeded, OnFailed);
}
function OnSucceeded(result, usercontext, methodName) {
window.mycallback = function (response) { alert(response); }
var s = document.createElement("script");
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Speak?oncomplete=mycallback&appId=Bearer " + encodeURIComponent(result.access_token) + "&text=" + text + "&language=" + language + "&format=" + format;
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="buttonSpeak" runat="server" Text="Speak" OnClientClick="speak();return false;" />
<br />
<asp:Label ID="lblResult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Note