Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando
-- Tutorial de iniciación a Autoit --
Volver al índice del tutorial
____________________________
29.- Texto a voz.
- Escribimos un texto y nos lo pronuncia en español.
- Es necesario incluir la librería:
#include <TTS.au3>
- TTS.au3
- Puedes instalar voces desde aquí: MicrosoftTTSVoices_Install.exe
- http://www.screamingbee.com/download/ScriptVOXStudio/MicrosoftTTSVoices_Install.exe
De texto a voz |
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TTS.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Texto a voz - Juan A. Villalpando", 528, 247, 192, 132)
$Label1 = GUICtrlCreateLabel("Escribe un texto: ", 24, 24, 104, 20)
$Edit1 = GUICtrlCreateEdit("", 144, 24, 361, 113)
GUICtrlSetData(-1, "Hola amigos. Espero que te guste este tutoriál")
$Button1 = GUICtrlCreateButton("Pulsa", 136, 168, 257, 49)
$Button2 = GUICtrlCreateButton("Borrar texto", 408, 168, 97, 49)
GUISetState(@SW_SHOW)
; Juan A. Villalpando
#EndRegion ### END Koda GUI section ###
$Default = _StartTTS()
If Not IsObj($Default) Then
MsgBox(0, 'Error', 'Error al crear el objeto StartTTS')
Exit
EndIf
MsgBox(0, 'Voces instaladas.', StringReplace(_GetVoices($Default, False), '|', @CRLF))
$Juan = _StartTTS()
_SetVoice($Juan, 'Juan')
If @error Then
_Speak($Default, 'La voz de Juan no está instalada.')
$Juan = False
EndIf
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
$Texto = GUICtrlRead($Edit1)
_SetRate($Juan, 2) ; Velocidad rápida de voz de Juan.
If IsObj($Juan) Then _Speak($Juan, $Texto)
_SetRate($Juan, -5) ; Velocidad lenta de voz de Juan.
If IsObj($Juan) Then _Speak($Juan, $Texto)
Case $msg = $Button2
GUICtrlSetData($Edit1,"")
EndSelect
Wend
Exit
|
_________________________________________
- Comentarios.
- Fíjate que he acentuado como aguda la palabra tutoriál, para que se pronuncie bien.
- Mediante esta línea salen las voces que tienes instaladas.
MsgBox(0, 'Voces instaladas.', StringReplace(_GetVoices($Default, False), '|', @CRLF))
- Este tutorial es una adaptación de:
- https://www.autoitscript.com/forum/topic/100439-text-to-speech-udf/
_________________________________________
- Otro código.
- https://www.autoitscript.com/forum/topic/12748-_talk-this-function-speaks-text-to-you/?page=2
De texto a voz |
#NoTrayIcon
#include <GUIConstants.au3>
Dim $voice = ObjCreate("Sapi.SpVoice")
$Error = ObjEvent("AutoIt.Error", "ErrFunc")
GUICreate("Talker", 600, 280)
$text = GUICtrlCreateInput("Escribe algo y te lo pronunciará.", 10, 10, 580, 50, $ES_MULTILINE)
$speak = GUICtrlCreateButton("Speak", 10, 65, -1, -1, $BS_DEFPUSHBUTTON)
GUICtrlCreateGroup("Options", 10, 100, 580, 170)
$rate = GUICtrlCreateSlider(20, 150, 280, 30, $TBS_TOP + $TBS_AUTOTICKS)
GUICtrlSetLimit($rate, 50, -50)
GUICtrlSetData($rate, 0)
$volume = GUICtrlCreateSlider(300, 150, 280, 30, $TBS_TOP + $TBS_AUTOTICKS)
GUICtrlSetLimit($volume, 100, 1)
GUICtrlSetData($volume, 100)
GUICtrlCreateLabel("Slow", 20, 185)
GUICtrlCreateLabel("Normal", 140, 185)
GUICtrlCreateLabel("Fast", 270, 185)
GUICtrlCreateLabel("Quiet", 310, 185)
GUICtrlCreateLabel("Loud", 550, 185)
GUICtrlCreateLabel("Voice:", 20, 233)
$voiceC = GUICtrlCreateCombo("Juan", 60, 230, 100)
Dim $SOTokens = $voice.GetVoices('', '')
For $Token In $SOTokens
GUICtrlSetData($voiceC, $Token.GetDescription)
Next
;~ GUICtrlSetData($voiceC, "Microsoft Mike|Microsoft Mary|LH Michael|LH Michelle")
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $speak
Speak(GUICtrlRead($text), GUICtrlRead($voiceC), GUICtrlRead($rate) / 10, GUICtrlRead($volume))
EndSwitch
WEnd
Func Speak($text, $SapiVoice, $rate = 1, $Vol = 100)
$voice.Rate = $rate
If @error Then Return
$voice.Volume = $Vol
If @error Then Return
Local $t_voice = $voice.GetVoices ("Name=" & $SapiVoice, "Language=409").Item (0)
If @error Then Return
$voice.Voice = $t_voice
If Not @error Then $voice.Speak ($text)
EndFunc ;==>Speak
Func ErrFunc()
MsgBox(48, "Error", "Tu ordenador no tiene instalada la voz de " & GUICtrlRead($voiceC) & ".")
SetError(1)
EndFunc ;==>ErrFunc
|
_________________
|