Spaces:
Running
Running
File size: 1,438 Bytes
29eda7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
$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
|