Page 1 of 3

SAPI 4 and SAPI 5 UserLibrary

Posted: Thu Jul 28, 2005 1:41 am
by Esteban1
I’ve compiled a little UserLibrary for using SAPI 4 and/or SAPI 5 engines (voices) in my PureBasic programs. It could be useful for someone else.
Some guys at the beginners forum tested it and found it useful (I'm a beginner too).

You can download it from here:

http://geocities.com/esteban1uy/My_drive.html

Functions:

TTSEnd()
TTSEngCount()
TTSEngMfg()
TTSEngName()
TTSGetPitch()
TTSGetSpeed()
TTSGetVolume()
TTSInit()
TTSPause()
TTSResume()
TTSSAPIVer()
TTSSelect()
TTSSetPitch()
TTSSetSpeed()
TTSSetVolume()
TTSSpeak()
TTSStop()

It also supports some events as AudioStart, AudioStop, and WordPosition.
Some examples included.

PS: Sorry for my English.

Posted: Thu Jul 28, 2005 3:25 am
by MVXA
Thank you for the Userlib. I need the SAPI much.

Posted: Thu Jul 28, 2005 10:04 am
by Gansta93
I'm still looking for french voices which don't cause crash when calling TTSInit() command. If someone can find it, :-D because I don't find. For Sapi 5 it would be better.
Thank again for the lib. :-D

Library Updated

Posted: Mon Aug 08, 2005 9:22 am
by Esteban1
After digging a lot in the SAPI 5.1 SDK finally found the way to get ALL the events working while speaking to a .wav file... by looking for the things the SDK doesn't explain!
(Microsoft guys really keep some details for themselves.)

Well, now you can get informed of the progress of encoding for all the engines installed in your system, independently of the SAPI version.

There's also a new function, TTSEngLang(). It retrieves the language description of the voices.

You can get PureTTS here:

http://geocities.com/esteban1uy/My_drive.html

Just look for the last release.

Re: Library Updated

Posted: Thu Aug 11, 2005 9:46 pm
by va!n
really great work! i like it! but there seems to be small problem with the debugger.. when the debugger is enabled in following example, i can hear nothing...

Code: Select all

TTSInit(0,0,0)
  TTSSelect(0)
  TTSSpeak("Just a test")
  Sleep_(5000)
TTSEnd()
...with disabled debugger it works everytime!

by the way, it would be cool to store a created wave direct into the memory (if you want add an echo or something else) - even you can easy use PlaySound()....

Are there any commands to change the output in realtime? like...

#D1 - #D9 ; delay like "I #D2 Love #D6 YOU"
#P1 - #P9 ; pitching
#S1 - #S1 ; speed (for singing, ok a bit crazy ;-)

btw, when using TTSSelect(0)... how can i be sure that it will be on every system the windows inbuild vocal???

keep on ya work... TTSSpeackToMemory() would be cool!!!

Edit:
Just take a look to http://and.intercon.ru/index.htm and download the 64k intro named Zoom3... its very impressive... (even he is using a very cool speech engine too... (hears very good and realistic i think...) afaik he is using the windows inbuild speech engine too!? i have a video where is he is exlaining his intro and the speech engine... (i will try to find the link where i have it from and poste then, if someone is interested!)

he released Synth stuff... as i can remember, he added any stuff of this speech engine in this package too? (or i got it from any other source!?)

Posted: Fri Aug 12, 2005 3:25 am
by Esteban1
to Va!n:

First of all, can you tell if the voice associated to index 0 (zero) is SAPI 4 or SAPI 5 compliant?

Just run this:

Code: Select all

TTSInit(0,0,0) 
vers.l=TTSSAPIVer(0)
Debug vers
TTSEnd()
If the version of the engine (voice) is 5 there will be no problem if you run your code with or without an associated window.
If the version is 4, you MUST open at least a window (even if it's not visible) for the voices to speak. It is not my fault, it's just a SAPI 4 issue.

On the other hand, both SAPI 4 and 5 are tag enabled in the library. For example, if your voice is SAPI 4 you can use:

Code: Select all

.
.
.
TTSSpeak("\Spd=120\Hello, \Spd=240\now I speak very fast.") 
.
.
.
and if your voice is SAPI 5:

Code: Select all

.
.
.
TTSSpeak("<RATE SPEED="+Chr(34)+"0"+Chr(34)+"/>Hello, <RATE SPEED="+Chr(34)+"6"+Chr(34)+"/>now i speak very fast.") 
.
.
.
You can take a look to SAPI tags at:

http://xtras.timehouse.fi/sapidoc.asp?con=8

and

http://xtras.timehouse.fi/sapidoc.asp?con=9

The "speak to memory" function you asked for is easy to make for SAPI 5, but for SAPI 4 it's beyond my knowledge (I'm just a beginner). Maybe with some help from the gurus...

Now I'm going to take a look to the page you pointed.

Esteban1

Posted: Fri Aug 12, 2005 5:30 am
by Esteban1
to va!n:

Sorry, I can't run the file you pointed to me, my pc doesn't meet the video requirements.

About the default voices, there is no way to ensure that the voice corresponding to index 0 (zero) is the pre-installed one. Index 0 voice is the default voice that every user can set via Control Panel (for SAPI 5). If the user has no SAPI 5 but he has SAPI 4, then index 0 voice is the first SAPI 4 voice he installed (but I'm not very sure of this). The best way to always get "Microsoft Sam" (for example) is to enumerate the voices installed until TTSEngName() returns "Microsoft Sam":

Code: Select all

TTSInit(0,0,0)
voices.l=TTSEngCount()
For i=0 To voices
  If TTSEngName(i)="Microsoft Sam"
    TTSSelect(i)
    Break
  EndIf
Next
If i=voices+1
  Debug "Microsoft Sam not found, using default voice instead."
EndIf
TTSSpeak("Hello world")
Delay(3000)
TTSEnd()
Esteban1

Posted: Fri Aug 12, 2005 3:30 pm
by va!n
Esteban1 wrote:to Va!n:
First of all, can you tell if the voice associated to index 0 (zero) is SAPI 4 or SAPI 5 compliant?
i executed your codesnip and it will return SAPI 5 - you wrote, that there isnt a window needed... but when try to execute my posted example (using SAPI5 also), it does not work with enabled debugger... (you have to kill the task)... with disabled all seems to work fine!

thanks for showing how to use tags and giving the links of docs (rtfm ;-)

very sad, that you cant run the 64k intro... i know "AND" the author has released the intro tunes as MP3 on his site but sadly wihtout the vocals... i will try to find a video of his intro... else i will try to record the voice part, so you can download and hear to it... its really very amazing good and cool... keep on your work... thanks

Edit:
Here i have two links where AND explaining on a party seminar his engines he used for his great 64k intro zoom3... The video is splitted in two parts... if you are interested mainly in the sound / speech engine (SAPI), just take a lookt at video part1 and start at timeline offset 20:20 mins... its really damn cool... have fun

ftp://ftp.edome.net/events/assembly04/v ... _part1.avi
ftp://ftp.edome.net/events/assembly04/v ... _part2.avi

i really like how can added optional stuff for changing how it will be spoken... control the tone and stretching the oooo of hero !? just take a look to the video...

Posted: Fri Aug 12, 2005 7:30 pm
by Esteban1
to va!n:

Let's make some experiments.

Try these great examples from Danilo:

http://purearea.net/pb/CodeArchiv/Music+Movie/Speech/Speech_Sample1.pb

http://purearea.net/pb/CodeArchiv/Music+Movie/Speech/Speech_Sample2.pb

They are SAPI 5 not using an associated window.


Exteban1

Posted: Fri Aug 12, 2005 11:35 pm
by va!n
thanks for the links... yes, danilo did some really great work and i know his two speech examples and i tried it when i he released it.... as far as i remember, i tested both sources on my old system using win2k and i didnt got it to work... i had to install the SAPI SDK or MS VoicePackage before... that was the reason why i dont saw any use for my private projects to include...

but since the 64k intro zoom3 released, i know there must be any trick to use speech without installing any additional stuff on a fresh installed Win2K/winXP system... its seems to be the same way, you are using with your lib!! Cool!

I dont have Danilos COM lib installed atm and i am still looking forward to your updates ;-) Keep on your nice work!

Btw, taked a look to the video? :wink:

Posted: Sat Aug 13, 2005 2:52 am
by Esteban1
It seems that AND speech is based on some form of Festival, a speech synthesis that is not related in any way to SAPI. Just take a look to this:


http://cslu.cse.ogi.edu/tts/index.html

I'm sorry to tell that PureTTS is not able to do what you need.

Esteban1

Posted: Sat Aug 13, 2005 10:38 am
by va!n
Esteban1 wrote:It seems that AND speech is based on some form of Festival, a speech synthesis that is not related in any way to SAPI.
Oh, that engine is really great! But i dont think that it fit in a few KBs as yours engine ;-)

