随手挖出来的google朗读API 可以朗读任何语言 直接返回就可以调用抢沙发
其中q=D是要朗读的内容. tl=朗读语音 是中文就是zh-cn以此类推,中间可以做任意替换,返回的MIME类型是audio/mepg
google 说 hello word:
作者：Paul Kimmel 来源：codeguru 更新时间：2007-12-11
I was surfing the web and saw the announcement of Microsoft Surface. Surface right now is a tabletop Windows Vista machine with cameras pointing out, no keyboard, and no mouse. Interactions are done with the surface of the device. Combined with the cameras and Bluetooth capabilities, Surface interacts with objects in the real world. For example, lay an enabled cell phone on the device and Surface downloads your pictures or possibly synchronizes your phone contacts with your Outlook contacts. I can't do the device justice here; it's one of those things you will have to see to believe (www.microsoft.com/surface). It's worth seeing.
I was so intrigued with a device that interacts naturally with the physical world that I became interested in the day-to-day possibilities of a more natural interaction with computing devices (as well as interested in writing a book about Surface. Hint: Microsoft, send me a Surface machine, for research purposes of course). Consequently, this article is an off-shoot of that interest.
输入: WScript.Echo("Microsoft Surface is cool!").
var shell = WScript.CreateObject("WScript.Shell");
var desktop = shell.SpecialFolders("Desktop");
var url = shell.CreateShortcut(desktop + "Popfly.url");
url.TargetPath = "http://www.popfly.ms";
WScript.Echo("Shortcut added to Popfly");
Figure 1: My FlickringVirtualEarth Mashup that shows the location of pictures from Flickr on VirtualEarth.
You can use the Speech API with just a few lines of code. You will need to create an ActiveXObject passing the name of the Speech API component, SAPI.SpVoice. (You can download the Speech API for free, if it's not installed on your computer already. Check out http://msdn2.microsoft.com/en-us/library/ms723627.aspx.) Next, you can pick a voice, and optionally set the speech rate and volume. Finally, send the text you'd like to be spoken (see Listing 2).
Note: Other browsers may not support ActiveX objects, but this technique works great on the most popular browser, IE.
实例代码2 The bare bones code it takes to read some hard coded text.
var voice = new ActiveXObject("SAPI.SpVoice");
voice.Speak("Microsoft Surface is cool!");
You can select from available voices and modulate the rate and volume with code like that shown in Listing 3. The rate can be from 1—slow—to 10—very fast; the volume can be from 0 to 100, which is the loudest; and the voice selected has to be an installed voice.
实例代码3: Speech script that sets the rate of speech, volume, and picks from an available voice.
var voices = voice.GetVoices();
var len = voices.count;
WScript.Echo("Length: " + len );
WScript.Echo("Voice: " +
if(len >= 2)
voice.Voice = voices(1);
voice.Rate = 1;
voice.Volume = 75;
voice.Speak("Microsoft PopFly is cool too!");
The code above gets the array of available voices. The number is retrieved and displayed and a description of voice at index 1 is displayed. On my machine, I have three voices and the voice at index 1 is LH Michelle. The speech rate is set to 1 (slow) and the volume is set to about ¾'s of the maximum volume.
Listing 4 combines the elements you have seen so far with some new features. I have introduced the debugger keyword that causes the debugger to break precisely at that line, making it easier to target specific code for debugging. I have also introduced a try..catch block and some cleanup code (see Listing 4).
Figure 2: By adding a debugger statement to your code, you will be prompted to select a debugger (usually Visual Studio or Microsoft Script Editor (shown)) and execution will be suspended at the debugger statement.
实例代码4: Speech capability bound to the onclick event of an <img> control. (The numbering is for reference only.)
<html xmlns="http://www.w3.org/1999/xhtml" >
var voice = new ActiveXObject("SAPI.SpVoice");
var phoneNumberText = event.srcElement.alt;
// set voice to LH Michelle
voice.Voice = voice.GetVoices()(1);
voice.Rate = 2; // pretty fast
voice.Volume = 100; // pretty loud
event.cancelBubble = true;
技巧: You will have to enable ActiveX content for your browser by selecting Tools|Internet Options, navigating to the Security tab, selecting Local intranet, Custom level, and enable or prompt for ActiveX controls and script.
The HTML in Listing 4 is a basic .HTML page. (This code will work in an .ASPX page too.) In the header section, you have a <Script> block that has a startup script that creates the ActiveXObject instance of the SAPI.SpVoice object—see lines 5 through 9. The SpeakIt function—lines 11 through 31—is bound to the onclick event of the <img> tag. The SpeakIt function reads the text in the ALT attribute of the <img> tag.
The debugger keyword on line 15 will always cause the debugger to break into the code. (Once you are comfortable with the code, simply comment line 15 out. A try..catch block—lines 13 and 27—responds to errors by displaying the text of the exception object. Finally, when the window closes the voice object is deleted.
I also introduced Microsoft Surface and PopFly. These are new and compelling products (or tools) that will soon be available. Check them out and let me know what you think—or blog about them.
35: if(voice) delete voice;
39: <form id="form1" runat="server">
41: <img alt="Paul's Number is (555) 555-1212 extension 3333"