User Tools

Site Tools


speaking_20the_20contents_20of_20a_20file

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.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
speaking_20the_20contents_20of_20a_20file.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1