User Tools

Site Tools


outputting_20speech_20to_20a_20file

Outputting speech to 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 output speech to your PC's loudspeakers, but what if you want to create a sound file containing the speech? Fortunately the SAPI 5 speech system (typically available in Windows 2000, XP and Vista) supports this facility directly.

The code below outputs speech to a specified WAV file:

        INSTALL @lib$+"COMLIBA"
 
        ON ERROR ON ERROR OFF : PROC_comexit : PRINT 'REPORT$ : END
        ON CLOSE PROC_comexit : QUIT
 
        PROC_cominit
        file$ = "test.wav"
        speech$ = "This is a test file"
 
        voice% = FN_createobject("SAPI.SpVoice")
        filestream% = FN_createobject("SAPI.SpFileStream")
        PROC_callmethod(filestream%, "Open("""+file$+""",3,0)")
        PROC_putobject(voice%, "AudioOutputStream(O filestream%)")
        PROC_callmethod(voice%, "Speak("""+speech$+""",0)")
        PROC_callmethod(filestream%, "Close")
        PROC_releaseobject(filestream%)
        PROC_releaseobject(voice%)
 
        PROC_comexit
 
        SYS "PlaySound", file$, 0, &20001

Note that this code requires COMLIB (or COMLIBA) version 3.3 or later, as supplied with BBC BASIC for Windows version 5.90a.

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
outputting_20speech_20to_20a_20file.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1