Nov 302010
Esta función sirve para utilizar el API Speak de Google, con la cual podemos llevar un texto a voz de máquina, esta api sólo se limita a cien caracteres, y por supuesto necesitamos de internet para que funcione.
El primer parámetro es el texto que queremos escuchar, el segundo el idioma o mejor dicho la pronunciación, en el caso de español es «es» para otros por ejemplo:
Alemán: de
Danés: da
Español: es
Finlandia: fi
Francés: fr
Inglés: en
Italiano: it
Neerlandés: nl
Polaco: pl
Portugués: pt
Sueco: sv
y el tercer parámetro es para llamar a DoEvents si es que lo deseamos.
Option Explicit
'-----------------------------------------------------------------------------------------------------
'Autor: Leandro Ascierto
'Web: www.leandroascierto.com.ar
'Abreviaturas
'de, da, es, fi, fr, en, it, nl, pl, pt, sv"
'Alemán , Danés, Español, Finlandia, Francés, Inglés, Italiano, Neerlandés, Polaco, Portugués, Sueco
'----------------------------------------------------------------------------------------------------
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function GoogleSpeak(ByVal sText As String, Optional ByVal Language As String = "es", Optional ByVal bDoevents As Boolean) As Boolean
On Error Resume Next
Dim sTempPath As String, ml As String
Dim FileLength As Long
sText = Replace(sText, vbCrLf, " ")
If Len(sText) > 100 Then Exit Function
sTempPath = Environ("Temp") & "\TempMP3.MP3"
If URLDownloadToFile(0&, "http://translate.google.com/translate_tts?tl=" & Language & "&q=" & sText, sTempPath, 0&, 0&) = 0 Then
If mciSendString("open " & Chr$(34) & sTempPath & Chr$(34) & " type MpegVideo" & " alias myfile", 0&, 0&, 0&) = 0 Then
ml = String(30, 0)
Call mciSendString("status myfile length ", ml, 30, 0&)
FileLength = Val(ml)
If FileLength Then
If mciSendString("play myFile", 0&, 0&, 0&) = 0 Then
Do While mciSendString("status myfile position ", ml, 30, 0&) = 0
If Val(ml) = FileLength Then GoogleSpeak = True: Exit Do
If bDoevents Then DoEvents
Loop
End If
End If
Call mciSendString("close myfile", 0&, 0&, 0&)
End If
Kill sTempPath
End If
End Function
Private Sub Command1_Click()
Debug.Print GoogleSpeak("Antes era sexo droga y rock and roll, ahora es paja mate y chamame", "es", True)
End Sub
Message…
There is noticeably a bundle to know about this. I assume you made certain nice points in features also….
Hola amigo, gracias por el código! Pero aquí no he podido hacer funcionar de ninguna manera … ¿Podría poner a disposición el proyecto para descargar por favor? ¡Un abrazo!