Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text to Speech Library (Windows only)
#1
I turned the powershell stuff into a simple little library for people to make use of in their projects, and here it is:

Code: (Select All)
_Title "Steve's Powershell Speech Library"

Speech_IoR 'initialize or reset speech options
Speech_SaP "Hello World, This is a normal speed demo of David's voice" 'speak and print
_Delay 2
Speech_Speaker "Ziva"
Speech_Say "Hello again.  This is a normal speed demo of Ziva's voice." 'just speak this one
_Delay 2
Speech_Speaker "David"
Speech_Speed -10
Speech_SaP "And now I'm speaking as David, but I'm speaking veeery slow."
_Delay 2
Speech_Speaker "Ziva"
Speech_Speed 5
Speech_SaP "And now I'm a very hyper Ziva!"
_Delay 2
Speech_Speed 0
Speech_Volume 30
Speech_SaP "And now I'm whispering to you that I'm done with my demo!"


'$INCLUDE:'TextToSpeech.BM'

As you can see, all the commands are preceeded by "Speech_", to try and help keep the sub names unique, associative, and not interfere with any user variable names and such.

Routines in this little package are:

Speech_IoR -- Init or Reset.  Call this first to initialize the settings (and turn volume up to 100, or else you'll be speaking on a MUTE channel)

Speech_Speaker -- Change the default speaker.  Currently I only support "David" and "Ziva", but feel free to change or add to this if your system has other voices installed via language/voice packs.

Speech_Speed -- Set a value from -10 to 10 to adjust the speed of the speaker.  0 id default, -10 is sloooow, and 10 is faaaast.

Speech_Volume -- Set a value from 0 to 100 to adjust how loud you're going to be speaking with the voices.

Speech_OutTo -- Use this to change where you want the speech to go.  Only options now are your speakers or a file.  Since it's not currently in the demo, as I didn't want to randomly save junk to folks drives, an example looks like:

        Speech_OutTo "MyTextToFile.wav"
        Speech_OutTo "Speaker"
        Speech_OutTo "" 'defaults/resets to speaker

Speech_Say -- Just says the text you specify with the settings you gave it previously.

Speech_SaP -- Says and Prints the text you specify to the screen as a quick print and speak shortcut.  Uses previous settings.

Speech_ToWav -- Converts text to a wav file and saves it to the disk where you specify.  Since it's not in the short demo above, usage would be as:

       Speech_ToWav "Hello World.  This is the text I'm saving to a file!", "MyFile.wav"

speak -- This is the master command with all the options built into it.  You can skip everything else, if you want to use this as a stand alone command to do everything all at once.  Everything else ends up calling this command at the end of the day, so you can bypass some processes if you call this directly.




And that's basically it for now.  Windows Speech Synthesizer is quite a powerful little tool, with a ton of options which we can utilize with it, but I figure this is the basics of what someone would need to be able to do with it for a program.  It seems to handle what I need from it for now.

If you guys need it to do more, feel free to ask and I'll see about adding extra functionality as people need it.  Or, feel free to make the changes necessary yourself and then share them here with us so everybody else can enjoy any extra tweaks you guys add into the code.




To make use of this:

1) Download the library from the attachment below.
2) Move it to your QB64 folder.
3) '$INCLUDE:'TextToSpeech.BM' at the end of your program.
4) Speech_IoR inside your code to initialize everything
5) Call the other subs as you want to make use of them and alter the settings to your specific needs.

It's that simple!  ;D


Attached Files
.bm   TextToSpeech.BM (Size: 2.96 KB / Downloads: 156)
Reply


Messages In This Thread
Text to Speech Library (Windows only) - by SMcNeill - 04-27-2022, 09:06 PM



Users browsing this thread: 4 Guest(s)