User Tools

Site Tools


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"
        voice% = FN_createobject("SAPI.SpVoice")
        PROC_callmethod(voice%, "Speak("""+filetospeak$+""", 12)")

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 for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
speaking_20the_20contents_20of_20a_20file.txt · Last modified: 2018/04/15 13:54 by richardrussell