Jump to content

Recommended Posts

Posted

Hi everyone its been loooong since I posted here :D:lol:

I have been trying to convert this curl executable parameters into autoit using the winhttp com object;

curl -F data_file=@my_audio_file.mp3 -F model=en-US "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###"

any ideas guys:D:)

 

PS: I am excited to post here after a looong time:lol:

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

  • 2 weeks later...
Posted (edited)
On 7/2/2018 at 11:20 AM, Surya said:

I have been trying to convert this curl executable parameters into autoit using the winhttp com object

Where is your attempt so that we can see where you are having a problem and give you some advice or guidance?

 

Edited by TheXman
Removed part about bumping post.
Posted

hi @TheXman I am very  poor in winhttp handling this is were I have reached ,I don't know wether it is right or not

Local $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOWZkMDYwZWI3Zjg0"
Local $boundary = "--------Boundary"

Local $Postdata = "--" & $boundary & @CRLF & _
"Content-Disposition: form-data; model=en-US; data_file=" & '"' & filename($filepath) & '"' & @CRLF & _
"Content-Type: data_file" & @CRLF & @CRLF & _
Binary(FileRead($filepath)) & @CRLF & _
"--" & $boundary & "--" & @CRLF



Local $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $boundary)
$oHTTP.Send("model=en-US; data_file=" &Binary(FileRead($filepath)));$Postdata)
$hotlink = $oHTTP.ResponseText

 

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Posted

Here is a good example of one way to do a POST that uploads a file:

 

It uses winhttp.au3.  You can find a link the latest version of winhttp.au3 using the link below.  The zip file includes documentation that explains the winhttp.au3 functions and has several examples.

 

Assuming that you are calling the Speechmatic API correctly, this should get you closer to your goal.  If you run into an obstacles implementing the API using the example above, post back and we'll see if we can help you get past it.

 

Posted (edited)

Hello Using WinHttp UDF you could do this:

#include "WinHTTP.au3"
Global Const $sFileToUpload = "C:\Users\User\Desktop\WinHttp\test.mp3" ;<- Set correct file location here
Global Const $sAddress = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###" ;<- Set correct host here

Local $sForm = _
        '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _
        '    <input type="file" name="data_file" />' & _
        '    <input type="submit" name="model" value="en-US">' & _
        '</form>'

; Initialize and get session handle
$hOpen = _WinHttpOpen()

$hForm = $sForm

; Fill form on this page
$sRead = _WinHttpSimpleFormFill($hForm, $hOpen, Default, "name:data_file", $sFileToUpload)

; Close connection handle
_WinHttpCloseHandle($hForm)
; Close session handle
_WinHttpCloseHandle($hOpen)

; See what's returned (in default browser or whatever)
If $sRead Then
    ConsoleWrite($sRead & @CRLF)
EndIf

Saludos

Edited by Danyfirex
Posted (edited)

.

Edited by TheXman
Removed content of my reply because it didn't add anyhting to the topic..
  • 2 weeks later...
Posted

voila everyone this is where I am I am unable to using winhttp it shows this

{
  "code": 400, 
  "error": "Missing data_file"
}
test.wav

 

this is the code

$filepath = FileOpenDialog("Select",@ScriptDir,"All (*.*)")
$filepah = FileOpen($filepath,16)
$output = AnonFilesUpload($filepath)

ConsoleWrite(filename($filepath) & @CRLF)
ConsoleWrite($output & @CRLF)

Func AnonFilesUpload($filepath)

 $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOMDYwZWI4Zjg0"
 $boundary = "------------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
 ; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
   ;"Content-Type: submit" &@CRLF & _
 $Postdata = "--" & $boundary & @CRLF & _
   "Content-Disposition: form-data; name=" &'"' &"data_file" &'"' &"; filename=" &'"' &filename($filepath) &'"' &@CRLF & _
   "Content-Type: audio/x-wav" & @CRLF & @CRLF & _
   BinaryToString(FileRead($filepah)) & @CRLF &@CRLF & _
   "--" & $boundary  &@CRLF & _
   'Content-Disposition: form-data; name="model"' &@CRLF &@CRLF & _
   'en-US' &@CRLF & _
   "--" & $boundary & "--" &@CRLF
