#include <GUIConstantsEx.au3>
Local $sVariable
GUICreate("", 173, 84, 192, 114)
$hInput = GUICtrlCreateInput("", 8, 8, 85, 21)
$hSave = GUICtrlCreateButton("Save", 8, 48, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hSave
$sVariable = GUICtrlRead($hInput)
MsgBox(0, "", "Переменная $Variable = " & $sVariable)
EndSwitch
WEnd
#include <Sound.au3>
#include <File.au3>
#include <Encoding.au3>
$sStringRus = 'Это вполне возможно, слушайте.'
$sStringEn = 'It is possible, listen up.'
$sUrlRus = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=' & _Encoding_URLToHex($sStringRus) & '&tl=ru'
$sUrlEn = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=' & _Encoding_URLToHex($sStringEn) & '&tl=en'
$sFileRus = _TempFile(@TempDir, 'rus_', '.mp3')
$sFileEn = _TempFile(@TempDir, 'en_', '.mp3')
$hDownload = InetGet($sUrlRus, $sFileRus, 17, 1)
Do
Sleep(20)
Until InetGetInfo($hDownload, 2)
If Not InetGetInfo($hDownload, 4) Then $fRus = True
InetClose($hDownload)
$hDownload = InetGet($sUrlEn, $sFileEn, 17, 1)
Do
Sleep(20)
Until InetGetInfo($hDownload, 2)
If Not InetGetInfo($hDownload, 4) Then $fEn = True
InetClose($hDownload)
If $fRus Then
$aSoundRus = _SoundOpen($sFileRus)
If Not @error Then
_SoundPlay($aSoundRus, 1)
_SoundClose($aSoundRus)
Sleep(500)
EndIf
EndIf
If $fEn Then
$aSoundEn = _SoundOpen($sFileEn)
If Not @error Then
_SoundPlay($aSoundEn, 1)
_SoundClose($aSoundEn)
EndIf
EndIf
FileDelete($sFileRus)
FileDelete($sFileEn)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <File.au3>
#include <Encoding.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate(" Переводчик Google", 300, 226, -1, -1, BitOR($WS_DLGFRAME,$WS_CLIPSIBLINGS))
$Edit1 = GUICtrlCreateEdit("", 0, 0, 299, 161)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Русский", 8, 168, 75, 25)
$Button2 = GUICtrlCreateButton("Английский", 112, 168, 75, 25)
$Button3 = GUICtrlCreateButton("Выход", 216, 168, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button3
Exit
Case $Button1
_SayRus(GUICtrlRead($Edit1))
Case $Button2
_SayEng(GUICtrlRead($Edit1))
EndSwitch
WEnd
Func _SayRus($Text)
$fRus = False
$sUrlRus = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=' & _Encoding_URLToHex($Text) & '&tl=ru'
$sFileRus = _TempFile(@TempDir, 'rus_', '.mp3')
$hDownload = InetGet($sUrlRus, $sFileRus, 17, 1)
Do
Sleep(20)
Until InetGetInfo($hDownload, 2)
If Not InetGetInfo($hDownload, 4) Then $fRus = True
InetClose($hDownload)
If $fRus Then
$aSoundRus = _SoundOpen($sFileRus)
If Not @error Then
_SoundPlay($aSoundRus, 1)
_SoundClose($aSoundRus)
Sleep(500)
EndIf
EndIf
FileDelete($sFileRus)
EndFunc
Func _SayEng($Text)
$fEn = False
$sUrlEn = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=' & _Encoding_URLToHex($Text) & '&tl=en'
$sFileEn = _TempFile(@TempDir, 'en_', '.mp3')
$hDownload = InetGet($sUrlEn, $sFileEn, 17, 1)
Do
Sleep(20)
Until InetGetInfo($hDownload, 2)
If Not InetGetInfo($hDownload, 4) Then $fEn = True
InetClose($hDownload)
If $fEn Then
$aSoundEn = _SoundOpen($sFileEn)
If Not @error Then
_SoundPlay($aSoundEn, 1)
_SoundClose($aSoundEn)
EndIf
EndIf
FileDelete($sFileEn)
EndFunc
Я бы функцию так сделал:Используй в виде функции:
#include <Sound.au3>
#include <File.au3>
#include <Encoding.au3>
_Say_In_Rus_or_En('Я бы функцию так сделал')
ConsoleWrite(@error & @LF)
_Say_In_Rus_or_En('I would have made the function so')
ConsoleWrite(@error & @LF)
_Say_In_Rus_or_En('1 2 3 4 5');рус.
ConsoleWrite(@error & @LF)
_Say_In_Rus_or_En('1 2 3 4 5', 1);англ.
ConsoleWrite(@error & @LF)
Func _Say_In_Rus_or_En($s_Text, $i_Flag = 0)
;$i_Flag - только для чисел, 0 - рус., не 0 - англ.
Local $s_Url = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=', $s_End = '&tl=', _
$s_Temp_FileMPEG, $h_Download, $ah_Sound, $i_Error, $i_Check_Rus, $i_Check_En, _
$sLang = 'ru'
If Not $s_Text Then Return SetError(1)
StringRegExpReplace($s_Text, '[а-яА-ЯёЁ]', '')
$i_Check_Rus = @extended
StringRegExpReplace($s_Text, '[a-zA-Z]', '')
$i_Check_En = @extended
If $i_Check_Rus And $i_Check_En Then Return SetError(1)
If Not $i_Check_Rus And Not $i_Check_En Then
StringRegExpReplace($s_Text, '[0-9]', '')
If Not @extended Then Return SetError(1)
If $i_Flag Then $sLang = 'en'
EndIf
$s_Text = _Encoding_URLToHex($s_Text)
If $i_Check_En Then $sLang = 'en'
$s_Url &= $s_Text & $s_End & $sLang
$s_Temp_FileMPEG = _TempFile(@TempDir, '~', '.mpeg')
$h_Download = InetGet($s_Url, $s_Temp_FileMPEG, 17, 1)
Do
Sleep(10)
Until InetGetInfo($h_Download, 2)
If InetGetInfo($h_Download, 4) Then $i_Error = 1
InetClose($h_Download)
If Not $i_Error Then
$ah_Sound = _SoundOpen($s_Temp_FileMPEG)
If Not @error Then
_SoundPlay($ah_Sound, 1)
_SoundClose($ah_Sound)
Else
$i_Error = 1
EndIf
EndIf
FileDelete($s_Temp_FileMPEG)
Return SetError($i_Error)
EndFunc ;==>_Say_In_Rus_or_En
Сейчас проверил, работает. Может у Вас кодеков нужных нет или сервис не работал?Раньше все было хорошо, а теперь...
До переустановки стоял K-Lite Codec Pack, сейчас установил - но проблема осталось. Чё за глюк ?! :blink:Может у Вас кодеков нужных нет или сервис не работал?
$s_Temp_FileMPEG = _TempFile(@TempDir, '~', '.mpeg')
If Not $i_Error Then
$ah_Sound = _SoundOpen($s_Temp_FileMPEG)
If Not @error Then
_SoundPlay($ah_Sound, 1)
_SoundClose($ah_Sound)
Else
$i_Error = 1
EndIf
EndIf
#include <Sound.au3>
Local $i_Error
If Not $i_Error Then
$ah_Sound = _SoundOpen("~emzicul.mpeg")
If Not @error Then
_SoundPlay($ah_Sound, 1)
_SoundClose($ah_Sound)
Else
$i_Error = 1
EndIf
EndIf
#include <File.au3>
#include <Encoding.au3>
_Say_In_Rus_or_En('Привет')
Func _Say_In_Rus_or_En($s_Text, $i_Flag = 0)
;$i_Flag - только для чисел, 0 - рус., не 0 - англ.
Local $s_Url = 'http://translate.google.ru/translate_tts?ie=UTF-8&q=', $s_End = '&tl=', _
$s_Temp_FileMPEG, $h_Download, $ah_Sound, $i_Error, $i_Check_Rus, $i_Check_En, _
$sLang = 'ru'
If Not $s_Text Then Return SetError(1)
StringRegExpReplace($s_Text, '[а-яА-яёЁ]', '')
$i_Check_Rus = @extended
StringRegExpReplace($s_Text, '[a-zA-Z]', '')
$i_Check_En = @extended
If $i_Check_Rus And $i_Check_En Then Return SetError(1)
If Not $i_Check_Rus And Not $i_Check_En Then
StringRegExpReplace($s_Text, '[0-9]', '')
If Not @extended Then Return SetError(1)
If $i_Flag Then $sLang = 'en'
EndIf
$s_Text = _Encoding_URLToHex($s_Text)
If $i_Check_En Then $sLang = 'en'
$s_Url &= $s_Text & $s_End & $sLang
$s_Temp_FileMPEG = _TempFile(@TempDir, '~', '.mp3')
$h_Download = InetGet($s_Url, $s_Temp_FileMPEG, 17, 1)
Do
Sleep(10)
Until InetGetInfo($h_Download, 2)
If InetGetInfo($h_Download, 4) Then $i_Error = 1
InetClose($h_Download)
If Not $i_Error Then
$oWMP = ObjCreate("WMPlayer.OCX.7")
$oWMP.Url = $s_Temp_FileMPEG
$oWMP.Controls.Play
Do
Until $oWMP.PlayState = 1
EndIf
FileDelete($s_Temp_FileMPEG)
Return SetError($i_Error)
EndFunc ;==>_Say_In_Rus_or_En