I have a program, written a while ago that reads a text.
I used a procedure that I found on the forum.
It works very well with v6.12 of PureBasic but I would like to use another voice.
In the narrator, I have the voice: Microsoft Henri (Natural) - French (France).
This voice works perfectly when I use Narrator on my computer.
What I don't know how to do is what changes I need to make to my program to make it use this voice.
I asked ChatGpt, but he only offered me programs that didn't work... He doesn't have the level of all these nice forum users who have been helping me for several years...
Can you help me?
I would like to point out that I am French.
Code: Select all
EnableExplicit
Global silence.s
silence="."+Space(1)
silence=". "
Enumeration Fichier
#Fichier
EndEnumeration
;************** VALEUR POUR "SpeechVoiceSpeakFlags".*****************
Enumeration
#SVSFDefault = 0
#SVSFlagsAsync = 1
#SVSFPurgeBeforeSpeak = 2
#SVSFIsFilename = 4
#SVSFIsXML = 8
#SVSFIsNotXML = 16
#SVSFPersistXML = 32
#SVSFNLPSpeakPunc = 64
#SVSFNLPMask = 64
#SVSFVoiceMask = 127
#SVSFUnusedFlags = -128
EndEnumeration
Enumeration
#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)
EndEnumeration
Interface ISpeechVoice Extends IDispatch
get_Status(*ISpeechVoiceStatus .l)
get_Voice(*ISpeechObjectToken.l)
put_Voice(*ISpeechObjectToken.l)
get_AudioOutput(*ISpeechObjectToken.l)
put_AudioOutput(*ISpeechObjectToken.l)
get_AudioOutputStream(*ISpeechBaseStream.l)
put_AudioOutputStream(*ISpeechBaseStream.l)
get_Rate(long.l)
put_Rate(long.l)
get_Volume(long.l)
put_Volume(long.l)
put_AllowAudioOutputFormatChangesOnNextSet(VARIANT_BOOL.l)
get_AllowAudioOutputFormatChangesOnNextSet(VARIANT_BOOL.l)
get_EventInterests(SpeechVoiceEvents .l)
put_EventInterests(SpeechVoiceEvents .l)
put_Priority(SpeechVoicePriority.l)
get_Priority(SpeechVoicePriority.l)
put_AlertBoundary(SpeechVoiceEvents.l)
get_AlertBoundary(SpeechVoiceEvents.l)
put_SynchronousSpeakTimeout(long.l)
SynchronousSpeakTimeout(long.l)
Speak(*Text, SpeechVoiceSpeakFlags.l, long.l)
SpeakStream(*ISpeechBaseStream, SpeechVoiceSpeakFlags.l, long.l)
Pause()
Resume()
Skip(*Type, NumItems.l, long.l)
GetVoices(*RequiredAttributes.l, *OptionalAttributes, *ISpeechObjectTokens.l)
GetAudioOutputs(*RequiredAttributes, *OptionalAttributes, *ISpeechObjectTokens.l)
WaitUntilDone(msTimeout.l, VARIANT_BOOL.l)
SpeakCompleteEvent(long.l)
IsUISupported(*TypeOfUI, *ExtraData.VARIANT, VARIANT_BOOL.l)
DisplayUI(hWndParent.l, *Title, *TypeOfUI, *ExtraData.VARIANT)
EndInterface
Procedure.b isSAPIInstalled()
; VERIFICATION DE L'INSTALLATION DE SAPI 4 OU 5.
Define a.i
Define bresult.b = #False
CoInitialize_(0)
If CoCreateInstance_(?CLSID_SpVoice, 0, #CLSCTX_ALL, ?IID_ISpVoice, @a) = 0
bresult = #True
Else
If CoCreateInstance_(?CLSID_ITextToSpeech, 0, #CLSCTX_ALL, ?IID_ITextToSpeech, @a) = 0
bresult = #True
EndIf
EndIf
CoUninitialize_()
ProcedureReturn bresult
EndProcedure
Procedure SAPISpeechtext(stext.s, speed = 0)
Define.i itemp, bstrtext
Define text1.s
Define *buffer1, *buffer2, *buffer3
Define clsid.CLSID, refiid.CLSID
Define speechvoice.ISpeechVoice
If isSAPIInstalled() = #True And stext <> #Null$
text1 = "SAPI.SpVoice"
*buffer1 = AllocateMemory((Len(text1) + 1) * 2)
PokeS(*buffer1, text1, -1, #PB_Unicode)
text1 = "{269316D8-57BD-11D2-9EEE-00C04F797396}"
*buffer2 = AllocateMemory((Len(text1) + 1) * 2)
PokeS(*buffer2, text1, -1, #PB_Unicode)
If CLSIDFromProgID_(*buffer1, @Clsid.clsid) = #S_OK
If CLSIDFromString_(*buffer2, @Refiid.clsid) = #S_OK
CoInitialize_(0)
If CoCreateInstance_(clsid, #Null, #CLSCTX_INPROC_SERVER, refiid, @speechvoice) = #S_OK
*buffer3 = AllocateMemory((Len(stext) + 1) * 2)
PokeS(*buffer3, stext, -1, #PB_Unicode)
itemp = #SVSFDefault
bstrtext = SysAllocString_(*buffer3)
speechvoice\put_Rate(speed)
speechvoice\put_Volume(100)
speechvoice\Speak(bstrtext, 0, @itemp)
SysFreeString_(bstrtext)
FreeMemory(*buffer3)
speechvoice\Release()
EndIf
CoUninitialize_()
EndIf
EndIf
FreeMemory(*buffer1)
FreeMemory(*buffer2)
EndIf
EndProcedure
; Programme principal
Global TexteComplet$ = "Selon la Bible,. quelle créature a tenté Adam dans le jardin d'éden ?"
SAPISpeechtext(TexteComplet$, 0) ; -5=lent, 0=vitesse normale, 5 vitesse rapide
TexteComplet$ = ". A . un serpent"
SAPISpeechtext(TexteComplet$, 0) ; -5=lent, 0=vitesse normale, 5 vitesse rapide
TexteComplet$=". B . une colombe"
SAPISpeechtext(TexteComplet$, 0) ; -5=lent, 0=vitesse normale, 5 vitesse rapide
TexteComplet$=". C . un lapin"
SAPISpeechtext(TexteComplet$, 0) ; -5=lent, 0=vitesse normale, 5 vitesse rapide
TexteComplet$=". D . une cigogne."
SAPISpeechtext(TexteComplet$, 0) ; -5=lent, 0=vitesse normale, 5 vitesse rapide
End
; fin programme principal
DataSection
CLSID_SpVoice:
Data.l $96749377
Data.w $3391,$11D2
Data.b $9E,$E3,$00,$C0,$4F,$79,$73,$96
IID_ISpVoice:
Data.l $269316D8
Data.w $57BD,$11D2
Data.b $9E,$EE,$00,$C0,$4F,$79,$73,$96
CLSID_ITextToSpeech:
Data.l $EEE78591
Data.w $FE22,$11D0
Data.b $8B,$EF,$00,$60,$08,$18,$41,$DE
IID_ITextToSpeech:
Data.l $EEE78590
Data.w $FE22,$11D0
Data.b $8B,$EF,$00,$60,$08,$18,$41,$DE
EndDataSection


