TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
Micoute
Messages : 2583
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par Micoute »

Moi, j'ai fait comme ça.

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
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
jak64
Messages : 89
Inscription : dim. 03/mai/2020 23:16

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par jak64 »

Bonjour Micoute,
J'ai essayé le code, aucun son ne sort !

Code : Tout sélectionner

SpeakText("Bonjour, comment vas-tu ?")
Delay(5000)
Avatar de l’utilisateur
Micoute
Messages : 2583
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par Micoute »

Pourtant c'est avec ça que je fais parlé ma belle horloge que j'ai nommée "LAURE LOGE".
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
Micoute
Messages : 2583
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par Micoute »

Voilà comment ça fonctionne sur mon ordinateur.

Code : Tout sélectionner

XIncludeFile "D:\Programmation\Prg Perso\S\SAPI\Programme pour faire parler l'ordi.pb"

Global H = Hour(Date()), M = Minute(Date()), S = Second(Date()), T$ = ""

If M And S = 0
  T$ = Str(H) + " heures" + M + " minutes"
ElseIf M And S
  T$ = Str(H) + " heures" + M + " minutes"  + S + " secondes"
ElseIf M = 0
  T$ = Str(H) + " heures" + S + " secondes"
ElseIf M = 0 And S = 0
  T$ = Str(H) + " heures"
EndIf  

InitSpeech()
SpeakText(T$)
Il faudra que tu change le chemin.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
jak64
Messages : 89
Inscription : dim. 03/mai/2020 23:16

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par jak64 »

Thanks Micoute, I will test this code.
See you soon
Avatar de l’utilisateur
Micoute
Messages : 2583
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: TTS - Sapi 5 (XP et plus) et Speech SDK 11 (Vista et plus)

Message par Micoute »

C'est vrai qu'un petit exemple est mieux qu'un long discours.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Répondre