VB6 Text To Speech Application

Pre-Requisite: Make sure that you system already has TTS (SAPI – Win32 Speech API) is installed.

If it is not installed, download & install it from this link. Microsoft Speech SDK or Win32 Speech API Download

Once this is installed successfully, the below code can be used in your VB projects.

VB6 Code – Text To Speech Application

Here is the simplest code with late binding or dynamic binding that refers TTS.

Sub Excel_Text_To_Speech_Late_Biding()
    'Object for TTS
    Dim obj_Text_To_Speech_Voice
    
    'Refer SAPI object
    Set obj_Text_To_Speech_Voice = CreateObject("SAPI.spVoice") 'Microsoft Speech SDK
    
    'Text To Speech - Voice Text Message
    obj_Text_To_Speech_Voice.Speak "hi how are you?" ' Voice Text To Speech
End Sub

Include the above code in any of your project & call this from a command button.

The computer will give the voice command entered in the code.

In case you would like to know more options inside this SDK, try this code.

Note: Include “Microsoft Speech Object Library from references before executing this code.

Sub Excel_Text_To_Speech_Early_Biding()
    'Object for TTS or Win32 Speech API - SAPI
    Dim obj_Text_To_Speech_Voice As SpeechLib.SpVoice
    
    'Create instance for SAPI object
    Set obj_Text_To_Speech_Voice = New SpeechLib.SpVoice
    
    'Text To Speech - Voice Text Message
    obj_Text_To_Speech_Voice.Speak "hi how are you?" ' Voice Text To Speech
End Sub

Output will be the same for this code also.

You can also further modify this code to read text from a file or filestream, choose speaker (make or female voice),  control volume, speed at which the text is read out.

Leave a Reply