Что нового

Как задать переменную

zeionline

Новичок
Сообщения
36
Репутация
1
Код:
$sString1 = 'слово'
Как сделать чтоб переменную "слово" я задавал уже при включенном скрипте в окне.
Спасибо.
 

Fever

Скриптер
Сообщения
308
Репутация
112
Код:
#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
 
Автор
Z

zeionline

Новичок
Сообщения
36
Репутация
1
Как его объединить с эти скриптом я пробовал не получилось .

Код:
#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)
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Используй в виде функции:
Код:
#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
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Zaramot [?]
Используй в виде функции:
Я бы функцию так сделал:
Код:
#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
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Я исправил функцию _Say_In_Rus_or_En(), в ней ошибка была. :-[
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
madmasles
Недавно я переустановил себе винду. Так вот, эта функция ( _Say_In_Rus_or_En()) перестала работать. Не выдает ошибок и не озвучивает. Раньше все было хорошо, а теперь... В чем может быть проблема, не подскажете ? :(
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Zaramot [?]
Раньше все было хорошо, а теперь...
Сейчас проверил, работает. Может у Вас кодеков нужных нет или сервис не работал?
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Может у Вас кодеков нужных нет или сервис не работал?
До переустановки стоял K-Lite Codec Pack, сейчас установил - но проблема осталось. Чё за глюк ?! :blink:


Добавлено:
Сообщение автоматически объединено:

Файл создается:
Код:
$s_Temp_FileMPEG = _TempFile(@TempDir, '~', '.mpeg')

Но при его запуске, он проигрывается без звука. Вот созданный файл: ~emzicul.mpeg
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Проблема в этой части кода:
Код:
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

а именно в проигрывание файла. Щас попробую разобратся :smile:.
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
Код:
#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

у меня вин ХР сп3. все работает. я имею ввиду звук - "привет". правда установлены обновления после сп3. не думаю что это имеет решающее значение. из кодеков установлен K-Lite_Codec_Pack_720_Mega
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Александр, Я знаю что дело не в кодеках, у меня функции SoundPlay() и _SoundPlay() (из библиотеке Sound.au3) не работают. Почему ?? Пока не знаю...


Добавлено:
Сообщение автоматически объединено:

Нашел решение:
Код:
#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
 
Верх