MsgBox(Default,Default,$Postdata)

 $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
 $oHTTP.Open("POST", $sServerURL, False)
 $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $boundary)
 $oHTTP.SetRequestHeader("Accept","application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
 $oHTTP.SetRequestHeader("Accept","utf-8;q=0.7")
 $oHTTP.Send($Postdata)
 $oHTTP.WaitForResponse()
 $hotlink = $oHTTP.ResponseText
 ConsoleWrite($hotlink)
 $hotlink = StringRegExpReplace(StringMid($hotlink, StringInStr($hotlink, "https")), '[/"}]', "")
   Return $hotlink
EndFunc

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

I took the code from here 

and tried to modify it but it wont work,Can anyone please help me where I am wrong

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

  • 3 weeks later...
Posted

 I made it till here what am I missing again

$filepath = FileOpenDialog("Select",@ScriptDir,"All (*.*)")
$filepah = FileOpen($filepath)
$output = AnonFilesUpload($filepath)

ConsoleWrite(filename($filepath) & @CRLF)
ConsoleWrite($output & @CRLF)

Func AnonFilesUpload($filepath)

 $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhUtOWZkMDYwZWI4Zjg0"
 $boundary = "------------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
 ; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
   ;"Content-Type: submit" &@CRLF & _
 $Postdata = '--' & $boundary & @CRLF & _
   'Content-Disposition: form-data; name="model"' &@CRLF &@CRLF & _
   'en-US' &@CRLF & _
   '--' & $boundary &@CRLF & _
   'Content-Disposition: form-data; name="data_file"; filename=' &'"' &filename($filepath) &'"' &@CRLF & _
   'Content-Type: audio/x-wav' & @CRLF & @CRLF & _
    FileRead($filepah)   & @CRLF & _
   '--' & $boundary & '--'
   MsgBox(Default,Default,$Postdata)

 $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
 $oHTTP.Open("POST", $sServerURL, False)
 $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" & $boundary)
 $oHTTP.SetRequestHeader("Accept","application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
 $oHTTP.SetRequestHeader("Accept","utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length',StringLen($Postdata))
 $oHTTP.Send($Postdata)
 $oHTTP.WaitForResponse()
 $hotlink = $oHTTP.ResponseText
 ConsoleWrite($hotlink)
 $hotlink = StringRegExpReplace(StringMid($hotlink, StringInStr($hotlink, "https")), '[/"}]', "")
   Return $hotlink
EndFunc

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

can someone help me..

while exexuting this i get this

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
{
  "code": 403, 
  "error": "Job rejected due to invalid audio"
}
tmp.wav

+>08:33:04 AutoIt3.exe ended.rc:0
+>08:33:04 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 21.53

 

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Posted

Does this work?

 

$filepath=@ScriptDir & "\test.mp3"
$sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhUtOWZkMDYwZWI4Zjg0"
$boundary = "------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
;"Content-Type: submit" &@CRLF & _
$Postdata = $boundary & @CRLF & _
        'Content-Disposition: form-data; name="data_file"; filename="' & filename($filepath) & '"' & @CRLF & _
        'Content-Type: audio/mpeg' & @CRLF & @CRLF & _
        FileRead($filepath) & @CRLF & _
        $boundary  & @CRLF & _
        'Content-Disposition: form-data; name="model"' & @CRLF & @CRLF & _
        'en-US' & @CRLF & _
        $boundary & "--" & @CRLF



;~ ConsoleWrite($Postdata & @CRLF)
;~ Exit

$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("Content-Type", 'multipart/form-data; boundary=----WinHttpBoundaryLine_51560.17967')
$oHTTP.SetRequestHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
$oHTTP.SetRequestHeader("Accept-Charset", "utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length', StringLen($Postdata))
$oHTTP.Send($Postdata)
$oHTTP.WaitForResponse()
$hotlink = $oHTTP.ResponseText
ConsoleWrite($hotlink)

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

Saludos

Posted (edited)

@Danyfirex it didn't work:(:'(:'(:'(

but the winhttp udf thing worked well,why doesn't the code work are we making any mistake or is it that my winhttp versions are not correct

I copy pasted ur code

screenshots attatched

Screenshot (16).png

Edited by Surya

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Posted

Hello. Here you have.

$filepath=@ScriptDir & "\zero.wav"
$sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOWZkMDYwZWI4Zjg0"
$boundary = "------WinHttpBoundaryLine_96747.69683"
$Postdata = $boundary & @CRLF & _
        'Content-Disposition: form-data; name="data_file"; filename="' & filename($filepath) & '"' & @CRLF & _
        'Content-Type: application/octet-stream' & @CRLF & @CRLF & _
        BinaryToString(FileRead($filepath)) & @CRLF & _
        $boundary  & @CRLF & _
        'Content-Disposition: form-data; name="model"' & @CRLF & @CRLF & _
        'en-US' & @CRLF & _
        $boundary & "--" & @CRLF


$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("User-Agent", 'Mozilla/5.0 (Windows NT 10.0; WOW64) WinHttp/1.6.3.9 (WinHTTP/5.1) like Gecko')
$oHTTP.SetRequestHeader("Content-Type", 'multipart/form-data; boundary=----WinHttpBoundaryLine_96747.69683')
$oHTTP.SetRequestHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
$oHTTP.SetRequestHeader("Accept-Charset", "utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length', StringLen($Postdata))
$oHTTP.Send(Binary($Postdata))
$oHTTP.WaitForResponse()
$hotlink = $oHTTP.ResponseText
ConsoleWrite($hotlink)

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

Saludos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...