rrg92's picture
v1
29eda7d
raw
history blame
1.44 kB
$ErrorActionPreference = "Stop";
# Send the POST request with the form data
$Uri = "http://localhost:8080/v1/audio/transcriptions"
function MultiPart($data){
$FormBoundary = [System.Guid]::NewGuid().ToString();
$BodyLines = @()
$Fields = @($data.keys)
foreach($FieldName in $Fields){
$FieldValue = $data[$FieldName];
$BodyLines += "--$FormBoundary"
if($FieldValue -is [IO.FileInfo]){
$File = $FieldValue
$BodyLines += "Content-Disposition: form-data; name=`"$FieldName`"; filename=`"$($File.name)`""
$BodyLines += "Content-Type: application/octet-stream"
$FileBytes = [System.IO.File]::ReadAllBytes($File.FullName);
$FieldValue = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetString($FileBytes)
} else {
$BodyLines += "Content-Disposition: form-data; name=`"$FieldName`""
}
$BodyLines += ""
$BodyLines += $FieldValue
}
$BodyLines += "--$FormBoundary--"
$BodyFinal = $BodyLines -Join "`r`n"
Invoke-WebRequest @Args -method POST -body $BodyFinal -ContentType "multipart/form-data; boundary=$FormBoundary"
}
# Create the form data payload
$FormData = @{
"file" = (Get-Item .\SampleSmall.wav)
model = "Systran/faster-whisper-small"
}
$RawResp = MultiPart $FormData -Uri $Uri
$result = [System.Text.Encoding]::UTF8.GetString($RawResp.RawContentStream.ToArray())
# Output the response from the server
$result