Btw, AND is using the windows inbuild SAPI4 and SAPI5 rotuines... You can see/hear it in his video... I did some searches at google for information abput storing the created wave (speech output) direct into memory.... i hadnt any luck yet ;-( Would be so cool, if someone can help you to implent this great feature ;-)

Posted: Sat Aug 13, 2005 6:44 pm
by Esteban1
OK friend.

Let me dig a little more in the SDK and I'll post the whole code to put the written audio stream to memory. But... (there's always a "but") you must remember that the memory contents will be in RAW format, something like a WAV but without a header.

Is that useful for you?



Esteban1

Posted: Sat Aug 13, 2005 11:00 pm
by va!n
thanks for your help and spending your time in adding this feature!! maybe there is any way to add a WAV header before the raw data!?

viewtopic.php?t=7431&highlight=create+wave

Posted: Sun Aug 14, 2005 9:40 am
by Esteban1
Here you are va!n.

By the way, why is it so important to reproduce AND's effect?
Is it for a contest or something?
If so it would be nice to see my name included in the credits (just a joke).

Well, this is the starting point for a lot of tricks, for example it is not difficult to encode the output to a mp3 file, or send the speech to a modem (like an answering machine), or even stream it to the web...

Code: Select all

Edited.
See next post.
Esteban1