DotNet Example: Speech Synthesis
This sample demonstrates loading, registering and using a .NET class from a DLL in the standard location.
Paste the code below into an Xbasic script and run it. Make sure the sound on your computer is turned on.
We need specify the assembly filename for System.Speech.dll because its assembly is not preloaded. If you take the assy parameter out of the RegisterClass call, the registration will fail.
dim Sv as DotNet::Services dim assy as DotNet::AssemblyReference assy.filename = DotNetPath()+"WPF\System.Speech.dll" dim Text as C = "This is a test. It is only a test. " \ + "If this had been a real emergency..."\ + " I wouldn't be playing with Alpha Anywhere!" If Sv.RegisterClass("Speech", "Synth", \ "System.Speech.Synthesis.SpeechSynthesizer", assy) dim TestTalker as Speech::Synth TestTalker.SpeakAsync(Text) else ui_msg_box("Speech Demo","Synth class not registered") end if
The MSDN documentation for speech recognition and speech synthesis is here.
This sample runs on the desktop. To create sound on a Web site that will play in a browser is somewhat more complicated.
The logic of this sample has been wrapped up in the new Xbasic TextToSpeech Function.