Jump to content

JonF

Active Members
  • Posts

    51
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

JonF's Achievements

Wayfarer

Wayfarer (2/7)

2

Reputation

  1. I have that. It doesn't work. The denial seems to be based on too many requests from my IP.
  2. Ah, that's it. If I use a VPN it works.
  3. This is driving me crazy. This worked flawlessly for months. Two days ago it stopped working with an "The requested action with this object has failed." error. I ran SFC. I restored the entire C drive to the day before from a Macrium Reflect image. I rewrote it to use the WinHttp.au3 UDF. I uninstalled and reinstalled AutoIT. I ran it in Steve Towner's GUI debugger (https://web.archive.org/web/20220401023656/https://www.thefoolonthehill.net/drupal/AutoIt Debugger) and verified the objects were objects. I've Googled the error and gotten many hits, none of which explain WTF should be done. If I un-comment the "$objErr =..." line the error message is "Access is denied". Help?? Func _GoogleAPITranslate($sMytext, $sFrom, $sTo) Global $objErr Local $sUrl,$sResponse, $JSONData, $sOutput = "", $aData ; $objErr = ObjEvent("AutoIt.Error","MyErrFunc") $oSC = ObjCreate("ScriptControl") $oSC.language = "Javascript" $g_sMytext = $oSC.eval("encodeURI('" & $sMytext & "');") $sUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $g_sMytext $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP = ObjCreate("Msxml2.XMLHTTP.6.0") $oHTTP.Open("POST", $sUrl, False) $oHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded') $oHTTP.Send() $sResponse = $oHTTP.ResponseText EndFunc ;==>_GoogleAPITranslate Func MyErrFunc() MsgBox(48, 'COM Error', $objErr.description) SetError(1) EndFunc ; https://www.autoitscript.com/forum/topic/202204-simple-google-translate/?do=findComment&comment=1505984 Func TestTranslate() MsgBox(0,'Output',_GoogleAPITranslate('Hello world','en','uk')) EndFunc TestTranslate()
  4. I followed TheXman's advice and got it to work using COM. ; Example of using the Windows Component Object Model to call the SpeechGen API #include <MsgBoxConstants.au3> #include <StringConstants.au3> ; Data for SpeechGen Local $Token = "SecretKeyInYourProfile", _ $Email = "YourEmail@gmail.com, _ $Text = "Привіт шановний", _ $Voice = "Ostap", _ $Format = "mp3", _ $Speed = "0.8" ; All arguments are strings. Arguments given defalt values are optional, but you cannot ; specify any arguments after using an argument with a default. See the test below, where ; $sFormat must be specified because $sSpeed is specified. ; Return value: URL of the speak file and set @error=0 if the process worked, ; error message string and set @error=1 if it did not. Func SpeechGen($sToken, $sEmail, $sData, $sVoice, $sFormat = "mp3", $sSpeed = "1.0", $sEmotion = "good", _ $sPause_sentence = "300", $sPause_paragraph = "400", $sBitrate = "48000") $sRequest = 'token=' & $sToken & '&email=' & $sEmail & '&voice=' & $sVoice _ & '&format=' & $sFormat & '$speed=' & $sSpeed & '&emotion=' & $sEmotion _ & '&pause_sentence=' & $sPause_sentence & '&pause_paragraph=' _ & $sPause_paragraph & '&bitrate=' & $sBitrate & '&text=' & $sData ; MsgBox($MB_OK, "Request",$sRequest) Global $oMyError = ObjEvent("AutoIt.Error", "MyCOMErrFunc") ; Initialize a COM error handler Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://speechgen.io/index.php?r=api/text", False) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($sRequest) Local $oReceived = $oHTTP.ResponseText $SpeechGenError = StringRegExp($oReceived, 'https:.*?\.mp3', $STR_REGEXPARRAYMATCH) ConsoleWrite(@CRLF & "Received: " & $oReceived & @CRLF) ;MsgBox($MB_OK, "Received", $oReceived) Local $SpeechGenError = StringRegExp($oReceived, 'error":".*?"', $STR_REGEXPARRAYMATCH) If StringLen($SpeechGenError[0]) > 9 Then Local $sErrorMessage = StringReplace(StringTrimLeft($SpeechGenError[0], 7), '"', "") MsgBox(BitOR($MB_ICONERROR, $MB_OK), "Error", $sErrorMessage & @CRLF & @CRLF & $oReceived, 10) Return SetError(1, 1, $sErrorMessage) Else $sURLReceived = StringRegExp($oReceived, 'https:.*?\.mp3', $STR_REGEXPARRAYMATCH) ConsoleWrite(@CRLF & "URL: " & StringReplace($sURLReceived[0], "\", "") & @CRLF & @CRLF) Return SetError(0, 0, StringReplace($sURLReceived[0], "\", "")) EndIf EndFunc ;==>SpeechGen ; COM error handler Func MyCOMErrFunc() MsgBox(0, "AutoItCOM", "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) EndFunc ;==>MyCOMErrFunc ; Test the system Func TestSpeechGen() Local $Result = SpeechGen($Token, $Email, $Text, $Voice, $Format, $Speed) If @error = 0 Then MsgBox($MB_OK, "URL of file", $Result) ; Un-comment to download the MP3 ; InetGet($Result, @ScriptDir & "\Result.mp3") Else MsgBox(BitOR($MB_ICONERROR, $MB_OK), "Error", $Result) EndIf EndFunc ;==>TestSpeechGen
  5. Your edited example doesn't work for me. I changed only the cURL path, token, and email. Response Body: {"id":0,"status":-1,"file":"","file_cors":"","parts":0,"parts_done":0,"duration":0,"format":"mp3","error":"Data is empty , use Post or Get request","balans":0}
  6. I appreciate your attempt, but perhaps you should have read the tropic before stepping in. The site will not accept those headers and will not accept a JSON formatted query and will not accept an unencoded string for the "text" parameter. After modifying until it works it fails in the same manner: POST Data:      "token=-redacted-&email=email%40gmail.com&voice=Ostap&format=mp3&speed=0.8&emotion=good&pause_sentence=300&pause_paragraph=400&bitrate=48000&text=%D0%9F%D1%80%D0%B8%D0%B2%D1%96%D1%82+%D1%88%D0%B0%D0%BD%D0%BE%D0%B2%D0%BD%D0%B8%D0%B9" Curl RetCode:   0 No error HTTP Resp Code: 200 Content Type:   text/html; charset=UTF-8 Content Size:   159 Response Headers: Response Body: HTTP/1.1 200 OK Server: nginx/1.14.1 Date: Thu, 14 Nov 2024 19:36:04 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/7.3.33 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST Access-Control-Allow-Headers: X-Requested-With Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Set-Cookie: PHPSESSID=3f0b423fffdf24f42b2f966cba92c010; path=/ {"id":0,"status":-1,"file":"","file_cors":"","parts":0,"parts_done":0,"duration":0,"format":"mp3","error":"Data is empty , use Post or Get request","balans":0} I looked at winhttp and couldn't make head nor tail of it. Using COM objects I don't understand at all. I'll try that again. I'm a novice at AUtoIT but give me FORTRAN, Basic, i386 assembly language, or IBM 370 assembly language I can run rings around you. I'll look at WinHTTP.au3 again.
  7. It needs Curl_Easy_Setopt($hCurl, $CURLOPT_SSL_VERIFYPEER, 0) Still fails, same way. I have their PHP example working but that's really inconvenient.😁
  8. Thanks for catching another error, but that's not it. It's the value of CURLOPT_POSTFIELDS. I've discovered that the site wants the data URI encoded in a weird format with the only header "Content-Type: application/x-www-form-urlencoded". I have had success with ShellExecuteWait with curl.exe: #include <FileConstants.au3> #include <StringConstants.au3> Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] ; ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode Global $Text,$data, $sAddress = 'https://speechgen.io/index.php?r=api/text', $cURLPath = "C:\Program Files\curl-8.11.0_1\bin\curl" $Text = 'Привіт шановний' $Command = ' --data "token=-redacted-&email=email%40gmail.com&' & _ 'voice=Ostap&format=mp3&speed=0.8&emotion=good&pause_sentence=300&pause_paragraph=400&bitrate=48000&text=' & _ _URIEncode($Text) & '" -k -H "Content-Type: application/x-www-form-urlencoded" ' _ & $sAddress & ' >' & @ScriptDir & '\Result.txt' $Result = ShellExecuteWait($cURLPath, $Command, "", "", @SW_MINIMIZE) (Note the encoded "@" in the email adress.) Which produces: {"id":"32796442","status":1,"file":"https:\/\/speechgen.io\/texttomp3\/20241104\/p_32107758_128.mp3","file_cors":"https:\/\/speechgen.io\/index.php?r=site\/download&prj=32796442&cors=28ee739ca163e1cb41b3b241d677d499","parts":0,"parts_done":0,"duration":"2","format":"mp3","error":"","balans":"19691","cost":"0"} However, this: #include <WinAPIDiag.au3> #include <Curl\Curl.au3> ; Beege rewrite #include <Constants.au3> Func _URIEncode($sData) Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc Test() Func Test() Local $arrHeaders = Curl_Slist_Append(0, "Content-Type: application/x-www-form-urlencoded") $Text = "Привіт шановний" ;Set up and execute cURL request $hCurl = Curl_Easy_Init() If Not $hCurl Then Return MsgBox($MB_ICONERROR, "Error", "Curl_Easy_Init() failed.") Curl_Easy_Setopt($hCurl, $CURLOPT_URL, "https://speechgen.io/index.php?r=api/text") Curl_Easy_Setopt($hCurl, $CURLOPT_HTTPHEADER, $arrHeaders) Curl_Easy_Setopt($hCurl, $CURLOPT_VERBOSE, 1) Curl_Easy_Setopt($hCurl, $CURLOPT_USERAGENT, "AutoIt/cURL") Curl_Easy_Setopt($hCurl, $CURLOPT_SSL_VERIFYPEER, 0) Curl_Easy_Setopt($hCurl, $CURLOPT_READFUNCTION, Curl_DataReadCallback()) Curl_Easy_Setopt($hCurl, $CURLOPT_CUSTOMREQUEST, "PUT") Curl_Easy_Setopt($hCurl, $CURLOPT_UPLOAD, 1) Curl_Easy_Setopt($hCurl, $CURLOPT_POST, 1) $data = '"token=-redacted-&email=email%40gmail.com&', & _ 'voice=Ostap&format=mp3&speed=0.8&emotion=good&pause_sentence=300&pause_paragraph=400&bitrate=48000&text=' & _ _URIEncode($Text) & '"' ConsoleWrite(@crlf & $data & @crlf & @crlf) Curl_Easy_Setopt($hCurl, $CURLOPT_POSTFIELDS, $data) $iRespCode = Curl_Easy_Perform($hCurl) If $iRespCode <> $CURLE_OK Then Return ConsoleWrite("Status Message: " & Curl_Easy_StrError($iRespCode) & @LF) $sResponse = BinaryToString(Curl_Data_Get($hCurl)) ;Clean up curl environment Curl_Easy_Cleanup($hCurl) Curl_Data_Cleanup($hCurl) ;Display response ConsoleWrite($sResponse & @CRLF) EndFunc Produces: {"id":0,"status":-1,"file":"","file_cors":"","parts":0,"parts_done":0,"duration":0,"format":"mp3","error":"Data is empty , use Post or Get request","balans":0}+>09:44:47 AutoIt3.exe ended.rc:0 Note "error":"Data is empty , use Post or Get request" I tried setting up a pointer a found at: ;Create binary buffer and store http post data in it $tByteBuffer = DllStructCreate("byte buffer[1000];") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Failed to create string buffer - @error = " & @error) $tByteBuffer.buffer = $data Curl_Easy_Setopt($hCurl, $CURLOPT_POSTFIELDS, $tByteBuffer.buffer) But it made no difference.
  9. Ah, you're right. It's a mistake from the original source. Thanks. Alas, fixing it doesn't change anything.
  10. I got the base code from the bottom of https://www.autoitscript.com/forum/topic/207859-curl-udf-libcurl-with-x64-support/page/2/#comments. It wasn't working. The coment that fixed it was on the next page. But I can't figure out what that means.
  11. It appears to be correct. CURLOPT_HTTPHEADER explained
  12. I'm trying to upload to a text-to-speech website. (Beege rewrite of Curl.au3). #include <Date.au3> #include <WinAPIDiag.au3> #include <Curl\Curl.au3> Test() Func Test() ;Create an array of request headers Local $arrHeaders = Curl_Slist_Append(0, "Accept: application/json") $arrHeaders = Curl_Slist_Append($arrHeaders, "Content-Type: application/json") ;Set up and execute cURL request $hCurl = Curl_Easy_Init() If Not $hCurl Then Return MsgBox($MB_ICONERROR, "Error", "Curl_Easy_Init() failed.") Curl_Easy_Setopt($hCurl, $CURLOPT_URL, "https://speechgen.io/index.php?r=api/text") Curl_Easy_Setopt($hCurl, $CURLOPT_HTTPHEADER, $aHeaders) Curl_Easy_Setopt($hCurl, $CURLOPT_USERAGENT, "AutoIt/cURL") Curl_Easy_Setopt($hCurl, $CURLOPT_VERBOSE, 1) Curl_Easy_Setopt($hCurl, $CURLOPT_SSL_VERIFYPEER, 0) Curl_Easy_Setopt($hCurl, $CURLOPT_READFUNCTION, Curl_DataReadCallback()) Curl_Easy_Setopt($hCurl, $CURLOPT_CUSTOMREQUEST, "PUT") Curl_Easy_Setopt($hCurl, $CURLOPT_UPLOAD, 1) $data = '{"Token":"{redacted}","email":"email@gmail.com","voice":"Ostap","format":"mp3","speed":"0.8","emotion":"good", _ "pause_sentence":"300","pause_paragraph":"400","bitrate":"48000",' $data = $data & '"text":"' & 'Heo світ' & '"}' ConsoleWrite(@crlf & $data & @crlf & @crlf) Curl_Easy_Setopt($hCurl, $CURLOPT_POSTFIELDS, $data) ;Get response code and response $iRespCode = Curl_Easy_Perform($hCurl) If $iRespCode <> $CURLE_OK Then Return ConsoleWrite("Status Message: " & Curl_Easy_StrError($iRespCode) & @LF) $sResponse = BinaryToString(Curl_Data_Get($hCurl)) ;Clean up curl environment Curl_Easy_Cleanup($hCurl) Curl_Data_Cleanup($hCurl) ;Display response ConsoleWrite($sResponse & @CRLF) EndFunc ;==>Test The result is: * Host speechgen.io:443 was resolved. * IPv6: (none) * IPv4: 5.45.72.182 * Trying 5.45.72.182:443... * ALPN: curl offers h2,http/1.1 * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / [blank] / UNDEF * ALPN: server accepted http/1.1 * Server certificate: * subject: CN=speechgen.io * start date: Sep 15 23:13:56 2024 GMT * expire date: Dec 14 23:13:55 2024 GMT * subjectAltName: host "speechgen.io" matched cert's "speechgen.io" * issuer: C=US; O=Let's Encrypt; CN=R10 * SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway. * Certificate level 0: Public key type ? (2048/112 Bits/secBits), signed using sha256WithRSAEncryption * Certificate level 1: Public key type ? (2048/112 Bits/secBits), signed using sha256WithRSAEncryption * Connected to speechgen.io (5.45.72.182) port 443 * using HTTP/1.x > PUT /index.php?r=api/text HTTP/1.1 Host: speechgen.io User-Agent: AutoIt/cURL Accept: */* Content-Type: application/json Content-Length: 4 * upload completely sent off: 4 bytes < HTTP/1.1 200 OK < Server: nginx/1.14.1 < Date: Mon, 11 Nov 2024 16:06:28 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < X-Powered-By: PHP/7.3.33 < Access-Control-Allow-Origin: * < Access-Control-Allow-Methods: GET, POST < Access-Control-Allow-Headers: X-Requested-With < Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate < Pragma: no-cache < Set-Cookie: PHPSESSID=e271ada2cc0504802aa013ef915dfc55; path=/ < * Connection #0 to host speechgen.io left intact {"id":0,"status":-1,"file":"","file_cors":"","parts":0,"parts_done":0,"duration":0,"format":"mp3","error":"Data is empty , use Post or Get request","balans":0} Apparently it's not getting my data as a POST request??
  13. Oooh, GetScreen worked. I don't remember why I chose Get Window. Thank you!
  14. I'm trying to read a pixel from the screen of a particular program. It always comes out black (0x000000). One should be white, the other should be blue. Is there some aspect of this program that prevents reading a pixel? #include <GetScreen.au3> Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc Run("C:\Program Files (x86)\YT Saver\ytsaverw.exe",@TempDir,@SW_MAXIMIZE) Opt("WinTitleMatchMode", 2) _WinWaitActivate("YT Saver","") $Handle = WinGetHandle("YT Saver") Sleep(5000) $aWin = WinGetPos($Handle) $Width = $aWin[2] $Height = $aWin[3] _GetScreen_Initialize($Width, $Height) _GetScreen_GetWindow($Handle) $Color = _GetScreen_GetPixel(350,200) $Color2 = _GetScreen_GetPixel(110,90) WinClose($Handle) $Color=Hex($Color,6) $Color2=Hex($Color2,6) MsgBox(0,"Info",$Color & " " & $Color2 & @CRLF & $Width & " " & $Height) Test.mp4
  15. I did. It didn't cover stderr. didn't help much.
×
×
  • Create New...