Choisir la voix du narrateur avec SAPI.SpVoice
Salut
Suite à cette discussion, voici 2 codes pour faire le choix du narrateur, un en VBScript direct et l'autre en VBScript dans un HTA/html.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Option Explicit
Dim Voix, ChoixVoix(), NomNarrateur(), Msg
Set Voix = CreateObject("SAPI.SpVoice")
'------------------------------------------------------------------------------------------------------------------
Sub RempliVoix()
Dim T, arrVoices
T = 1
MsG = ""
For Each arrVoices In Voix.GetVoices
ReDim Preserve ChoixVoix(T)
Set ChoixVoix(T) = arrVoices
ReDim Preserve NomNarrateur(T)
NomNarrateur(T) = ExtratNom(arrVoices.GetDescription())
If T = 1 Then
MsG = T & " " & NomNarrateur(T)
ELse
MsG = MsG & vbcrlf & T & " " & NomNarrateur(T)
End If
T=T+1
Next
End Sub
'------------------------------------------------------------------------------------------------------------------
Function ExtratNom(InfosVoix)
Dim RegularExpressioN, ResulT, Match
Dim MeStr
MeStr = Cstr(InfosVoix)
Set RegularExpressioN = New RegExp
RegularExpressioN.Pattern = " ([A-Za-z]*)"
RegularExpressioN.Global = False
Set ResulT = RegularExpressioN.Execute(MeStr)
Set Match = ResulT(0)
ExtratNom = Match.Value
End Function
'------------------------------------------------------------------------------------------------------------------
RempliVoix()' appel de la Sub pour récupérer les voix installées sur l'ordinateur
Voix.Speak "A que coucou,, une fois,, avant le choix. La voix en cours est la voix de,," & NomNarrateur(1)
Dim Rep
Rep = Trim(InputBox(Msg,"N° de la langue de votre choix? "))
If Len(Rep) <> 0 And IsNumeric(Rep) Then
If Rep <> 1 Then ' la voie N°1 est toujours celle en cours
Voix.Voice.Category.Default = ChoixVoix(Rep).Id
Voix.Speak "A que coucou, Vous avez choisi la voix de,, " & NomNarrateur(Rep)
Else
Voix.Speak "A que coucou, Vous n'avez pas choisi de modifié la voix"
End IF
End If
Set Voix = NotHing ' Nettoyage |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <HTML>
<HEAD lang="fr">
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Choisir la voix du narrateur</title>
<HTA:APPLICATION
MAXIMIZEBUTTON="no"
SCROLL="no"
BorderStyle="thin"
>
</HEAD>
<SCRIPT language="VBScript" type="text/vbscript">
'------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim ChemSleep, T
Dim Voix, ChoixVoix(), Nomnarrateur()
Set Voix = CreateObject("SAPI.SpVoice")
'------------------------------------------------------------------------------------------------------------------
Sub Window_Onload()
ResizeTo 500,380 'redimensionne la page HTA (largeur,Hauteur)
RempliVoix()
End Sub
'------------------------------------------------------------------------------------------------------------------
Sub Window_OnUnload()
Set Voix = NotHing
End Sub
'------------------------------------------------------------------------------------------------------------------
</SCRIPT>
<body>
Votre choix du narrateur: <select id="ListVoix" onChange="ListVoix_Click"> </SELECT><br />
Entrez un texte à lire<br /><textarea id="TxtData" Rows="12" Cols="54">
Au clair de la Lune
Mon ami Pierrot
Prête-moi ta plume
Pour écrire un mot
Ma chandelle est morte
Je n'ai plus de feu
Ouvre-moi ta porte
Pour l'amour de Dieu
Au clair de la Lune
Pierrot répondit
Je n'ai pas de plume
Je suis dans mon lit
Va chez la voisine
Je crois qu'elle y est
Car dans sa cuisine
On bat le briquet
Au clair de la Lune
On n'y voit qu'un peu
On cherche la plume
On cherche le feu
En cherchant d'la sorte
Je n'sais c'qu'on trouvera
Mais je sais qu'la porte
Sur eux se ferma</textarea><br />
<br />
<button id="BtGo" onclick="LireTexte"> Lire le texte </button><br />
<SCRIPT language="VBScript" type="text/vbscript">
'---------------------------------------------------------------------------------------------------------------
Sub RempliVoix()
Dim oOption
'recuperation des voix disponibles sur l'ordinateur
Dim arrVoices
T = -1
For Each arrVoices In Voix.GetVoices
T = T + 1
ReDim Preserve ChoixVoix(T)
Set ChoixVoix(T) = arrVoices
ReDim Preserve Nomnarrateur(T)
Nomnarrateur(T) = ExtratNom(arrVoices.GetDescription())
Set oOption = window.Document.createElement("OPTION")
oOption.Text = Nomnarrateur(T)'arrVoices.GetDescription()
oOption.Value = arrVoices.GetDescription()
ListVoix.Add (oOption)
Next
If T > 0 Then ListVoix.style.visibility = "visible" Else ListVoix.style.visibility = "hidden"
End Sub
'------------------------------------------------------------------------------------------------------------------
Function ExtratNom(InfosVoix)
Dim RegularExpressioN, ResulT, Match
Dim MeStr
MeStr = Cstr(InfosVoix)
Set RegularExpressioN = New RegExp
RegularExpressioN.Pattern = " ([A-Za-z]*)"
RegularExpressioN.Global = False
Set ResulT = RegularExpressioN.Execute(MeStr)
Set Match = ResulT(0)
ExtratNom = Match.Value
End Function
'------------------------------------------------------------------------------------------------------------------
Sub ListVoix_Click()
Dim Idx
For T = 0 to ListVoix.length - 1
If ListVoix(T).Selected then Idx = T: Exit For
Next
Voix.Voice.Category.Default = ChoixVoix(Idx).Id
End Sub
'------------------------------------------------------------------------------------------------------------------
Sub LireTexte()
Voix.Speak Trim(TxtData.value)
End Sub
</SCRIPT>
</body>
</HTML> |
Comment faire pour que mon app sapi lise en arabe ?
Bonjour à tous,
J'ai fait une app avec sapi vbs qui est en français. Je veux savoir comment faire pour qu'il lise en arabe.
Merci