Ms Speech
Posted: Tue Feb 18, 2025 5:56 pm
Good morning,
the procedure below which uses an included file created by Justin.
https://www.purebasic.fr/english/viewto ... hilit=sapi
I don't know how to tell if a sound is playing or not!
Here is the procedure I use
Can you help me?
the procedure below which uses an included file created by Justin.
https://www.purebasic.fr/english/viewto ... hilit=sapi
I don't know how to tell if a sound is playing or not!
Here is the procedure I use
Code: Select all
XIncludeFile "sapihelper.pbi"
Procedure Lire_Texte(Texte.s, Vitesse.w = 0) ; Vitesse = 0, vitesse "normale" par défaut
Protected.IEnumSpObjectTokens cpEnum
Protected.ISpObjectToken voiceToken
Protected.ISpVoice pVoice
Protected.IID CLSID_SpVoice, IID_ISpVoice
Protected NewMap voicetokens.ISpObjectToken()
Protected.i voiceId
Protected.s name
Protected Numero_De_Voix.w
CoInitialize_(0)
IIDFromString_( #CLSID_SpVoice$, @CLSID_SpVoice )
IIDFromString_( #IID_ISpVoice$, @IID_ISpVoice )
If CoCreateInstance_( @CLSID_SpVoice, #Null, #CLSCTX_INPROC_SERVER, @IID_ISpVoice, @pVoice ) <> #S_OK
Debug "Failed To create voice opbject"
Else
pVoice\SetInterest( #SPFEI_ALL_EVENTS, #SPFEI_ALL_EVENTS )
If SpEnumTokens( #SPCAT_VOICES, "", "", @cpEnum ) <> #S_OK
Debug "Failed to enumerate voices"
Else
While cpEnum\Next( 1, @voiceToken, #Null ) = #S_OK
If voiceToken\GetId( @voiceId ) = #S_OK
voicetokens(GetFilePart(PeekS(voiceId)) ) = voiceToken
EndIf
Wend
cpEnum\Release()
ForEach voicetokens()
Numero_De_Voix + 1
If Numero_De_Voix = 2
pvoice\setvoice(voicetokens() )
pvoice\SetRate(Vitesse) ; Vitesse de lecture
pvoice\SetVolume(100) ; Volume
pvoice\speak( Texte, #SPF_ASYNC, #NUL) ; Lecture phrase en mode asynchrone
EndIf
Next
ForEach voicetokens()
voicetokens()\release()
Next
EndIf
EndIf
EndProcedure
Lire_Texte("Bonjour, comment vas-tu ?")
Delay(5000)