Re: SAPI5 speech via COM in AutoIt, VBNET, & C#

  • From: Veli-Pekka Tätilä <vtatila@xxxxxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Tue, 11 Sep 2007 07:37:03 +0300

Hi Jamal,
I imagine this code is greatly interesting to many people, I know some
newbies who like the speech feature one of the best in programming,
overall. Talking the stuff to a wave file and switching voices is a
little harder, requiring more method calls and collections. I have
sample code of that in PErl which should be relatively easy to
translate, too. Look for Speech.SpVoice twice and sampling rate once in
the following:

http://www.student.oulu.fi/~vtatila/perltut.html

But can anyone tell me how to change pitch in a SAPI 5 synth? It sure is
not a property yet seems like a standard parameter in application
software such as screen readers.

Does anyone have sample code of a SAPI synth? I'd like to write one that
captures stuff to a text file, from Acrobat and Ms Reader, that is.

PS: Another good SAPI 5 example is the NVDA source that comes with the
app.

-- 
With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila

Jamal Mazrui wrote:
> 
> Below are example programs in three languages:  AutoIt, Visual Basic .NET,
> and C#.  Each contains a Say routine to speak a string via COM automation
> with SAPI5, as well as code to test that routine.  Initial comments give
> command-line syntax for compiling and running the program -- assuming
> relevant tools have been included on the Windows search path.
> 
> Hope this helps,
> Jamal
> ----------
> 
> ; AutoIt
> ; Run sapi.au3 with the following command line:
> ; start sapi.au3
> ; or compile it with the following command line:
> ; aut2exe /in sapi.au3
> ; Then run sapi.exe
> 
> Func Say($sText)
> Local $oSapi = ObjCreate("SAPI.SpVoice")
> $oSapi.Speak($sText)
> $oSapi = 0
> EndFunc
> 
> Local $sText = "Testing 1 2 3"
> Say($sText)
> 
> ----------
> 
> ' Visual Basic .NET
> ' Compile sapi.vb with the following command line:
> ' vbc.exe sapi.vb
> ' Then run sapi.exe
> 
> Module Program
> 
> Sub Say(sText As String)
> Dim sProgID As String = "SAPI.SPVoice"
> Dim oSapi As Object = Microsoft.VisualBasic.CreateObject("SAPI.SPVoice")
> oSapi.Speak(sText)
> System.Runtime.InteropServices.Marshal.ReleaseComObject(oSapi)
> End Sub
> 
> Sub Main()
> Dim sText As String = "Testing 1 2 3"
> Say(sText)
> End Sub
> 
> End Module
> 
> ----------
> 
> // C#
> // Compile sapi.cs with the following command line:
> // csc.exe sapi.cs
> // Then run sapi.exe
> 
> class Program {
> 
> static void Say(string sText) {
> string sProgID = "SAPI.SPVoice";
> System.Type tSapi = System.Type.GetTypeFromProgID(sProgID);
> object oSapi = System.Activator.CreateInstance(tSapi);
> string sMethod = "Speak";
> object[] oArgs = {sText};
> tSapi.InvokeMember(sMethod, System.Reflection.BindingFlags.InvokeMethod,
> null, oSapi, oArgs);
> System.Runtime.InteropServices.Marshal.ReleaseComObject(oSapi);
> } // Say method
> 
> static void Main() {
> string sText = "Testing 1 2 3";
> Say(sText);
> } // Main method
> 
> } // Program class
> 
> ----------
> End of Document
> 
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: