This is an old revision of the document!
Speaking the contents of a file
by Richard Russell, October 2008
The supplied example program SPEAK.BBC illustrates how you can use Windows' built-in speech synthesis capabilities to speak a string (or strings) provided by your program, but what if you want to speak the contents of a text file? You could, of course, load the file into a set of strings and speak those, but the SAPI 5 speech system (typically available in Windows 2000, XP and Vista) provides a more direct method.
The code below speaks the text in the specified file:
INSTALL @lib$+"COMLIBA" ON ERROR PRINT 'REPORT$ : PROC_comexit : END ON CLOSE PROC_comexit : QUIT filetospeak$ = "C:\test.txt" PROC_cominit voice% = FN_createobject("SAPI.SpVoice") PROC_callmethod(voice%, "Speak("""+filetospeak$+""", 12)") PROC_releaseobject(voice%) PROC_comexit
The value 12 in the PROC_callmethod line specifies that the file may contain embedded tags to control parameters such as speed, volume and voice (see this article for details). If you don't want such tags to be acted upon change this value to 4.