I am trying to alter the voice in a DirectSS Text to speech control.
I am able to make the control speak.

"DirectSS1.speak (Label1.caption) 'This reads the words from a text box"

Going on the above how do I change the voice. The other properties I am playing with as I go along.

Dani AI

Generated

If you stick with the Microsoft Speech Object Library (SAPI 5), you can change voices without guessing indexes by filtering on attributes like Name, Gender, and Language, and then tweak rate/volume. This avoids surprises when new voices are installed, and it is more robust than selecting Item(0). As showed the basics, here is a slightly safer pattern you can drop into VB6 (Project -> References -> Microsoft Speech Object Library), then call from your form code.

' Late-bound for brevity; early-binding via SpeechLib is fine too.
Dim v As Object, toks As Object
Set v = CreateObject("SAPI.SpVoice")

' Pick by exact name (e.g., "Microsoft Mary") or by attributes.
Set toks = v.GetVoices("Name=Microsoft Mary", "")
If toks.Count = 0 Then Set toks = v.GetVoices("Gender=Female;Language=409", "") ' en-US

If toks.Count > 0 Then Set v.Voice = toks.Item(0)

' Optional: adjust prosody
v.Rate = -1   ' -10..+10
v.Volume = 90 ' 0..100
' When speaking XML markup (for pitch, etc.), pass SVSFIsXML with your Speak call.

GetVoices supports filter strings such as Name, Gender, Age, Language, and Vendor; prefer those over numeric indexes. See SpVoice.GetVoices filters. (learn.microsoft.com) Rate and Volume are first-class properties on SpVoice. See SpVoice interface properties. (learn.microsoft.com) For pitch (which is engine-dependent), embed SAPI XML like <pitch absmiddle='5'>text</pitch> and speak with the XML flag; tags for pitch/rate/volume are documented here: XML TTS tutorial. (learn.microsoft.com)

Troubleshooting: if your VB6 app only ever sees one voice (e.g., Sam) on 64-bit Windows, remember VB6 is 32-bit and enumerates 32-bit SAPI voices. Open the 32-bit Speech Properties via C:\Windows\SysWOW64\Speech\SpeechUX\sapi.cpl to confirm installed 32-bit voices and the default selection. See this vendor note and Microsoft forum thread: Configure the SAPI TTS voice (32-bit applet path) and Windows 7 x64 voice selection. (help.genesys.com, answers.microsoft.com) Also verify that voices are registered under HKLM\SOFTWARE\Microsoft\Speech\Voices\Tokens (and WOW6432Node on x64). See Object tokens and registry settings. (learn.microsoft.com)

Finally, is right: the old Direct* controls and SAPI 5 automation are different stacks. Mixing them can hide voices; pick one approach and stick to it. (learn.microsoft.com)

Recommended Answers

All 3 Replies

This is my code with Microsoft Speech Object Library as my reference

Dim Voice As SpVoice

Set Voice = New SpVoice

'* This will display available voice in VB6 Immediate Window from your computer
Debug.Print Voice.GetVoices().Count

'* This will change the voice
Set Voice.Voice = Voice.GetVoices().Item(0) '* Index 0 = Voice Count

Voice.Speak Text1.Text, SVSFlagsAsync

I only have Microsoft Sam installed on my computer, so Voice Count is just 1.

Hope this Helps

I also found something on the net where you can download Text-to-Speech Voices that you can install on your computer.

Haven't tried it, but I hope the link will work.

For anyone trying to access VB SPEECH to TEXT still please know that there are THREE ways to do it.  There are two different OCX controls.  The first two you get by checking the boxes to add those fancier OCX controls. 

First, Microsoft DirectTextTosSpeech or  Second, Microsoft Voice Text.  You get there by going into Project - Components or CTRL-T  If you plan to port your program using the above you need a different DLL file for each.  - Xvoice.DLL and VText.DLL or something quite similar. - If you plan to port it you need to install their respective DLLs or your entire program will not install. 

The THIRD way to change TEXT to SPEECH is the BEST-most up-to-date method works with code noted above. But there's no OCX control.  You have to had  add a REFERENCE. 
Project - References.  There's no keyboard shortcut  Then find way down there the
Microsoft Speech Object Library.    Once checked it pops nicely to the top. I'm posting this hoping you will find that 

more easily than I.   I've never had cause to look in there.    That done you only to declare the voice object as noted in the code above.  You can download the entire Developer's kit at this link.

MS-Text-to-Speech 5.1 Soft Dev Kit & files

To port this to other computers you need the redistribute files, all 30 megs or so of them, which is a lot more than a DLL file but it does work. I can now chane the voice to MS Mike, Mary, or Sam Note:  the TTL voice doesn't work that way.  

When or *IF* I figure out how to change the speed and pitch easily I will keep you... uh... posted.  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.