Code : Tout sélectionner
EnableExplicit
#CLSCTX_INPROC_SERVER = 1
;/Valeur pour SpeechVoiceSpeakFlags
#SVSFDefault = 0
Interface ISpeechVoice Extends IDispatch
    get_Status(*ISpeechVoiceStatus)
    get_Voice(*ISpeechObjectToken)
    put_Voice(*ISpeechObjectToken)
    get_AudioOutput(*ISpeechObjectToken)
    put_AudioOutput(*ISpeechObjectToken)
    get_AudioOutputStream(*ISpeechBaseStream)
    put_AudioOutputStream(*ISpeechBaseStream)
    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, *OptionalAttributes, *ISpeechObjectTokens)
    GetAudioOutputs(*RequiredAttributes, *OptionalAttributes, *ISpeechObjectTokens)
    WaitUntilDone(msTimeout.l, VARIANT_BOOL.l)
    SpeakCompleteEvent(long.l)
    IsUISupported(*TypeOfUI, *ExtraData.VARIANT, VARIANT_BOOL.l)
    DisplayUI(hWndParent.l, *Title, *TypeOfUI, *ExtraData.VARIANT)
EndInterface
Global SpeechVoice.ISpeechVoice
Global Texte1.s = "SAPI.SpVoice"
Global Texte2.s = "{269316D8-57BD-11D2-9EEE-00C04F797396}"
Procedure InitSpeech()
    Define Clsid.CLSID
    Define Refiid.CLSID
    Global *Tampon1 = AllocateMemory((Len(Texte1) + 1) * 2)
    PokeS(*Tampon1, Texte1, -1, #PB_Unicode)
    Global *Tampon2 = AllocateMemory((Len(Texte2) + 1) * 2)
    PokeS(*Tampon2, Texte2, -1, #PB_Unicode)
    If CLSIDFromProgID_(*Tampon1, @Clsid) = #S_OK
        If CLSIDFromString_(*Tampon2, @Refiid) = #S_OK
            CoInitialize_(0)
            If CoCreateInstance_(Clsid, #Null, #CLSCTX_INPROC_SERVER, Refiid, @SpeechVoice) = #S_OK
                ; Synthèse vocale initialisée avec succès
                ProcedureReturn #True
            EndIf
            CoUninitialize_()
        EndIf
    EndIf
    FreeMemory(*Tampon1)
    FreeMemory(*Tampon2)
    ProcedureReturn #False
EndProcedure
Procedure SpeakText(text.s)
    If SpeechVoice
        SpeechVoice\Speak(SysAllocString_(text), #SVSFDefault, 0)
    EndIf
EndProcedure