that works with any SAPI5 voices and also Espeak
to appoint (after passing through Tailbite) "lib_Speak"
in the folder "\ PureLibraries \ UserLibraries"
Code: Select all
; Lire une chaine dans le registre
Procedure.s ReadRegKey(OpenKey.l,SubKey.s,ValueName.s) ; ====================================== ReadRegKey
;
hKey.l=0
keyvalue.s=Space(255)
DataSize.l=255
If RegOpenKeyEx_(OpenKey,SubKey,0,#KEY_READ,@hKey)
keyvalue=""
Else
If RegQueryValueEx_(hKey,ValueName,0,0,@keyvalue,@DataSize)
keyvalue=""
Else
keyvalue=Left(keyvalue,DataSize-1)
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn keyvalue
EndProcedure
ProcedureDLL.s getvoix( )
; retourne une chaine qui commence par le nombre de voix, suivi des noms des voix,separé par des virgules
; on peux tout recuperer avec stringfield ;o)
idx = 0
nom.s=""
NetBTKeyName.s = "SOFTWARE\Microsoft\Speech\Voices\Tokens"
NetBTKeyHandle.l = 0
RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, @NetBTKeyName, 0, #KEY_READ, @NetBTKeyHandle)
;Debug NetBTKeyHandle
keyLength = 255
keyname.s = Space(keyLength)
idx = 0
While RegEnumKeyEx_(NetBTKeyHandle, idx, @keyname, @keyLength, 0, 0, 0, 0) = 0
NetBTKeyName.s = "SOFTWARE\Microsoft\Speech\Voices\Tokens\"+keyname.s+"\Attributes\"
keyn.s= ReadRegKey(#HKEY_LOCAL_MACHINE, NetBTKeyName.s,"Name")
nom.s=nom.s+keyn+","
idx + 1
keyLength = 255
keyn=""
Wend
nom.s=Str(idx)+","+nom.s
nom.s=Left(nom.s,Len(nom.s)-1)
ProcedureReturn nom.s
EndProcedure
ProcedureDLL Speak(voix$,Text$,volume=100,vitesse=-3,pitch=0)
If voix$<>""
vox.s="<voice required="+Chr(34)+"Name="+ voix$+Chr(34)+"/>"+"<pitch absmiddle="+Chr(34)+Str(pitch)+Chr(34)+"/>"
Else
vox.s=""
EndIf
Interface ISpNotifySource Extends IUnknown
SetNotifySink(a)
SetNotifyWindowMessage(a,b,c,d)
SetNotifyCallbackFunction(a,b,c)
SetNotifyCallbackInterface(a,b,c)
SetNotifyWin32Event()
WaitForNotifyEvent(a)
GetNotifyEventHandle()
EndInterface
Interface ISpEventSource Extends ISpNotifySource
SetInterest(a,b)
GetEvents(a,b,c)
GetInfo(a)
EndInterface
Interface ISpVoice Extends ISpEventSource
SetOutput(a,b)
GetOutputObjectToken(a)
GetOutputStream(a)
Pause()
Resume()
SetVoice(a)
GetVoice(a)
Speak(a,b,c)
SpeakStream(a,b,c)
GetStatus(a,b)
Skip(a,b,c)
SetPriority(a)
GetPriority(a)
SetAlertBoundary(a)
GetAlertBoundary(a)
SetRate(a)
GetRate(a)
SetVolume(a)
GetVolume(a)
WaitUntilDone(a)
SetSyncSpeakTimeout(a)
GetSyncSpeakTimeout(a)
SpeakCompleteEvent()
IsUISupported(a,b,c,d)
DisplayUI(a,b,c,d,e)
EndInterface
Global VoiceObject.ISpVoice
#CLSCTX_INPROC_SERVER = $1
#CLSCTX_INPROC_HANDLER = $2
#CLSCTX_LOCAL_SERVER = $4
#CLSCTX_REMOTE_SERVER = $10
#CLSCTX_ALL = (#CLSCTX_INPROC_SERVER|#CLSCTX_INPROC_HANDLER|#CLSCTX_LOCAL_SERVER|#CLSCTX_REMOTE_SERVER)
CoInitialize_(0)
If CoCreateInstance_(?CLSID_SpVoice, 0, #CLSCTX_ALL, ?IID_ISpVoice, @VoiceObject.ISpVoice) = 0
VoiceObject\SetVolume(volume)
VoiceObject\SetRate(vitesse)
;VoiceObject\SetVoice({0879A4E0-A92C-11d1-B17B-0020AFED142E}) ; voix 0
length = Len(vox.s+Text$)*2+10
*mem = AllocateMemory(length)
Text$=vox.s+Text$
MultiByteToWideChar_(#CP_ACP ,0,Text$,-1,*mem, length)
VoiceObject\Speak(*mem,0,0)
FreeMemory(*mem)
Else
MessageRequester("ERROR","MS SPEECH API not installed",0)
EndIf
DataSection
CLSID_SpVoice:
;96749377-3391-11D2-9EE3-00C04F797396
Data.l $96749377
Data.w $3391,$11D2
Data.b $9E,$E3,$00,$C0,$4F,$79,$73,$96
IID_ISpVoice:
;6C44DF74-72B9-4992-A1EC-EF996E0422D4
Data.l $6C44DF74
Data.w $72B9,$4992
Data.b $A1,$EC,$EF,$99,$6E,$04,$22,$D4
EndDataSection
EndProcedure
;
; EPB
Use:
Speak(the name of the voice$,say the sentence$,Volume ,Speed Diction,Pitch)
Speed Diction and Pitch , depends on the voice used
Examples :
; **********************************************************************************
; in French
Speak( "ScanSoft Virginie_Dri40_16kHz" , "bonjour" , 100, 2, 150) ; if the voice Virginie installed
Speak( "eSpeak-FR" , "bonjour" , 100, 2, 150) ; if the voice Espeak installed
Speak( "eSpeak-FR+F2" , "bonjour" , 100, 2, 150) ; if the voice Espeak installed
; **********************************************************************************
; in english
Speak( "eSpeak-en" , "Hello" , 100, 2, 150) ; if the voice Espeak installed
Speak( "Microsoft Anna" , "hello" , 100, 2, 150) ; if the voice Microsoft Anna installed
; ***********************************************************************************
; EPB
the list of installed voices:
just With
voix$=getvoix( )
voix$=getvoix( ) ; on recupere le nombre et le nom des voix installé
; getvoix() retourne une chaine "nbr_de_voix,voix1$,voix2$,voix3$........ etc "
nombre = Val(StringField(voix$, 1, "," )) ; recupere le nombre de voix installé (premier element de la chaine)
voix$=Right(voix$,Len(voix$)- 2) ; on retire le nombre de voix, et sa virgule de la liste des noms de voix
For i= 1 To nombre ;
Debug StringField(voix$,i, "," ) ; ressort tout les noms des voix installées
Next i
These are the names that will be used with fonction Speak ()
